From 956eeb1361736dfae741b3715b372bbfa5347982 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Fri, 11 May 2012 14:45:02 +0530 Subject: [PATCH] fetch defaults after mapping from prev document --- .../doctype/purchase_invoice/purchase_invoice.py | 10 +++++++++- .../doctype/sales_invoice/sales_invoice.py | 5 ++--- erpnext/selling/doctype/quotation/quotation.py | 2 +- .../selling/doctype/sales_common/sales_common.py | 16 ++++++++++++++++ .../selling/doctype/sales_order/sales_order.py | 2 +- .../stock/doctype/delivery_note/delivery_note.py | 2 +- 6 files changed, 30 insertions(+), 7 deletions(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index 66df40fcd8..b459b64d69 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -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 diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 59ec9c223a..5f09a432d1 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -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: diff --git a/erpnext/selling/doctype/quotation/quotation.py b/erpnext/selling/doctype/quotation/quotation.py index a99f5d7a97..511a74dc22 100644 --- a/erpnext/selling/doctype/quotation/quotation.py +++ b/erpnext/selling/doctype/quotation/quotation.py @@ -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] diff --git a/erpnext/selling/doctype/sales_common/sales_common.py b/erpnext/selling/doctype/sales_common/sales_common.py index 1a60a06fd2..0a038b12fb 100644 --- a/erpnext/selling/doctype/sales_common/sales_common.py +++ b/erpnext/selling/doctype/sales_common/sales_common.py @@ -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): diff --git a/erpnext/selling/doctype/sales_order/sales_order.py b/erpnext/selling/doctype/sales_order/sales_order.py index 320131cd3a..7a19528153 100644 --- a/erpnext/selling/doctype/sales_order/sales_order.py +++ b/erpnext/selling/doctype/sales_order/sales_order.py @@ -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] diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.py b/erpnext/stock/doctype/delivery_note/delivery_note.py index e2d2ca3f53..c1bb92dd27 100644 --- a/erpnext/stock/doctype/delivery_note/delivery_note.py +++ b/erpnext/stock/doctype/delivery_note/delivery_note.py @@ -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]