diff --git a/erpnext/accounts/doctype/c_form/c_form.js b/erpnext/accounts/doctype/c_form/c_form.js index 4fb32275e9..d9e5c68d2b 100644 --- a/erpnext/accounts/doctype/c_form/c_form.js +++ b/erpnext/accounts/doctype/c_form/c_form.js @@ -17,10 +17,13 @@ //c-form js file // ----------------------------- cur_frm.fields_dict.invoice_details.grid.get_field("invoice_no").get_query = function(doc) { - return 'SELECT `tabSales Invoice`.`name` FROM `tabSales Invoice` WHERE `tabSales Invoice`.`company` = "' +doc.company+'" AND `tabSales Invoice`.%(key)s LIKE "%s" AND `tabSales Invoice`.`customer` = "' + doc.customer + '" AND `tabSales Invoice`.`docstatus` = 1 and `tabSales Invoice`.`c_form_applicable` = "Yes" and ifnull(`tabSales Invoice`.c_form_no, "") = "" ORDER BY `tabSales Invoice`.`name` ASC LIMIT 50'; + cond = "" + if (doc.customer) cond += ' AND `tabSales Invoice`.`customer` = "' + cstr(doc.customer) + '"'; + if (doc.company) cond += ' AND `tabSales Invoice`.`company` = "' + cstr(doc.company) + '"'; + return 'SELECT `tabSales Invoice`.`name` FROM `tabSales Invoice` WHERE `tabSales Invoice`.`docstatus` = 1 and `tabSales Invoice`.`c_form_applicable` = "Yes" and ifnull(`tabSales Invoice`.c_form_no, "") = ""'+cond+' AND `tabSales Invoice`.%(key)s LIKE "%s" ORDER BY `tabSales Invoice`.`name` ASC LIMIT 50'; } cur_frm.cscript.invoice_no = function(doc, cdt, cdn) { var d = locals[cdt][cdn]; get_server_fields('get_invoice_details', d.invoice_no, 'invoice_details', doc, cdt, cdn, 1); -} +} \ No newline at end of file diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index fe65e95866..d9c3fb149f 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -174,15 +174,13 @@ class DocType(TransactionBase): self.doclist = get_obj('GL Control').get_advances(self, self.doc.credit_to, 'Purchase Invoice Advance','advance_allocation_details','debit') - # ============= OTHER CHARGES ==================== - - # Get Tax rate if account type is TAX - # ------------------------------------ def get_rate(self,arg): return get_obj('Purchase Common').get_rate(arg,self) - # Get Purchase Taxes and Charges Master - # ----------------------------------------------------------- + def load_default_taxes(self): + self.doclist = get_obj('Purchase Common').load_default_taxes(self) + + def get_purchase_tax_details(self): self.doclist = get_obj('Purchase Common').get_purchase_tax_details(self) diff --git a/erpnext/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.txt b/erpnext/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.txt index 8add7afa67..5c72c2c584 100644 --- a/erpnext/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.txt +++ b/erpnext/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.txt @@ -3,9 +3,9 @@ # These values are common in all dictionaries { - 'creation': '2012-07-03 13:30:50', + 'creation': '2012-05-15 12:14:32', 'docstatus': 0, - 'modified': '2012-07-12 14:10:35', + 'modified': '2012-08-17 09:57:04', 'modified_by': u'Administrator', 'owner': u'wasim@webnotestech.com' }, @@ -107,6 +107,25 @@ 'search_index': 0 }, + # DocField + { + 'doctype': u'DocField', + 'fieldname': u'is_default', + 'fieldtype': u'Check', + 'label': u'Default' + }, + + # DocField + { + 'doctype': u'DocField', + 'fieldname': u'company', + 'fieldtype': u'Link', + 'in_filter': 1, + 'label': u'Company', + 'options': u'Company', + 'reqd': 1 + }, + # DocField { 'doctype': u'DocField', diff --git a/erpnext/buying/doctype/purchase_common/purchase_common.js b/erpnext/buying/doctype/purchase_common/purchase_common.js index 8a1c9ee973..33c05df546 100644 --- a/erpnext/buying/doctype/purchase_common/purchase_common.js +++ b/erpnext/buying/doctype/purchase_common/purchase_common.js @@ -29,10 +29,26 @@ cur_frm.cscript.get_default_schedule_date = function(doc) { } } +cur_frm.cscript.load_taxes = function(doc, cdt, cdn, callback) { + // run if this is not executed from dt_map... + doc = locals[doc.doctype][doc.name]; + if(doc.supplier || getchildren('Purchase Taxes and Charges', doc.name, 'purchase_tax_details', doc.doctype).length) { + if(callback) { + callback(doc, cdt, cdn); + } + } else { + $c_obj(make_doclist(doc.doctype, doc.name),'load_default_taxes','',function(r,rt){ + refresh_field('purchase_tax_details'); + if(callback) callback(doc, cdt, cdn); + }); + } +} + + // Gets called after existing item details are update to fill in // remaining default values -cur_frm.cscript.load_defaults = function(doc, dt, dn) { +cur_frm.cscript.load_defaults = function(doc, dt, dn, callback) { if(!cur_frm.doc.__islocal) { return; } doc = locals[doc.doctype][doc.name]; @@ -46,6 +62,7 @@ cur_frm.cscript.load_defaults = function(doc, dt, dn) { LocalDB.set_default_values(children[i]); } refresh_field(cur_frm.cscript.fname); + cur_frm.cscript.load_taxes(doc, dt, dn, callback); } // Update existing item details @@ -58,10 +75,11 @@ cur_frm.cscript.update_item_details = function(doc, dt, dn, callback) { if(!r.exc) { refresh_field(cur_frm.cscript.fname); doc = locals[doc.doctype][doc.name]; - cur_frm.cscript.load_defaults(doc, dt, dn); - if(callback) callback(doc, dt, dn); + cur_frm.cscript.load_defaults(doc, dt, dn, callback); } }); + } else { + cur_frm.cscript.load_taxes(doc, dt, dn, callback); } } diff --git a/erpnext/buying/doctype/purchase_common/purchase_common.py b/erpnext/buying/doctype/purchase_common/purchase_common.py index b9e689fe6a..b8424aba7f 100644 --- a/erpnext/buying/doctype/purchase_common/purchase_common.py +++ b/erpnext/buying/doctype/purchase_common/purchase_common.py @@ -624,15 +624,23 @@ class DocType(TransactionBase): msgprint("'%s' Not Within The Fiscal Year"%(dn)) raise Exception - -#---Other charges starting point------------------------ - - # Get other charges from Master - # ================================================================================= - def get_purchase_tax_details(self,obj): + def load_default_taxes(self, obj): + return self.get_purchase_tax_details(obj, 1) + + def get_purchase_tax_details(self,obj, default = 0): obj.doclist = self.doc.clear_table(obj.doclist,'purchase_tax_details') + + if default: add_cond = " and ifnull(t2.is_default,0) = 1" + else: add_cond = " and t1.parent = '"+cstr(obj.doc.purchase_other_charges)+"'" + + other_charge = sql(""" + select t1.* + from `tabPurchase Taxes and Charges` t1, `tabPurchase Taxes and Charges Master` t2 + where t1.parent = t2.name %s + order by t1.idx + """% add_cond, as_dict = 1) + idx = 0 - other_charge = sql("select category, add_deduct_tax, charge_type,row_id,description,account_head,rate,tax_amount from `tabPurchase Taxes and Charges` where parent = '%s' order by idx" %(obj.doc.purchase_other_charges), as_dict = 1) for other in other_charge: d = addchild(obj.doc, 'purchase_tax_details', 'Purchase Taxes and Charges', 1, obj.doclist) d.category = other['category'] diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.js b/erpnext/buying/doctype/purchase_order/purchase_order.js index a1983c34a7..4e8c2c0384 100644 --- a/erpnext/buying/doctype/purchase_order/purchase_order.js +++ b/erpnext/buying/doctype/purchase_order/purchase_order.js @@ -36,7 +36,10 @@ cur_frm.cscript.onload = function(doc, cdt, cdn) { } cur_frm.cscript.onload_post_render = function(doc, dt, dn) { - if(doc.__islocal) cur_frm.cscript.get_default_schedule_date(doc); + var callback = function(doc, dt, dn) { + if(doc.__islocal) cur_frm.cscript.get_default_schedule_date(doc); + } + cur_frm.cscript.update_item_details(doc, dt, dn, callback); } cur_frm.cscript.refresh = function(doc, cdt, cdn) { diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.py b/erpnext/buying/doctype/purchase_order/purchase_order.py index 533e8ad778..65efd3767f 100644 --- a/erpnext/buying/doctype/purchase_order/purchase_order.py +++ b/erpnext/buying/doctype/purchase_order/purchase_order.py @@ -57,6 +57,7 @@ class DocType(TransactionBase): # Get Item Details def get_item_details(self, arg =''): + import json if arg: return get_obj(dt='Purchase Common').get_item_details(self,arg) else: @@ -360,13 +361,11 @@ class DocType(TransactionBase): self.update_rw_material_detail() -# OTHER CHARGES TRIGGER FUNCTIONS -# ==================================================================================== - - # *********** Get Tax rate if account type is TAX ******************** def get_rate(self,arg): - return get_obj('Purchase Common').get_rate(arg,self) + return get_obj('Purchase Common').get_rate(arg,self) + + def load_default_taxes(self): + self.doclist = get_obj('Purchase Common').load_default_taxes(self) - # **** Pull details from other charges master (Get Other Charges) **** def get_purchase_tax_details(self): self.doclist = get_obj('Purchase Common').get_purchase_tax_details(self) diff --git a/erpnext/buying/doctype/supplier_quotation/supplier_quotation.js b/erpnext/buying/doctype/supplier_quotation/supplier_quotation.js index 430d1eed99..6135ad4d9f 100644 --- a/erpnext/buying/doctype/supplier_quotation/supplier_quotation.js +++ b/erpnext/buying/doctype/supplier_quotation/supplier_quotation.js @@ -38,6 +38,7 @@ cur_frm.cscript.onload = function(doc, dt, dn) { cur_frm.cscript.refresh = function(doc, dt, dn) { erpnext.hide_naming_series(); cur_frm.cscript.dynamic_label(doc, dt, dn); + cur_frm.cscript.load_taxes(doc, dt, dn); cur_frm.cscript.toggle_contact_section(doc); diff --git a/erpnext/buying/doctype/supplier_quotation/supplier_quotation.py b/erpnext/buying/doctype/supplier_quotation/supplier_quotation.py index 1577eab1a6..057f8da257 100644 --- a/erpnext/buying/doctype/supplier_quotation/supplier_quotation.py +++ b/erpnext/buying/doctype/supplier_quotation/supplier_quotation.py @@ -73,6 +73,9 @@ class DocType(TransactionBase): d.purchase_ref_rate = d.discount_rate = d.purchase_rate = 0.0 d.import_ref_rate = d.import_rate = 0.0 + def load_default_taxes(self): + self.doclist = get_obj('Purchase Common').load_default_taxes(self) + def get_purchase_tax_details(self): self.doclist = get_obj('Purchase Common').get_purchase_tax_details(self) diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py index caf4d5ae6e..2be671ed5a 100644 --- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py @@ -469,15 +469,11 @@ class DocType(TransactionBase): d.current_stock = bin and flt(bin[0]['actual_qty']) or 0 - - -# OTHER CHARGES TRIGGER FUNCTIONS -# ==================================================================================== - - # *********** Get Tax rate if account type is TAX ******************** def get_rate(self,arg): return get_obj('Purchase Common').get_rate(arg,self) - - # **** Pull details from other charges master (Get Other Charges) **** + + def load_default_taxes(self): + self.doclist = get_obj('Purchase Common').load_default_taxes(self) + def get_purchase_tax_details(self): self.doclist = get_obj('Purchase Common').get_purchase_tax_details(self)