mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-31 10:49:09 +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"""
|
"""Global Defaults"""
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
import frappe.defaults
|
import frappe.defaults
|
||||||
from frappe.custom.doctype.property_setter.property_setter import make_property_setter
|
from frappe.custom.doctype.property_setter.property_setter import make_property_setter
|
||||||
@@ -19,6 +20,18 @@ keydict = {
|
|||||||
"disable_in_words": "disable_in_words",
|
"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
|
from frappe.model.document import Document
|
||||||
|
|
||||||
|
|
||||||
@@ -53,6 +66,7 @@ class GlobalDefaults(Document):
|
|||||||
|
|
||||||
self.toggle_rounded_total()
|
self.toggle_rounded_total()
|
||||||
self.toggle_in_words()
|
self.toggle_in_words()
|
||||||
|
self.set_disable_rounded_total_on_pos_profiles()
|
||||||
|
|
||||||
frappe.clear_cache()
|
frappe.clear_cache()
|
||||||
|
|
||||||
@@ -61,44 +75,31 @@ class GlobalDefaults(Document):
|
|||||||
return frappe.defaults.get_defaults()
|
return frappe.defaults.get_defaults()
|
||||||
|
|
||||||
def toggle_rounded_total(self):
|
def toggle_rounded_total(self):
|
||||||
self.disable_rounded_total = cint(self.disable_rounded_total)
|
|
||||||
|
|
||||||
# Make property setters to hide rounded total fields
|
# Make property setters to hide rounded total fields
|
||||||
for doctype in (
|
for doctype in ROUNDED_TOTAL_DOCTYPES:
|
||||||
"Quotation",
|
|
||||||
"Sales Order",
|
|
||||||
"Sales Invoice",
|
|
||||||
"Delivery Note",
|
|
||||||
"Supplier Quotation",
|
|
||||||
"Purchase Order",
|
|
||||||
"Purchase Invoice",
|
|
||||||
"Purchase Receipt",
|
|
||||||
):
|
|
||||||
make_property_setter(
|
make_property_setter(
|
||||||
doctype,
|
doctype,
|
||||||
"base_rounded_total",
|
"base_rounded_total",
|
||||||
"hidden",
|
"hidden",
|
||||||
self.disable_rounded_total,
|
cint(self.disable_rounded_total),
|
||||||
"Check",
|
"Check",
|
||||||
validate_fields_for_doctype=False,
|
validate_fields_for_doctype=False,
|
||||||
)
|
)
|
||||||
make_property_setter(
|
|
||||||
doctype, "base_rounded_total", "print_hide", 1, "Check", validate_fields_for_doctype=False
|
|
||||||
)
|
|
||||||
|
|
||||||
make_property_setter(
|
make_property_setter(
|
||||||
doctype,
|
doctype,
|
||||||
"rounded_total",
|
"rounded_total",
|
||||||
"hidden",
|
"hidden",
|
||||||
self.disable_rounded_total,
|
cint(self.disable_rounded_total),
|
||||||
"Check",
|
"Check",
|
||||||
validate_fields_for_doctype=False,
|
validate_fields_for_doctype=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
make_property_setter(
|
make_property_setter(
|
||||||
doctype,
|
doctype,
|
||||||
"rounded_total",
|
"rounded_total",
|
||||||
"print_hide",
|
"print_hide",
|
||||||
self.disable_rounded_total,
|
cint(self.disable_rounded_total),
|
||||||
"Check",
|
"Check",
|
||||||
validate_fields_for_doctype=False,
|
validate_fields_for_doctype=False,
|
||||||
)
|
)
|
||||||
@@ -113,24 +114,13 @@ class GlobalDefaults(Document):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def toggle_in_words(self):
|
def toggle_in_words(self):
|
||||||
self.disable_in_words = cint(self.disable_in_words)
|
|
||||||
|
|
||||||
# Make property setters to hide in words fields
|
# Make property setters to hide in words fields
|
||||||
for doctype in (
|
for doctype in ROUNDED_TOTAL_DOCTYPES:
|
||||||
"Quotation",
|
|
||||||
"Sales Order",
|
|
||||||
"Sales Invoice",
|
|
||||||
"Delivery Note",
|
|
||||||
"Supplier Quotation",
|
|
||||||
"Purchase Order",
|
|
||||||
"Purchase Invoice",
|
|
||||||
"Purchase Receipt",
|
|
||||||
):
|
|
||||||
make_property_setter(
|
make_property_setter(
|
||||||
doctype,
|
doctype,
|
||||||
"in_words",
|
"in_words",
|
||||||
"hidden",
|
"hidden",
|
||||||
self.disable_in_words,
|
cint(self.disable_in_words),
|
||||||
"Check",
|
"Check",
|
||||||
validate_fields_for_doctype=False,
|
validate_fields_for_doctype=False,
|
||||||
)
|
)
|
||||||
@@ -138,7 +128,14 @@ class GlobalDefaults(Document):
|
|||||||
doctype,
|
doctype,
|
||||||
"in_words",
|
"in_words",
|
||||||
"print_hide",
|
"print_hide",
|
||||||
self.disable_in_words,
|
cint(self.disable_in_words),
|
||||||
"Check",
|
"Check",
|
||||||
validate_fields_for_doctype=False,
|
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