Merge pull request #58033 from mihir-kandoi/gate-selling-toggle-setters

perf: rewrite selling settings toggle setters only on change
This commit is contained in:
Mihir Kandoi
2026-08-11 16:42:36 +05:30
committed by GitHub
4 changed files with 37 additions and 3 deletions

View File

@@ -297,7 +297,6 @@
"hide_days": 1,
"hide_seconds": 1,
"label": "Tax Id",
"print_hide": 1,
"read_only": 1
},
{
@@ -1940,6 +1939,7 @@
"allow_on_submit": 1,
"fieldname": "additional_discount_account",
"fieldtype": "Link",
"hidden": 1,
"label": "Discount Account",
"options": "Account"
},
@@ -2360,7 +2360,7 @@
"link_fieldname": "consolidated_invoice"
}
],
"modified": "2026-06-21 12:46:13.250145",
"modified": "2026-08-11 12:00:00.000000",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Sales Invoice",

View File

@@ -887,6 +887,7 @@
"allow_on_submit": 1,
"fieldname": "discount_account",
"fieldtype": "Link",
"hidden": 1,
"label": "Discount Account",
"options": "Account"
},
@@ -1067,7 +1068,7 @@
"idx": 1,
"istable": 1,
"links": [],
"modified": "2026-08-07 17:31:31.732720",
"modified": "2026-08-11 12:00:00.000000",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Sales Invoice Item",

View File

@@ -125,6 +125,9 @@ class SellingSettings(Document):
)
def toggle_hide_tax_id(self):
if not self.has_value_changed("hide_tax_id"):
return
_hide_tax_id = cint(self.hide_tax_id)
# Make property setters to hide tax_id fields
@@ -137,6 +140,9 @@ class SellingSettings(Document):
)
def toggle_editable_rate_for_bundle_items(self):
if not self.has_value_changed("editable_bundle_item_rates"):
return
editable_bundle_item_rates = cint(self.editable_bundle_item_rates)
make_property_setter(
@@ -149,6 +155,9 @@ class SellingSettings(Document):
)
def toggle_discount_accounting_fields(self):
if not self.has_value_changed("enable_discount_accounting"):
return
enable_discount_accounting = cint(self.enable_discount_accounting)
make_property_setter(

View File

@@ -34,3 +34,27 @@ class TestSellingSettings(ERPNextTestSuite):
settings.save()
set_by_naming_series.assert_called_once()
def test_unrelated_change_does_not_rewrite_toggle_setters(self):
settings = frappe.get_single("Selling Settings")
settings.allow_multiple_items = not settings.allow_multiple_items
with patch(
"erpnext.selling.doctype.selling_settings.selling_settings.make_property_setter"
) as make_property_setter:
settings.save()
make_property_setter.assert_not_called()
def test_toggle_setters_rewritten_when_related_settings_change(self):
settings = frappe.get_single("Selling Settings")
settings.hide_tax_id = not settings.hide_tax_id
settings.editable_bundle_item_rates = not settings.editable_bundle_item_rates
settings.enable_discount_accounting = not settings.enable_discount_accounting
with patch(
"erpnext.selling.doctype.selling_settings.selling_settings.make_property_setter"
) as make_property_setter:
settings.save()
self.assertEqual(make_property_setter.call_count, 11)