fetch defaults after mapping from prev document
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
index 66df40f..b459b64 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
@@ -97,10 +97,18 @@
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 59ec9c2..5f09a43 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
@@ -177,14 +177,13 @@
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 a99f5d7..511a74d 100644
--- a/erpnext/selling/doctype/quotation/quotation.py
+++ b/erpnext/selling/doctype/quotation/quotation.py
@@ -83,7 +83,7 @@
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 1a60a06..0a038b1 100644
--- a/erpnext/selling/doctype/sales_common/sales_common.py
+++ b/erpnext/selling/doctype/sales_common/sales_common.py
@@ -156,6 +156,22 @@
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 320131c..7a19528 100644
--- a/erpnext/selling/doctype/sales_order/sales_order.py
+++ b/erpnext/selling/doctype/sales_order/sales_order.py
@@ -100,7 +100,7 @@
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 e2d2ca3..c1bb92d 100644
--- a/erpnext/stock/doctype/delivery_note/delivery_note.py
+++ b/erpnext/stock/doctype/delivery_note/delivery_note.py
@@ -117,7 +117,7 @@
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]