From 1cb22f9d057612e4e592494e472c4d962236d828 Mon Sep 17 00:00:00 2001 From: Raffael Meyer <14891507+barredterra@users.noreply.github.com> Date: Thu, 25 Dec 2025 10:22:37 +0100 Subject: [PATCH] fix: don't duplicate default income account to Item (#50413) * fix: don't duplicate default income account to Item Only store _Default Income Account_ in **Item** if it's different from the **Company**'s _Default Income Account_. Resolves #48231 * refactor: move db call out of loop * docs: add docstring (cherry picked from commit b6cb9d47990554d332574cc52c02daea566fbada) --- erpnext/controllers/selling_controller.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/erpnext/controllers/selling_controller.py b/erpnext/controllers/selling_controller.py index d74ea55450a..3667a7a7e76 100644 --- a/erpnext/controllers/selling_controller.py +++ b/erpnext/controllers/selling_controller.py @@ -1004,10 +1004,19 @@ class SellingController(StockController): def set_default_income_account_for_item(obj): - for d in obj.get("items"): - if d.item_code: - if getattr(d, "income_account", None): - set_item_default(d.item_code, obj.company, "income_account", d.income_account) + """Set income account as default for items in the transaction. + + Updates the item default income account for each item in the transaction + if it differs from the company's default income account. + + Args: + obj: Transaction document containing items table with income_account field + """ + company_default = frappe.get_cached_value("Company", obj.company, "default_income_account") + for d in obj.get("items", default=[]): + income_account = getattr(d, "income_account", None) + if d.item_code and income_account and income_account != company_default: + set_item_default(d.item_code, obj.company, "income_account", income_account) def get_serial_and_batch_bundle(child, parent, delivery_note_child=None):