From 55d2a54785f527fc4429f0c457e5294a18a0cd90 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 1/2] 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) # Conflicts: # erpnext/controllers/selling_controller.py --- erpnext/controllers/selling_controller.py | 54 +++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/erpnext/controllers/selling_controller.py b/erpnext/controllers/selling_controller.py index 1cd98508e0b..adb9dd27da6 100644 --- a/erpnext/controllers/selling_controller.py +++ b/erpnext/controllers/selling_controller.py @@ -728,7 +728,61 @@ class SellingController(StockController): def set_default_income_account_for_item(obj): +<<<<<<< HEAD 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): + from erpnext.stock.serial_batch_bundle import SerialBatchCreation + + if parent.get("is_return") and parent.get("packed_items"): + return + + if child.get("use_serial_batch_fields"): + return + + if not frappe.get_single_value("Stock Settings", "auto_create_serial_and_batch_bundle_for_outward"): + return + + item_details = frappe.db.get_value("Item", child.item_code, ["has_serial_no", "has_batch_no"], as_dict=1) + + if not item_details.has_serial_no and not item_details.has_batch_no: + return + + sn_doc = SerialBatchCreation( + { + "item_code": child.item_code, + "warehouse": child.warehouse, + "voucher_type": parent.doctype, + "voucher_no": parent.name if parent.docstatus < 2 else None, + "voucher_detail_no": delivery_note_child.name if delivery_note_child else child.name, + "posting_datetime": get_combine_datetime(parent.posting_date, parent.posting_time), + "qty": child.qty, + "type_of_transaction": "Outward" if child.qty > 0 and parent.docstatus < 2 else "Inward", + "company": parent.company, + "do_not_submit": "True", + } + ) + + doc = sn_doc.make_serial_and_batch_bundle() + child.db_set("serial_and_batch_bundle", doc.name) + + return doc.name +>>>>>>> b6cb9d4799 (fix: don't duplicate default income account to Item (#50413)) From 8d28dcb18be4f0738402333ae27c9b9eee08e5de Mon Sep 17 00:00:00 2001 From: barredterra <14891507+barredterra@users.noreply.github.com> Date: Sun, 11 Jan 2026 17:59:27 +0100 Subject: [PATCH 2/2] chore: resolve conflicts --- erpnext/controllers/selling_controller.py | 45 ----------------------- 1 file changed, 45 deletions(-) diff --git a/erpnext/controllers/selling_controller.py b/erpnext/controllers/selling_controller.py index adb9dd27da6..b6738d65bfc 100644 --- a/erpnext/controllers/selling_controller.py +++ b/erpnext/controllers/selling_controller.py @@ -728,12 +728,6 @@ class SellingController(StockController): def set_default_income_account_for_item(obj): -<<<<<<< HEAD - 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 @@ -747,42 +741,3 @@ def set_default_income_account_for_item(obj): 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): - from erpnext.stock.serial_batch_bundle import SerialBatchCreation - - if parent.get("is_return") and parent.get("packed_items"): - return - - if child.get("use_serial_batch_fields"): - return - - if not frappe.get_single_value("Stock Settings", "auto_create_serial_and_batch_bundle_for_outward"): - return - - item_details = frappe.db.get_value("Item", child.item_code, ["has_serial_no", "has_batch_no"], as_dict=1) - - if not item_details.has_serial_no and not item_details.has_batch_no: - return - - sn_doc = SerialBatchCreation( - { - "item_code": child.item_code, - "warehouse": child.warehouse, - "voucher_type": parent.doctype, - "voucher_no": parent.name if parent.docstatus < 2 else None, - "voucher_detail_no": delivery_note_child.name if delivery_note_child else child.name, - "posting_datetime": get_combine_datetime(parent.posting_date, parent.posting_time), - "qty": child.qty, - "type_of_transaction": "Outward" if child.qty > 0 and parent.docstatus < 2 else "Inward", - "company": parent.company, - "do_not_submit": "True", - } - ) - - doc = sn_doc.make_serial_and_batch_bundle() - child.db_set("serial_and_batch_bundle", doc.name) - - return doc.name ->>>>>>> b6cb9d4799 (fix: don't duplicate default income account to Item (#50413))