refactor: Add advance settings

This commit is contained in:
Deepesh Garg
2026-02-04 16:50:58 +05:30
parent a734f90920
commit 0687e683f8
5 changed files with 180 additions and 40 deletions

View File

@@ -20,6 +20,10 @@
"enable_common_party_accounting", "enable_common_party_accounting",
"allow_multi_currency_invoices_against_single_party_account", "allow_multi_currency_invoices_against_single_party_account",
"confirm_before_resetting_posting_date", "confirm_before_resetting_posting_date",
"analytics_section",
"enable_analytical_accounting",
"column_break_vtnr",
"enable_discounts_and_margin",
"journals_section", "journals_section",
"merge_similar_account_heads", "merge_similar_account_heads",
"deferred_accounting_settings_section", "deferred_accounting_settings_section",
@@ -51,12 +55,16 @@
"allow_pegged_currencies_exchange_rates", "allow_pegged_currencies_exchange_rates",
"column_break_yuug", "column_break_yuug",
"stale_days", "stale_days",
"payments_tab",
"section_break_jpd0", "section_break_jpd0",
"auto_reconcile_payments", "auto_reconcile_payments",
"auto_reconciliation_job_trigger", "auto_reconciliation_job_trigger",
"reconciliation_queue_size", "reconciliation_queue_size",
"column_break_resa", "column_break_resa",
"exchange_gain_loss_posting_date", "exchange_gain_loss_posting_date",
"payment_options_section",
"enable_loyalty_point_program",
"column_break_ctam",
"invoicing_settings_tab", "invoicing_settings_tab",
"accounts_transactions_settings_section", "accounts_transactions_settings_section",
"over_billing_allowance", "over_billing_allowance",
@@ -281,7 +289,7 @@
}, },
{ {
"default": "0", "default": "0",
"description": "Learn about <a href=\"https://docs.frappe.io/erpnext/user/manual/en/common_party_accounting\">Common Party</a>", "description": "Learn about <a href=\"https://docs.frappe.io/erpnext/user/manual/en/common_party_accounting\" rel=\"noopener noreferrer\">Common Party</a>",
"fieldname": "enable_common_party_accounting", "fieldname": "enable_common_party_accounting",
"fieldtype": "Check", "fieldtype": "Check",
"label": "Enable Common Party Accounting" "label": "Enable Common Party Accounting"
@@ -637,6 +645,49 @@
"fieldname": "budget_section", "fieldname": "budget_section",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"label": "Budget" "label": "Budget"
},
{
"fieldname": "analytics_section",
"fieldtype": "Section Break",
"label": "Analytical Accounting"
},
{
"fieldname": "column_break_vtnr",
"fieldtype": "Column Break"
},
{
"default": "0",
"description": "Enable cost center, projects and other custom accounting dimensions",
"fieldname": "enable_analytical_accounting",
"fieldtype": "Check",
"label": "Enable Analytical Accounting"
},
{
"default": "0",
"description": "Apply discounts and margins on products",
"fieldname": "enable_discounts_and_margin",
"fieldtype": "Check",
"label": "Enable Discounts and Margin"
},
{
"fieldname": "payments_tab",
"fieldtype": "Tab Break",
"label": "Payments"
},
{
"fieldname": "payment_options_section",
"fieldtype": "Section Break",
"label": "Payment Options"
},
{
"default": "0",
"fieldname": "enable_loyalty_point_program",
"fieldtype": "Check",
"label": "Enable Loyalty Point Program"
},
{
"fieldname": "column_break_ctam",
"fieldtype": "Column Break"
} }
], ],
"grid_page_length": 50, "grid_page_length": 50,
@@ -646,7 +697,7 @@
"index_web_pages_for_search": 1, "index_web_pages_for_search": 1,
"issingle": 1, "issingle": 1,
"links": [], "links": [],
"modified": "2026-01-11 18:30:45.968531", "modified": "2026-02-04 15:20:03.309843",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Accounts", "module": "Accounts",
"name": "Accounts Settings", "name": "Accounts Settings",

View File

@@ -12,6 +12,29 @@ from frappe.utils import cint
from erpnext.accounts.utils import sync_auto_reconcile_config from erpnext.accounts.utils import sync_auto_reconcile_config
SELLING_DOCTYPES = [
"Sales Invoice",
"Sales Order",
"Delivery Note",
"Quotation",
"Sales Invoice Item",
"Sales Order Item",
"Delivery Note Item",
"Quotation Item",
"POS Invoice",
"POS Invoice Item",
]
BUYING_DOCTYPES = [
"Purchase Invoice",
"Purchase Order",
"Purchase Receipt",
"Purchase Invoice Item",
"Purchase Order Item",
"Purchase Receipt Item",
]
class AccountsSettings(Document): class AccountsSettings(Document):
# begin: auto-generated types # begin: auto-generated types
@@ -43,9 +66,12 @@ class AccountsSettings(Document):
default_ageing_range: DF.Data | None default_ageing_range: DF.Data | None
delete_linked_ledger_entries: DF.Check delete_linked_ledger_entries: DF.Check
determine_address_tax_category_from: DF.Literal["Billing Address", "Shipping Address"] determine_address_tax_category_from: DF.Literal["Billing Address", "Shipping Address"]
enable_analytical_accounting: DF.Check
enable_common_party_accounting: DF.Check enable_common_party_accounting: DF.Check
enable_discounts_and_margin: DF.Check
enable_fuzzy_matching: DF.Check enable_fuzzy_matching: DF.Check
enable_immutable_ledger: DF.Check enable_immutable_ledger: DF.Check
enable_loyalty_point_program: DF.Check
enable_party_matching: DF.Check enable_party_matching: DF.Check
exchange_gain_loss_posting_date: DF.Literal["Invoice", "Payment", "Reconciliation Date"] exchange_gain_loss_posting_date: DF.Literal["Invoice", "Payment", "Reconciliation Date"]
fetch_valuation_rate_for_internal_transaction: DF.Check fetch_valuation_rate_for_internal_transaction: DF.Check
@@ -98,6 +124,18 @@ class AccountsSettings(Document):
if old_doc.show_payment_schedule_in_print != self.show_payment_schedule_in_print: if old_doc.show_payment_schedule_in_print != self.show_payment_schedule_in_print:
self.enable_payment_schedule_in_print() self.enable_payment_schedule_in_print()
if old_doc.enable_analytical_accounting != self.enable_analytical_accounting:
toggle_accounting_dimension_sections(not self.enable_analytical_accounting)
clear_cache = True
if old_doc.enable_discounts_and_margin != self.enable_discounts_and_margin:
toggle_sales_discount_section(not self.enable_discounts_and_margin)
clear_cache = True
if old_doc.enable_loyalty_point_program != self.enable_loyalty_point_program:
toggle_loyalty_point_program_section(not self.enable_loyalty_point_program)
clear_cache = True
if clear_cache: if clear_cache:
frappe.clear_cache() frappe.clear_cache()
@@ -154,3 +192,32 @@ class AccountsSettings(Document):
frappe.db.sql(f"drop procedure if exists {InitSQLProceduresForAR.init_procedure_name}") frappe.db.sql(f"drop procedure if exists {InitSQLProceduresForAR.init_procedure_name}")
frappe.db.sql(f"drop procedure if exists {InitSQLProceduresForAR.allocate_procedure_name}") frappe.db.sql(f"drop procedure if exists {InitSQLProceduresForAR.allocate_procedure_name}")
def toggle_accounting_dimension_sections(hide):
accounting_dimension_doctypes = frappe.get_hooks("accounting_dimension_doctypes")
for doctype in accounting_dimension_doctypes:
create_property_setter_for_hiding_field(doctype, "accounting_dimensions_section", hide)
def toggle_sales_discount_section(hide):
for doctype in SELLING_DOCTYPES + BUYING_DOCTYPES:
meta = frappe.get_meta(doctype)
if meta.has_field("additional_discount_section"):
create_property_setter_for_hiding_field(doctype, "additional_discount_section", hide)
if meta.has_field("discount_and_margin"):
create_property_setter_for_hiding_field(doctype, "discount_and_margin", hide)
def toggle_loyalty_point_program_section(hide):
for doctype in SELLING_DOCTYPES:
meta = frappe.get_meta(doctype)
if meta.has_field("loyalty_points_redemption"):
create_property_setter_for_hiding_field(doctype, "loyalty_points_redemption", hide)
def create_property_setter_for_hiding_field(doctype, field_name, hide):
make_property_setter(
doctype,
field_name,
"hidden",
hide,
"Check",
validate_fields_for_doctype=False,
)

View File

@@ -99,7 +99,7 @@
"ignore_tax_withholding_threshold", "ignore_tax_withholding_threshold",
"override_tax_withholding_entries", "override_tax_withholding_entries",
"tax_withholding_entries", "tax_withholding_entries",
"section_break_49", "additional_discount_section",
"apply_discount_on", "apply_discount_on",
"base_discount_amount", "base_discount_amount",
"coupon_code", "coupon_code",
@@ -197,13 +197,13 @@
"column_break8", "column_break8",
"unrealized_profit_loss_account", "unrealized_profit_loss_account",
"against_income_account", "against_income_account",
"sales_team_section_break", "commission_section",
"sales_partner", "sales_partner",
"amount_eligible_for_commission", "amount_eligible_for_commission",
"column_break10", "column_break10",
"commission_rate", "commission_rate",
"total_commission", "total_commission",
"section_break2", "sales_team_section",
"sales_team", "sales_team",
"edit_printing_settings", "edit_printing_settings",
"letter_head", "letter_head",
@@ -1076,14 +1076,6 @@
"no_copy": 1, "no_copy": 1,
"options": "Cost Center" "options": "Cost Center"
}, },
{
"collapsible": 1,
"fieldname": "section_break_49",
"fieldtype": "Section Break",
"hide_days": 1,
"hide_seconds": 1,
"label": "Additional Discount"
},
{ {
"default": "Grand Total", "default": "Grand Total",
"fieldname": "apply_discount_on", "fieldname": "apply_discount_on",
@@ -1265,7 +1257,6 @@
"read_only": 1 "read_only": 1
}, },
{ {
"collapsible": 1,
"collapsible_depends_on": "advances", "collapsible_depends_on": "advances",
"fieldname": "advances_section", "fieldname": "advances_section",
"fieldtype": "Section Break", "fieldtype": "Section Break",
@@ -1699,10 +1690,10 @@
"read_only": 1 "read_only": 1
}, },
{ {
"allow_on_submit": 1,
"default": "No", "default": "No",
"fieldname": "is_opening", "fieldname": "is_opening",
"fieldtype": "Select", "fieldtype": "Select",
"hidden": 1,
"hide_days": 1, "hide_days": 1,
"hide_seconds": 1, "hide_seconds": 1,
"label": "Is Opening Entry", "label": "Is Opening Entry",
@@ -1731,18 +1722,6 @@
"oldfieldtype": "Text", "oldfieldtype": "Text",
"print_hide": 1 "print_hide": 1
}, },
{
"collapsible": 1,
"collapsible_depends_on": "sales_partner",
"fieldname": "sales_team_section_break",
"fieldtype": "Section Break",
"hide_days": 1,
"hide_seconds": 1,
"label": "Commission",
"oldfieldtype": "Section Break",
"options": "fa fa-group",
"print_hide": 1
},
{ {
"fieldname": "sales_partner", "fieldname": "sales_partner",
"fieldtype": "Link", "fieldtype": "Link",
@@ -1786,16 +1765,6 @@
"options": "Company:company:default_currency", "options": "Company:company:default_currency",
"print_hide": 1 "print_hide": 1
}, },
{
"collapsible": 1,
"collapsible_depends_on": "sales_team",
"fieldname": "section_break2",
"fieldtype": "Section Break",
"hide_days": 1,
"hide_seconds": 1,
"label": "Sales Team",
"print_hide": 1
},
{ {
"allow_on_submit": 1, "allow_on_submit": 1,
"fieldname": "sales_team", "fieldname": "sales_team",
@@ -2306,6 +2275,36 @@
{ {
"fieldname": "column_break_xjag", "fieldname": "column_break_xjag",
"fieldtype": "Column Break" "fieldtype": "Column Break"
},
{
"collapsible": 1,
"fieldname": "additional_discount_section",
"fieldtype": "Section Break",
"hide_days": 1,
"hide_seconds": 1,
"label": "Additional Discount"
},
{
"collapsible": 1,
"collapsible_depends_on": "sales_team",
"fieldname": "sales_team_section",
"fieldtype": "Section Break",
"hide_days": 1,
"hide_seconds": 1,
"label": "Sales Team",
"print_hide": 1
},
{
"collapsible": 1,
"collapsible_depends_on": "sales_partner",
"fieldname": "commission_section",
"fieldtype": "Section Break",
"hide_days": 1,
"hide_seconds": 1,
"label": "Commission",
"oldfieldtype": "Section Break",
"options": "fa fa-group",
"print_hide": 1
} }
], ],
"grid_page_length": 50, "grid_page_length": 50,
@@ -2319,7 +2318,7 @@
"link_fieldname": "consolidated_invoice" "link_fieldname": "consolidated_invoice"
} }
], ],
"modified": "2026-02-04 12:14:56.149710", "modified": "2026-02-04 16:21:54.112633",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Accounts", "module": "Accounts",
"name": "Sales Invoice", "name": "Sales Invoice",

View File

@@ -29,6 +29,7 @@
"dn_required", "dn_required",
"sales_update_frequency", "sales_update_frequency",
"blanket_order_allowance", "blanket_order_allowance",
"enable_tracking_sales_commissions",
"column_break_5", "column_break_5",
"allow_multiple_items", "allow_multiple_items",
"allow_against_multiple_purchase_orders", "allow_against_multiple_purchase_orders",
@@ -297,6 +298,13 @@
"fieldname": "set_zero_rate_for_expired_batch", "fieldname": "set_zero_rate_for_expired_batch",
"fieldtype": "Check", "fieldtype": "Check",
"label": "Set Incoming Rate as Zero for Expired Batch" "label": "Set Incoming Rate as Zero for Expired Batch"
},
{
"default": "0",
"description": "Manage sales partner's and sales team's commissions",
"fieldname": "enable_tracking_sales_commissions",
"fieldtype": "Check",
"label": "Enable tracking sales commissions"
} }
], ],
"grid_page_length": 50, "grid_page_length": 50,
@@ -306,7 +314,7 @@
"index_web_pages_for_search": 1, "index_web_pages_for_search": 1,
"issingle": 1, "issingle": 1,
"links": [], "links": [],
"modified": "2026-01-23 00:04:33.105916", "modified": "2026-02-04 16:16:57.618127",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Selling", "module": "Selling",
"name": "Selling Settings", "name": "Selling Settings",

View File

@@ -10,7 +10,6 @@ from frappe.custom.doctype.property_setter.property_setter import make_property_
from frappe.model.document import Document from frappe.model.document import Document
from frappe.utils import cint from frappe.utils import cint
class SellingSettings(Document): class SellingSettings(Document):
# begin: auto-generated types # begin: auto-generated types
# This code is auto-generated. Do not modify anything in this block. # This code is auto-generated. Do not modify anything in this block.
@@ -37,6 +36,7 @@ class SellingSettings(Document):
editable_price_list_rate: DF.Check editable_price_list_rate: DF.Check
enable_cutoff_date_on_bulk_delivery_note_creation: DF.Check enable_cutoff_date_on_bulk_delivery_note_creation: DF.Check
enable_discount_accounting: DF.Check enable_discount_accounting: DF.Check
enable_tracking_sales_commissions: DF.Check
fallback_to_default_price_list: DF.Check fallback_to_default_price_list: DF.Check
hide_tax_id: DF.Check hide_tax_id: DF.Check
maintain_same_rate_action: DF.Literal["Stop", "Warn"] maintain_same_rate_action: DF.Literal["Stop", "Warn"]
@@ -57,6 +57,8 @@ class SellingSettings(Document):
self.toggle_discount_accounting_fields() self.toggle_discount_accounting_fields()
def validate(self): def validate(self):
old_doc = self.get_doc_before_save()
for key in [ for key in [
"cust_master_name", "cust_master_name",
"customer_group", "customer_group",
@@ -78,6 +80,9 @@ class SellingSettings(Document):
self.validate_fallback_to_default_price_list() self.validate_fallback_to_default_price_list()
if old_doc.enable_tracking_sales_commissions != self.enable_tracking_sales_commissions:
toggle_tracking_sales_commissions_section(not self.enable_tracking_sales_commissions)
def validate_fallback_to_default_price_list(self): def validate_fallback_to_default_price_list(self):
if ( if (
self.fallback_to_default_price_list self.fallback_to_default_price_list
@@ -175,3 +180,13 @@ class SellingSettings(Document):
"Code", "Code",
validate_fields_for_doctype=False, validate_fields_for_doctype=False,
) )
def toggle_tracking_sales_commissions_section(hide):
from erpnext.accounts.doctype.accounts_settings.accounts_settings import create_property_setter_for_hiding_field, SELLING_DOCTYPES
for doctype in SELLING_DOCTYPES:
meta = frappe.get_meta(doctype)
if meta.has_field("commission_section"):
create_property_setter_for_hiding_field(doctype, "commission_section", hide)
if meta.has_field("sales_team_section"):
create_property_setter_for_hiding_field(doctype, "sales_team_section", hide)