From d905204e4964cc11e9c46fc34793ca40f4845dc3 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Thu, 22 Oct 2015 18:49:08 +0530 Subject: [PATCH] [fix] Update expense account in old purchase invoices if missing --- .../v6_4/fix_expense_included_in_valuation.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/erpnext/patches/v6_4/fix_expense_included_in_valuation.py b/erpnext/patches/v6_4/fix_expense_included_in_valuation.py index 24cf96814af..436dd02a2c1 100644 --- a/erpnext/patches/v6_4/fix_expense_included_in_valuation.py +++ b/erpnext/patches/v6_4/fix_expense_included_in_valuation.py @@ -33,12 +33,22 @@ def execute(): (pi.name, company.expenses_included_in_valuation)) if gle_for_expenses_included_in_valuation: + print pi.name + frappe.db.sql("""delete from `tabGL Entry` where voucher_type='Purchase Invoice' and voucher_no=%s""", pi.name) - print pi.name - purchase_invoice = frappe.get_doc("Purchase Invoice", pi.name) + + # some old entries have missing expense accounts + if purchase_invoice.against_expense_account: + expense_account = purchase_invoice.against_expense_account.split(",") + if len(expense_account) == 1: + expense_account = expense_account[0] + for item in purchase_invoice.items: + if not item.expense_account: + item.db_set("expense_account", expense_account, update_modified=False) + purchase_invoice.make_gl_entries() def get_frozen_date(company, account):