diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index 042af0bcd3f..e131a6fec36 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -305,24 +305,7 @@ 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" @@ -341,7 +324,27 @@ 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 3caf714ddd7..619e252ef15 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -321,3 +321,4 @@ erpnext.patches.v7_0.update_mode_of_payment_type finally:erpnext.patches.v7_0.update_timesheet_communications erpnext.patches.v7_0.update_status_of_zero_amount_sales_order erpnext.patches.v7_0.repost_bin_qty_and_item_projected_qty +erpnext.patches.v7_0.repost_gle_for_pi_with_update_stock \ No newline at end of file diff --git a/erpnext/patches/v7_0/repost_gle_for_pi_with_update_stock.py b/erpnext/patches/v7_0/repost_gle_for_pi_with_update_stock.py new file mode 100644 index 00000000000..2355d539aee --- /dev/null +++ b/erpnext/patches/v7_0/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 diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py index e9d4cb3fef5..ced6a6431fa 100644 --- a/erpnext/stock/doctype/item/item.py +++ b/erpnext/stock/doctype/item/item.py @@ -567,7 +567,7 @@ class Item(WebsiteGenerator): existing_allow_negative_stock = frappe.db.get_value("Stock Settings", None, "allow_negative_stock") frappe.db.set_value("Stock Settings", None, "allow_negative_stock", 1) - for warehouse in frappe.db.sql("select name from `tabWarehouse` where is_group = 0"): + for warehouse in frappe.db.sql("select warehouse from `tabBin` where item_code=%s", new_name): repost_stock(new_name, warehouse[0]) frappe.db.set_value("Stock Settings", None, "allow_negative_stock", existing_allow_negative_stock)