From f5f3ef1baeea51ecd03121bf21be2691158930f5 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 31 Oct 2016 16:16:17 +0530 Subject: [PATCH] repost gle for Purchase Invoice with update stock --- .../purchase_invoice/purchase_invoice.py | 41 ++++++++++--------- erpnext/patches.txt | 3 +- .../repost_gle_for_pi_with_update_stock.py | 16 ++++++++ 3 files changed, 40 insertions(+), 20 deletions(-) create mode 100644 erpnext/patches/v7_1/repost_gle_for_pi_with_update_stock.py diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index 1c9bcbc577..22de07fa39 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -305,25 +305,8 @@ class PurchaseInvoice(BuyingController): if not self.grand_total: return - self.auto_accounting_for_stock = \ - cint(frappe.defaults.get_global_default("auto_accounting_for_stock")) - - self.stock_received_but_not_billed = self.get_company_default("stock_received_but_not_billed") - self.expenses_included_in_valuation = self.get_company_default("expenses_included_in_valuation") - self.negative_expense_to_be_booked = 0.0 - gl_entries = [] - - - self.make_supplier_gl_entry(gl_entries) - self.make_item_gl_entries(gl_entries) - self.make_tax_gl_entries(gl_entries) - - gl_entries = merge_similar_entries(gl_entries) - - self.make_payment_gl_entries(gl_entries) - - self.make_write_off_gl_entry(gl_entries) - + gl_entries = self.get_gl_entries() + if gl_entries: update_outstanding = "No" if (cint(self.is_paid) or self.write_off_account) else "Yes" @@ -342,6 +325,26 @@ class PurchaseInvoice(BuyingController): elif self.docstatus == 2 and cint(self.update_stock) and self.auto_accounting_for_stock: delete_gl_entries(voucher_type=self.doctype, voucher_no=self.name) + def get_gl_entries(self, warehouse_account=None): + self.auto_accounting_for_stock = \ + cint(frappe.defaults.get_global_default("auto_accounting_for_stock")) + + self.stock_received_but_not_billed = self.get_company_default("stock_received_but_not_billed") + self.expenses_included_in_valuation = self.get_company_default("expenses_included_in_valuation") + self.negative_expense_to_be_booked = 0.0 + gl_entries = [] + + + self.make_supplier_gl_entry(gl_entries) + self.make_item_gl_entries(gl_entries) + self.make_tax_gl_entries(gl_entries) + + gl_entries = merge_similar_entries(gl_entries) + + self.make_payment_gl_entries(gl_entries) + self.make_write_off_gl_entry(gl_entries) + + return gl_entries def make_supplier_gl_entry(self, gl_entries): if self.grand_total: diff --git a/erpnext/patches.txt b/erpnext/patches.txt index e5cdb1adad..d694ef4e8e 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -341,4 +341,5 @@ erpnext.patches.v7_1.add_field_for_task_dependent erpnext.patches.v7_0.repost_bin_qty_and_item_projected_qty erpnext.patches.v7_1.set_prefered_contact_email execute:frappe.db.sql("update `tabSingles` set value = 1 where field = 'unlink_payment_on_cancellation_of_invoice' and doctype = 'Accounts Settings'") -execute:frappe.db.sql("update `tabStock Entry` set total_amount = null where purpose in('Repack', 'Manufacture')") \ No newline at end of file +execute:frappe.db.sql("update `tabStock Entry` set total_amount = null where purpose in('Repack', 'Manufacture')") +erpnext.patches.v7_1.repost_gle_for_pi_with_update_stock \ No newline at end of file diff --git a/erpnext/patches/v7_1/repost_gle_for_pi_with_update_stock.py b/erpnext/patches/v7_1/repost_gle_for_pi_with_update_stock.py new file mode 100644 index 0000000000..2355d539ae --- /dev/null +++ b/erpnext/patches/v7_1/repost_gle_for_pi_with_update_stock.py @@ -0,0 +1,16 @@ +# 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 + +def execute(): + if not cint(frappe.defaults.get_global_default("auto_accounting_for_stock")): + return + + for pi in frappe.db.sql("""select name from `tabPurchase Invoice` + where update_stock=1 and docstatus=1 order by posting_date asc""", as_dict=1): + pi_doc = frappe.get_doc("Purchase Invoice", pi.name) + pi_doc.make_gl_entries() + frappe.db.commit() \ No newline at end of file