From f039c8b58fde6fad523f15223bb345ee0b0ccebe Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 14 Aug 2012 15:38:17 +0530 Subject: [PATCH 1/2] get_query for invoice in c-form --- erpnext/accounts/doctype/c_form/c_form.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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 From 0170b2b4bc5f9498590045bbc9f6e7e9e8ca57ea Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Fri, 17 Aug 2012 11:00:15 +0530 Subject: [PATCH 2/2] default purchase taxes and charges master will be automatically fetched in pur transactions --- .../purchase_invoice/purchase_invoice.py | 10 ++++---- .../purchase_taxes_and_charges_master.txt | 16 +++++++++---- .../purchase_common/purchase_common.js | 24 ++++++++++++++++--- .../purchase_common/purchase_common.py | 22 +++++++++++------ .../doctype/purchase_order/purchase_order.js | 5 +++- .../doctype/purchase_order/purchase_order.py | 11 ++++----- .../supplier_quotation/supplier_quotation.js | 1 + .../supplier_quotation/supplier_quotation.py | 3 +++ .../purchase_receipt/purchase_receipt.py | 12 ++++------ 9 files changed, 69 insertions(+), 35 deletions(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index 668d2ef005..9e2eb7351c 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -173,15 +173,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 1ecac405f3..15b4dfa954 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-03-27 14:35:51', + 'creation': '2012-05-15 12:14:32', 'docstatus': 0, - 'modified': '2012-03-27 14:35:51', + 'modified': '2012-08-17 09:57:04', 'modified_by': u'Administrator', 'owner': u'wasim@webnotestech.com' }, @@ -24,7 +24,7 @@ 'section_style': u'Simple', 'server_code_error': u' ', 'show_in_menu': 0, - 'version': 18 + 'version': 1 }, # These values are common for all DocField @@ -106,6 +106,14 @@ 'search_index': 0 }, + # DocField + { + 'doctype': u'DocField', + 'fieldname': u'is_default', + 'fieldtype': u'Check', + 'label': u'Default' + }, + # DocField { 'doctype': u'DocField', @@ -127,4 +135,4 @@ 'oldfieldtype': u'Table', 'options': u'Purchase Taxes and Charges' } -] +] \ No newline at end of file diff --git a/erpnext/buying/doctype/purchase_common/purchase_common.js b/erpnext/buying/doctype/purchase_common/purchase_common.js index 68dc8c73d4..e240b49f9a 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 5a65d5219a..8d1d3b5149 100644 --- a/erpnext/buying/doctype/purchase_common/purchase_common.py +++ b/erpnext/buying/doctype/purchase_common/purchase_common.py @@ -623,15 +623,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 d84d06eda9..55f59b5c28 100644 --- a/erpnext/buying/doctype/purchase_order/purchase_order.py +++ b/erpnext/buying/doctype/purchase_order/purchase_order.py @@ -56,6 +56,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: @@ -359,13 +360,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 f5b9335c4d..88219760b7 100644 --- a/erpnext/buying/doctype/supplier_quotation/supplier_quotation.py +++ b/erpnext/buying/doctype/supplier_quotation/supplier_quotation.py @@ -72,6 +72,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 10fecbfe66..807b3658a7 100644 --- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py @@ -468,15 +468,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)