From 6028a19e6ba613979947c1c3d8318d0bc38d2b3f Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Fri, 21 Jun 2024 17:21:32 +0530 Subject: [PATCH] fix: incorrect against_account upon reposting (cherry picked from commit 20c4098399d5cb276d373074036a738e6cee67b0) --- .../accounts/doctype/purchase_invoice/purchase_invoice.py | 6 +++++- .../repost_accounting_ledger/repost_accounting_ledger.py | 4 ++++ erpnext/accounts/doctype/sales_invoice/sales_invoice.py | 4 ++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index e0debba6fd5..2015dd1b634 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -413,7 +413,7 @@ class PurchaseInvoice(BuyingController): for item in self.get("items"): validate_account_head(item.idx, item.expense_account, self.company, "Expense") - def set_against_expense_account(self): + def set_against_expense_account(self, force=False): against_accounts = [] for item in self.get("items"): if item.expense_account and (item.expense_account not in against_accounts): @@ -421,6 +421,10 @@ class PurchaseInvoice(BuyingController): self.against_expense_account = ",".join(against_accounts) + def force_set_against_expense_account(self): + self.set_against_expense_account() + frappe.db.set_value(self.doctype, self.name, "against_expense_account", self.against_expense_account) + def po_required(self): if frappe.db.get_value("Buying Settings", None, "po_required") == "Yes": if frappe.get_value( diff --git a/erpnext/accounts/doctype/repost_accounting_ledger/repost_accounting_ledger.py b/erpnext/accounts/doctype/repost_accounting_ledger/repost_accounting_ledger.py index 15478ab8633..550e80ec8bc 100644 --- a/erpnext/accounts/doctype/repost_accounting_ledger/repost_accounting_ledger.py +++ b/erpnext/accounts/doctype/repost_accounting_ledger/repost_accounting_ledger.py @@ -149,6 +149,10 @@ def start_repost(account_repost_doc=str) -> None: doc.make_gl_entries_on_cancel() doc.docstatus = 1 + if doc.doctype == "Sales Invoice": + doc.force_set_against_income_account() + else: + doc.force_set_against_expense_account() doc.make_gl_entries() elif doc.doctype in ["Payment Entry", "Journal Entry", "Expense Claim"]: diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 3ea4b91641c..009c48a385c 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -768,6 +768,10 @@ class SalesInvoice(SellingController): against_acc.append(d.income_account) self.against_income_account = ",".join(against_acc) + def force_set_against_income_account(self): + self.set_against_income_account() + frappe.db.set_value(self.doctype, self.name, "against_income_account", self.against_income_account) + def add_remarks(self): if not self.remarks: if self.po_no and self.po_date: