mirror of
https://github.com/frappe/erpnext.git
synced 2026-10-29 22:57:42 +00:00
fix: deadlock when setting item default income account (backport #59414)
Setting an item default income account no longer deadlocks.
(cherry picked from commit 53b92732c5)
This commit is contained in:
@@ -1130,7 +1130,7 @@ def set_default_income_account_for_item(obj):
|
||||
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=[]):
|
||||
for d in sorted(obj.get("items", default=[]), key=lambda row: row.item_code or ""):
|
||||
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)
|
||||
|
||||
@@ -1436,6 +1436,7 @@ def set_item_default(item_code, company, fieldname, value):
|
||||
if d.company == company:
|
||||
if not d.get(fieldname):
|
||||
frappe.db.set_value(d.doctype, d.name, fieldname, value)
|
||||
item.clear_cache()
|
||||
return
|
||||
|
||||
# no row found, add a new row for the company
|
||||
|
||||
@@ -23,6 +23,7 @@ from erpnext.stock.doctype.item.item import (
|
||||
get_item_attribute,
|
||||
get_timeline_data,
|
||||
get_uom_conv_factor,
|
||||
set_item_default,
|
||||
validate_is_stock_item,
|
||||
)
|
||||
from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry
|
||||
@@ -323,6 +324,18 @@ class TestItem(FrappeTestCase):
|
||||
for key, value in purchase_item_check.items():
|
||||
self.assertEqual(value, purchase_item_details.get(key))
|
||||
|
||||
def test_set_item_default_refreshes_cached_item(self):
|
||||
item = make_item(
|
||||
properties={
|
||||
"item_defaults": [{"company": "_Test Company", "default_warehouse": "_Test Warehouse - _TC"}]
|
||||
}
|
||||
)
|
||||
|
||||
set_item_default(item.name, "_Test Company", "income_account", "_Test Account Sales - _TC")
|
||||
|
||||
cached_item = frappe.get_cached_doc("Item", item.name)
|
||||
self.assertEqual(cached_item.item_defaults[0].income_account, "_Test Account Sales - _TC")
|
||||
|
||||
def test_item_default_validations(self):
|
||||
with self.assertRaises(frappe.ValidationError) as ve:
|
||||
make_item(
|
||||
|
||||
Reference in New Issue
Block a user