From c81eabe07b431a61cfcafceedb0cef17d49ce424 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Mon, 2 Sep 2013 16:27:34 +0530 Subject: [PATCH] [fix] [minor] recreate gl entries when using auto inventory accounting to fix bug introduced due to commit - 5dd6b1d082d180133813c1c661d5e72076a19491 --- .../p01_fix_buying_amount_gl_entries.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/patches/september_2013/p01_fix_buying_amount_gl_entries.py b/patches/september_2013/p01_fix_buying_amount_gl_entries.py index 1fe3b4623d..160aa15e54 100644 --- a/patches/september_2013/p01_fix_buying_amount_gl_entries.py +++ b/patches/september_2013/p01_fix_buying_amount_gl_entries.py @@ -35,11 +35,26 @@ def recreate_gl_entries(doctype, name, parentfield): item_values = webnotes.conn.get_value("Item", item.item_code, ["purchase_account", "default_sales_cost_center"]) company_values = webnotes.conn.get_value("Company", bean.doc.company, - ["default_expense_account", "cost_center"]) + ["default_expense_account", "cost_center", "stock_adjustment_cost_center"]) if not item.expense_account: item.expense_account = (item_values and item_values[0]) or (company_values and company_values[0]) + if not item.cost_center: - item.cost_center = (item_values and item_values[1]) or (company_values and company_values[1]) + item.cost_center = (item_values and item_values[1]) or \ + (company_values and (company_values[1] or company_values[2])) + + if not (item.expense_account and item.cost_center): + res = webnotes.conn.sql("""select expense_account, cost_center + from `tab%s` child where docstatus=1 and item_code=%s + ifnull(expense_account, '')!='' and ifnull(cost_center, '')!='' + and (select company from `tab%s` parent where parent.name=child.parent)=%s + order by creation desc limit 1""" % (item.doctype, "%s", doctype, "%s"), + (item.item_code, bean.doc.company)) + if res: + if not item.expense_account: + item.expense_account = res[0][0] + if not item.cost_center: + item.cost_center = res[0][1] webnotes.conn.set_value(item.doctype, item.name, "expense_account", item.expense_account) webnotes.conn.set_value(item.doctype, item.name, "cost_center", item.cost_center)