default purchase taxes and charges master will be automatically fetched in pur transactions

This commit is contained in:
Nabin Hait 2012-08-17 11:00:15 +05:30
parent f039c8b58f
commit 0170b2b4bc
9 changed files with 69 additions and 35 deletions

View File

@ -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)

View File

@ -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'
}
]
]

View File

@ -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);
}
}

View File

@ -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']

View File

@ -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) {

View File

@ -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)

View File

@ -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);

View File

@ -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)

View File

@ -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)