mirror of
https://github.com/frappe/erpnext.git
synced 2026-08-13 06:31:48 +00:00
fix(selling): hide commission fields without a sales partner and stop copying them
Across Sales Order, Delivery Note, Sales Invoice and POS Invoice, the Commission section's commission_rate, total_commission and amount_eligible_for_commission are sales-partner commission fields: - depends_on eval:doc.sales_partner so they only show when a Sales Partner is set; - no_copy so a duplicated/amended document does not carry a stale commission rate or computed commission amount (the sales partner itself still copies). depends_on is client-only, so the server-side commission calculation is unchanged. Add a Sales Order test for the no_copy behaviour.
This commit is contained in:
@@ -1425,19 +1425,23 @@
|
||||
"width": "50%"
|
||||
},
|
||||
{
|
||||
"depends_on": "eval:doc.sales_partner",
|
||||
"fetch_from": "sales_partner.commission_rate",
|
||||
"fetch_if_empty": 1,
|
||||
"fieldname": "commission_rate",
|
||||
"fieldtype": "Float",
|
||||
"label": "Commission Rate (%)",
|
||||
"no_copy": 1,
|
||||
"oldfieldname": "commission_rate",
|
||||
"oldfieldtype": "Currency",
|
||||
"print_hide": 1
|
||||
},
|
||||
{
|
||||
"depends_on": "eval:doc.sales_partner",
|
||||
"fieldname": "total_commission",
|
||||
"fieldtype": "Currency",
|
||||
"label": "Total Commission",
|
||||
"no_copy": 1,
|
||||
"oldfieldname": "total_commission",
|
||||
"oldfieldtype": "Currency",
|
||||
"options": "Company:company:default_currency",
|
||||
@@ -1528,9 +1532,11 @@
|
||||
"print_hide": 1
|
||||
},
|
||||
{
|
||||
"depends_on": "eval:doc.sales_partner",
|
||||
"fieldname": "amount_eligible_for_commission",
|
||||
"fieldtype": "Currency",
|
||||
"label": "Amount Eligible for Commission",
|
||||
"no_copy": 1,
|
||||
"options": "Company:company:default_currency",
|
||||
"read_only": 1
|
||||
},
|
||||
@@ -1636,7 +1642,7 @@
|
||||
"icon": "fa fa-file-text",
|
||||
"is_submittable": 1,
|
||||
"links": [],
|
||||
"modified": "2026-05-28 12:22:50.253090",
|
||||
"modified": "2026-06-21 12:46:13.250145",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "POS Invoice",
|
||||
|
||||
@@ -1747,6 +1747,7 @@
|
||||
"width": "50%"
|
||||
},
|
||||
{
|
||||
"depends_on": "eval:doc.sales_partner",
|
||||
"fetch_from": "sales_partner.commission_rate",
|
||||
"fetch_if_empty": 1,
|
||||
"fieldname": "commission_rate",
|
||||
@@ -1754,16 +1755,19 @@
|
||||
"hide_days": 1,
|
||||
"hide_seconds": 1,
|
||||
"label": "Commission Rate (%)",
|
||||
"no_copy": 1,
|
||||
"oldfieldname": "commission_rate",
|
||||
"oldfieldtype": "Currency",
|
||||
"print_hide": 1
|
||||
},
|
||||
{
|
||||
"depends_on": "eval:doc.sales_partner",
|
||||
"fieldname": "total_commission",
|
||||
"fieldtype": "Currency",
|
||||
"hide_days": 1,
|
||||
"hide_seconds": 1,
|
||||
"label": "Total Commission",
|
||||
"no_copy": 1,
|
||||
"oldfieldname": "total_commission",
|
||||
"oldfieldtype": "Currency",
|
||||
"options": "Company:company:default_currency",
|
||||
@@ -1970,9 +1974,11 @@
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"depends_on": "eval:doc.sales_partner",
|
||||
"fieldname": "amount_eligible_for_commission",
|
||||
"fieldtype": "Currency",
|
||||
"label": "Amount Eligible for Commission",
|
||||
"no_copy": 1,
|
||||
"options": "Company:company:default_currency",
|
||||
"read_only": 1
|
||||
},
|
||||
@@ -2354,7 +2360,7 @@
|
||||
"link_fieldname": "consolidated_invoice"
|
||||
}
|
||||
],
|
||||
"modified": "2026-05-28 12:15:12.486443",
|
||||
"modified": "2026-06-21 12:46:13.250145",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Sales Invoice",
|
||||
|
||||
@@ -1329,6 +1329,7 @@
|
||||
"width": "50%"
|
||||
},
|
||||
{
|
||||
"depends_on": "eval:doc.sales_partner",
|
||||
"fetch_from": "sales_partner.commission_rate",
|
||||
"fetch_if_empty": 1,
|
||||
"fieldname": "commission_rate",
|
||||
@@ -1336,17 +1337,20 @@
|
||||
"hide_days": 1,
|
||||
"hide_seconds": 1,
|
||||
"label": "Commission Rate",
|
||||
"no_copy": 1,
|
||||
"oldfieldname": "commission_rate",
|
||||
"oldfieldtype": "Currency",
|
||||
"print_hide": 1,
|
||||
"width": "100px"
|
||||
},
|
||||
{
|
||||
"depends_on": "eval:doc.sales_partner",
|
||||
"fieldname": "total_commission",
|
||||
"fieldtype": "Currency",
|
||||
"hide_days": 1,
|
||||
"hide_seconds": 1,
|
||||
"label": "Total Commission",
|
||||
"no_copy": 1,
|
||||
"oldfieldname": "total_commission",
|
||||
"oldfieldtype": "Currency",
|
||||
"options": "Company:company:default_currency",
|
||||
@@ -1477,9 +1481,11 @@
|
||||
},
|
||||
{
|
||||
"allow_on_submit": 1,
|
||||
"depends_on": "eval:doc.sales_partner",
|
||||
"fieldname": "amount_eligible_for_commission",
|
||||
"fieldtype": "Currency",
|
||||
"label": "Amount Eligible for Commission",
|
||||
"no_copy": 1,
|
||||
"options": "Company:company:default_currency",
|
||||
"read_only": 1
|
||||
},
|
||||
@@ -1760,7 +1766,7 @@
|
||||
"idx": 105,
|
||||
"is_submittable": 1,
|
||||
"links": [],
|
||||
"modified": "2026-05-28 11:41:11.823034",
|
||||
"modified": "2026-06-21 12:46:13.250145",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Selling",
|
||||
"name": "Sales Order",
|
||||
|
||||
@@ -3044,6 +3044,25 @@ class TestSalesOrder(ERPNextTestSuite):
|
||||
finally:
|
||||
frappe.db.set_value("Item", "_Test Item", "grant_commission", 1)
|
||||
|
||||
def test_commission_fields_not_copied_on_duplicate(self):
|
||||
"""Commission rate/amount fields are no_copy; only the sales partner carries to a copy."""
|
||||
frappe.db.set_value("Item", "_Test Item", "grant_commission", 1)
|
||||
try:
|
||||
so = make_sales_order(qty=10, rate=100, do_not_save=True)
|
||||
so.sales_partner = "_Test Sales Partner India - 1"
|
||||
so.commission_rate = 7
|
||||
so.save()
|
||||
self.assertEqual(so.total_commission, 70)
|
||||
|
||||
# ignore_no_copy=False mirrors UI "Duplicate"/amend, which honour no_copy
|
||||
duplicate = frappe.copy_doc(so, ignore_no_copy=False)
|
||||
self.assertEqual(duplicate.sales_partner, "_Test Sales Partner India - 1")
|
||||
self.assertFalse(duplicate.commission_rate)
|
||||
self.assertFalse(duplicate.total_commission)
|
||||
self.assertFalse(duplicate.amount_eligible_for_commission)
|
||||
finally:
|
||||
frappe.db.set_value("Item", "_Test Item", "grant_commission", 1)
|
||||
|
||||
|
||||
def compare_payment_schedules(doc, doc1, doc2):
|
||||
for index, schedule in enumerate(doc1.get("payment_schedule")):
|
||||
|
||||
@@ -1154,11 +1154,13 @@
|
||||
"width": "50%"
|
||||
},
|
||||
{
|
||||
"depends_on": "eval:doc.sales_partner",
|
||||
"fetch_from": "sales_partner.commission_rate",
|
||||
"fetch_if_empty": 1,
|
||||
"fieldname": "commission_rate",
|
||||
"fieldtype": "Float",
|
||||
"label": "Commission Rate (%)",
|
||||
"no_copy": 1,
|
||||
"oldfieldname": "commission_rate",
|
||||
"oldfieldtype": "Currency",
|
||||
"print_hide": 1,
|
||||
@@ -1166,9 +1168,11 @@
|
||||
"width": "100px"
|
||||
},
|
||||
{
|
||||
"depends_on": "eval:doc.sales_partner",
|
||||
"fieldname": "total_commission",
|
||||
"fieldtype": "Currency",
|
||||
"label": "Total Commission",
|
||||
"no_copy": 1,
|
||||
"oldfieldname": "total_commission",
|
||||
"oldfieldtype": "Currency",
|
||||
"options": "Company:company:default_currency",
|
||||
@@ -1262,9 +1266,11 @@
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"depends_on": "eval:doc.sales_partner",
|
||||
"fieldname": "amount_eligible_for_commission",
|
||||
"fieldtype": "Currency",
|
||||
"label": "Amount Eligible for Commission",
|
||||
"no_copy": 1,
|
||||
"options": "Company:company:default_currency",
|
||||
"read_only": 1
|
||||
},
|
||||
@@ -1466,7 +1472,7 @@
|
||||
"idx": 146,
|
||||
"is_submittable": 1,
|
||||
"links": [],
|
||||
"modified": "2026-05-28 11:44:37.286743",
|
||||
"modified": "2026-06-21 12:46:13.250145",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Stock",
|
||||
"name": "Delivery Note",
|
||||
|
||||
Reference in New Issue
Block a user