Merge pull request #6017 from nabinhait/repost_future_stock_transactions
Repost gle for future transactions if update stock checked in back dated purchase invoice
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
index 176e529..d17e80f 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
@@ -301,7 +301,7 @@
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 46ed9bc..fcdff21 100644
--- a/erpnext/controllers/stock_controller.py
+++ b/erpnext/controllers/stock_controller.py
@@ -38,6 +38,7 @@
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 @@
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 ac2c2d9..73eac92 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -308,4 +308,5 @@
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 0000000..3a6526c
--- /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