fetch defaults after mapping from prev document

This commit is contained in:
Nabin Hait 2012-05-11 14:45:02 +05:30
parent 43dd041ced
commit 956eeb1361
6 changed files with 30 additions and 7 deletions

View File

@ -97,10 +97,18 @@ class DocType(TransactionBase):
self.validate_duplicate_docname('purchase_order')
self.doclist = get_obj('DocType Mapper', 'Purchase Order-Purchase Invoice').dt_map('Purchase Order', 'Purchase Invoice', self.doc.purchase_order_main, self.doc, self.doclist, "[['Purchase Order', 'Purchase Invoice'],['Purchase Order Item', 'Purchase Invoice Item'], ['Purchase Taxes and Charges','Purchase Taxes and Charges']]")
ret = self.get_credit_to()
self.get_expense_account('entries')
ret = self.get_credit_to()
if ret.has_key('credit_to'):
self.doc.credit_to = ret['credit_to']
def get_expense_account(self, doctype):
for d in getlist(self.doclist, doctype):
if d.item_code:
item = webnotes.conn.sql("select purchase_account, cost_center from tabItem where name = '%s'" %(d.item_code), as_dict=1)
d.expense_head = item and item[0]['purchase_account'] or ''
d.cost_center = item and item[0]['cost_center'] or ''
# Get Item Details

View File

@ -177,14 +177,13 @@ class DocType(TransactionBase):
arg = {'item_code':doc.fields.get('item_code'), 'income_account':doc.fields.get('income_account'),
'cost_center': doc.fields.get('cost_center'), 'warehouse': doc.fields.get('warehouse')};
ret = obj.get_item_details(arg, self)
ret = self.get_pos_details(arg, ret)
ret = self.get_pos_details(arg)
for r in ret:
if not doc.fields.get(r):
doc.fields[r] = ret[r]
def get_pos_details(self, args, ret):
def get_pos_details(self, args, ret = {}):
if args['item_code'] and cint(self.doc.is_pos) == 1:
dtl = webnotes.conn.sql("select income_account, warehouse, cost_center from `tabPOS Setting` where user = '%s' and company = '%s'" % (session['user'], self.doc.company), as_dict=1)
if not dtl:

View File

@ -83,7 +83,7 @@ class DocType(TransactionBase):
if doc.fields.get('item_code'):
arg = {'item_code':doc.fields.get('item_code'), 'income_account':doc.fields.get('income_account'),
'cost_center': doc.fields.get('cost_center'), 'warehouse': doc.fields.get('warehouse')};
ret = obj.get_item_details(arg, self)
ret = obj.get_item_defaults(arg, self)
for r in ret:
if not doc.fields.get(r):
doc.fields[r] = ret[r]

View File

@ -156,6 +156,22 @@ class DocType(TransactionBase):
ret['base_ref_rate'] = flt(base_ref_rate)
ret['basic_rate'] = flt(base_ref_rate)
return ret
def get_item_defaults(self, args):
item = webnotes.conn.sql("""select default_warehouse, default_income_account, default_sales_cost_center from `tabItem`
where name = '%s' and (ifnull(end_of_life,'') = '' or end_of_life > now() or end_of_life = '0000-00-00')
and (is_sales_item = 'Yes' or is_service_item = 'Yes') """ % (args['item_code']), as_dict=1)
ret = {
'reserved_warehouse' : item and item[0]['default_warehouse'] or '',
'warehouse' : item and item[0]['default_warehouse'] or args.get('warehouse'),
'income_account' : item and item[0]['default_income_account'] or args.get('income_account'),
'cost_center' : item and item[0]['default_sales_cost_center'] or args.get('cost_center')
}
return ret
# ***************** Get Ref rate as entered in Item Master ********************
def get_ref_rate(self, item_code, price_list_name, price_list_currency, plc_conv_rate):

View File

@ -100,7 +100,7 @@ class DocType(TransactionBase):
if doc.fields.get('item_code'):
arg = {'item_code':doc.fields.get('item_code'), 'income_account':doc.fields.get('income_account'),
'cost_center': doc.fields.get('cost_center'), 'warehouse': doc.fields.get('warehouse')};
ret = obj.get_item_details(arg, self)
ret = obj.get_item_defaults(arg, self)
for r in ret:
if not doc.fields.get(r):
doc.fields[r] = ret[r]

View File

@ -117,7 +117,7 @@ class DocType(TransactionBase):
if doc.fields.get('item_code'):
arg = {'item_code':doc.fields.get('item_code'), 'income_account':doc.fields.get('income_account'),
'cost_center': doc.fields.get('cost_center'), 'warehouse': doc.fields.get('warehouse')};
ret = obj.get_item_details(arg, self)
ret = obj.get_item_defaults(arg, self)
for r in ret:
if not doc.fields.get(r):
doc.fields[r] = ret[r]