From 99d4ff4a29406638a55f080dc71910951522841e Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 8 Aug 2016 14:12:16 +0530 Subject: [PATCH] Repost gle for future transactions if update stock checked in back dated purchase invoice --- .../purchase_invoice/purchase_invoice.py | 2 +- erpnext/controllers/stock_controller.py | 8 ++++---- erpnext/patches.txt | 3 ++- .../repost_future_gle_for_purchase_invoice.py | 20 +++++++++++++++++++ 4 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 erpnext/patches/v7_0/repost_future_gle_for_purchase_invoice.py diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index 176e529665..d17e80f757 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -301,7 +301,7 @@ class PurchaseInvoice(BuyingController): asset.flags.ignore_validate_update_after_submit = True asset.save() - def make_gl_entries(self, repost_future_gle=False): + def make_gl_entries(self, repost_future_gle=True): self.auto_accounting_for_stock = \ cint(frappe.defaults.get_global_default("auto_accounting_for_stock")) diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py index 46ed9bc072..fcdff21591 100644 --- a/erpnext/controllers/stock_controller.py +++ b/erpnext/controllers/stock_controller.py @@ -38,6 +38,7 @@ class StockController(AccountsController): gl_list = [] warehouse_with_no_account = [] + for detail in voucher_details: sle_list = sle_map.get(detail.name) if sle_list: @@ -266,10 +267,9 @@ def update_gl_entries_after(posting_date, posting_time, for_warehouses=None, for voucher_obj = frappe.get_doc(voucher_type, voucher_no) expected_gle = voucher_obj.get_gl_entries(warehouse_account) if expected_gle: - if not existing_gle or not compare_existing_and_expected_gle(existing_gle, - expected_gle): - _delete_gl_entries(voucher_type, voucher_no) - voucher_obj.make_gl_entries(repost_future_gle=False) + if not existing_gle or not compare_existing_and_expected_gle(existing_gle, expected_gle): + _delete_gl_entries(voucher_type, voucher_no) + voucher_obj.make_gl_entries(repost_future_gle=False) else: _delete_gl_entries(voucher_type, voucher_no) diff --git a/erpnext/patches.txt b/erpnext/patches.txt index ac2c2d9b7b..73eac92c88 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -308,4 +308,5 @@ erpnext.patches.v7_0.remove_old_earning_deduction_doctypes erpnext.patches.v7_0.make_guardian erpnext.patches.v7_0.update_refdoc_in_landed_cost_voucher erpnext.patches.v7_0.set_material_request_type_in_item -erpnext.patches.v7_0.rename_examination_to_assessment \ No newline at end of file +erpnext.patches.v7_0.rename_examination_to_assessment +erpnext.patches.v7_0.repost_future_gle_for_purchase_invoice diff --git a/erpnext/patches/v7_0/repost_future_gle_for_purchase_invoice.py b/erpnext/patches/v7_0/repost_future_gle_for_purchase_invoice.py new file mode 100644 index 0000000000..3a6526ca23 --- /dev/null +++ b/erpnext/patches/v7_0/repost_future_gle_for_purchase_invoice.py @@ -0,0 +1,20 @@ +# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors +# License: GNU General Public License v3. See license.txt + +from __future__ import unicode_literals +import frappe +from frappe.utils import cint +from erpnext.controllers.stock_controller import get_warehouse_account, update_gl_entries_after + +def execute(): + if not cint(frappe.defaults.get_global_default("auto_accounting_for_stock")): + return + + wh_account = get_warehouse_account() + + for pi in frappe.get_all("Purchase Invoice", filters={"docstatus": 1, "update_stock": 1}): + pi_doc = frappe.get_doc("Purchase Invoice", pi.name) + items, warehouses = pi_doc.get_items_and_warehouses() + update_gl_entries_after(pi_doc.posting_date, pi_doc.posting_time, warehouses, items, wh_account) + + frappe.db.commit() \ No newline at end of file