perf: rewrite selling settings toggle setters only on change

on_update reran toggle_hide_tax_id, toggle_editable_rate_for_bundle_items
and toggle_discount_accounting_fields on every save, rewriting 11
property setters and clearing the meta cache of five doctypes.

Gate each toggle on has_value_changed. Fresh installs save the settings
with pure defaults (set_single_defaults), so the gated-off state must
match the JSON schema: align sales_invoice.json and
sales_invoice_item.json with the values every saved site already has —
tax_id printed when hide_tax_id is off, discount accounts hidden while
discount accounting is disabled. Packed Item rate already matches.
This commit is contained in:
Mihir Kandoi
2026-08-11 16:21:21 +05:30
parent 909e7b1457
commit 136e00d513
3 changed files with 13 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(