mirror of
https://github.com/frappe/erpnext.git
synced 2026-02-12 17:23:38 +00:00
refactor: global defaults (#52481)
* fix(global_defaults): set disable rounded total on POS Profiles * fix: removed re-setting fields on toggle functions * fix: removed property setter for print_hide
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
|
||||
|
||||
"""Global Defaults"""
|
||||
|
||||
import frappe
|
||||
import frappe.defaults
|
||||
from frappe.custom.doctype.property_setter.property_setter import make_property_setter
|
||||
@@ -19,6 +20,18 @@ keydict = {
|
||||
"disable_in_words": "disable_in_words",
|
||||
}
|
||||
|
||||
ROUNDED_TOTAL_DOCTYPES = (
|
||||
"Quotation",
|
||||
"Sales Order",
|
||||
"POS Invoice",
|
||||
"Sales Invoice",
|
||||
"Delivery Note",
|
||||
"Supplier Quotation",
|
||||
"Purchase Order",
|
||||
"Purchase Invoice",
|
||||
"Purchase Receipt",
|
||||
)
|
||||
|
||||
from frappe.model.document import Document
|
||||
|
||||
|
||||
@@ -53,6 +66,7 @@ class GlobalDefaults(Document):
|
||||
|
||||
self.toggle_rounded_total()
|
||||
self.toggle_in_words()
|
||||
self.set_disable_rounded_total_on_pos_profiles()
|
||||
|
||||
frappe.clear_cache()
|
||||
|
||||
@@ -61,44 +75,31 @@ class GlobalDefaults(Document):
|
||||
return frappe.defaults.get_defaults()
|
||||
|
||||
def toggle_rounded_total(self):
|
||||
self.disable_rounded_total = cint(self.disable_rounded_total)
|
||||
|
||||
# Make property setters to hide rounded total fields
|
||||
for doctype in (
|
||||
"Quotation",
|
||||
"Sales Order",
|
||||
"Sales Invoice",
|
||||
"Delivery Note",
|
||||
"Supplier Quotation",
|
||||
"Purchase Order",
|
||||
"Purchase Invoice",
|
||||
"Purchase Receipt",
|
||||
):
|
||||
for doctype in ROUNDED_TOTAL_DOCTYPES:
|
||||
make_property_setter(
|
||||
doctype,
|
||||
"base_rounded_total",
|
||||
"hidden",
|
||||
self.disable_rounded_total,
|
||||
cint(self.disable_rounded_total),
|
||||
"Check",
|
||||
validate_fields_for_doctype=False,
|
||||
)
|
||||
make_property_setter(
|
||||
doctype, "base_rounded_total", "print_hide", 1, "Check", validate_fields_for_doctype=False
|
||||
)
|
||||
|
||||
make_property_setter(
|
||||
doctype,
|
||||
"rounded_total",
|
||||
"hidden",
|
||||
self.disable_rounded_total,
|
||||
cint(self.disable_rounded_total),
|
||||
"Check",
|
||||
validate_fields_for_doctype=False,
|
||||
)
|
||||
|
||||
make_property_setter(
|
||||
doctype,
|
||||
"rounded_total",
|
||||
"print_hide",
|
||||
self.disable_rounded_total,
|
||||
cint(self.disable_rounded_total),
|
||||
"Check",
|
||||
validate_fields_for_doctype=False,
|
||||
)
|
||||
@@ -113,24 +114,13 @@ class GlobalDefaults(Document):
|
||||
)
|
||||
|
||||
def toggle_in_words(self):
|
||||
self.disable_in_words = cint(self.disable_in_words)
|
||||
|
||||
# Make property setters to hide in words fields
|
||||
for doctype in (
|
||||
"Quotation",
|
||||
"Sales Order",
|
||||
"Sales Invoice",
|
||||
"Delivery Note",
|
||||
"Supplier Quotation",
|
||||
"Purchase Order",
|
||||
"Purchase Invoice",
|
||||
"Purchase Receipt",
|
||||
):
|
||||
for doctype in ROUNDED_TOTAL_DOCTYPES:
|
||||
make_property_setter(
|
||||
doctype,
|
||||
"in_words",
|
||||
"hidden",
|
||||
self.disable_in_words,
|
||||
cint(self.disable_in_words),
|
||||
"Check",
|
||||
validate_fields_for_doctype=False,
|
||||
)
|
||||
@@ -138,7 +128,14 @@ class GlobalDefaults(Document):
|
||||
doctype,
|
||||
"in_words",
|
||||
"print_hide",
|
||||
self.disable_in_words,
|
||||
cint(self.disable_in_words),
|
||||
"Check",
|
||||
validate_fields_for_doctype=False,
|
||||
)
|
||||
|
||||
def set_disable_rounded_total_on_pos_profiles(self):
|
||||
POSProfile = frappe.qb.DocType("POS Profile")
|
||||
|
||||
frappe.qb.update(POSProfile).set(
|
||||
POSProfile.disable_rounded_total, cint(self.disable_rounded_total)
|
||||
).run()
|
||||
|
||||
Reference in New Issue
Block a user