From 215c901a0d856d659c742bd5571daa32c55ad49d Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Mon, 2 Sep 2013 15:38:53 +0530 Subject: [PATCH] [fix] [minor] recreate gl entries when using auto inventory accounting to fix bug introduced due to commit - 5dd6b1d082d180133813c1c661d5e72076a19491 --- controllers/selling_controller.py | 9 ++++-- patches/patch_list.py | 1 + patches/september_2013/__init__.py | 0 .../p01_fix_buying_amount_gl_entries.py | 31 +++++++++++++++++++ 4 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 patches/september_2013/__init__.py create mode 100644 patches/september_2013/p01_fix_buying_amount_gl_entries.py diff --git a/controllers/selling_controller.py b/controllers/selling_controller.py index a13d747279..5605ccf3a2 100644 --- a/controllers/selling_controller.py +++ b/controllers/selling_controller.py @@ -99,6 +99,8 @@ class SellingController(StockController): for item in self.doclist.get({"parentfield": self.fname}): if item.item_code in self.stock_items or \ (item_sales_bom and item_sales_bom.get(item.item_code)): + + buying_amount = 0 if item.item_code in self.stock_items: buying_amount = get_buying_amount(self.doc.doctype, self.doc.name, item.name, stock_ledger_entries.get((item.item_code, @@ -108,9 +110,10 @@ class SellingController(StockController): self.doc.doctype, self.doc.name, item.name, stock_ledger_entries, item_sales_bom) - item.buying_amount = buying_amount >= 0.01 and buying_amount or 0 - webnotes.conn.set_value(item.doctype, item.name, "buying_amount", - item.buying_amount) + # buying_amount >= 0.01 so that gl entry doesn't get created for such small amounts + item.buying_amount = buying_amount >= 0.01 and buying_amount or 0 + webnotes.conn.set_value(item.doctype, item.name, "buying_amount", + item.buying_amount) def check_expense_account(self, item): if item.buying_amount and not item.expense_account: diff --git a/patches/patch_list.py b/patches/patch_list.py index 1d382a56bd..2db62cf3a8 100644 --- a/patches/patch_list.py +++ b/patches/patch_list.py @@ -257,4 +257,5 @@ patch_list = [ "execute:webnotes.reload_doc('accounts', 'Print Format', 'POS Invoice') # 2013-08-16", "patches.august_2013.p06_fix_sle_against_stock_entry", "execute:webnotes.bean('Style Settings').save() #2013-08-20", + "patches.september_2013.p01_fix_buying_amount_gl_entries", ] \ No newline at end of file diff --git a/patches/september_2013/__init__.py b/patches/september_2013/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/patches/september_2013/p01_fix_buying_amount_gl_entries.py b/patches/september_2013/p01_fix_buying_amount_gl_entries.py new file mode 100644 index 0000000000..b32317469d --- /dev/null +++ b/patches/september_2013/p01_fix_buying_amount_gl_entries.py @@ -0,0 +1,31 @@ +# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. +# License: GNU General Public License v3. See license.txt + +from __future__ import unicode_literals +import webnotes +import webnotes.defaults +from webnotes.utils import cint + +def execute(): + if not cint(webnotes.defaults.get_global_default("auto_inventory_accounting")): + return + + # fix delivery note + for dn in webnotes.conn.sql_list("""select name from `tabDelivery Note` where docstatus=1 + and posting_date >= "2013-08-06" """): + recreate_gl_entries("Delivery Note", dn) + + # fix sales invoice + for si in webnotes.conn.sql_list("""select name from `tabSales Invoice` where docstatus=1 + and update_stock=1 and posting_date >= "2013-08-06" """): + recreate_gl_entries("Sales Invoice", si) + +def recreate_gl_entries(doctype, name): + # remove gl entries + webnotes.conn.sql("""delete from `tabGL Entry` where voucher_type=%s + and voucher_no=%s""", (doctype, name)) + + # calculate buying amount and make gl entries + bean = webnotes.bean(doctype, name) + bean.run_method("set_buying_amount") + bean.run_method("make_gl_entries") \ No newline at end of file