mirror of
https://github.com/frappe/erpnext.git
synced 2026-08-11 13:41:47 +00:00
fix(selling): make commission_rate a Percent field on Sales Person and Sales Team
commission_rate was a free-text Data field on the Sales Person master and the Sales Team child, storing percentages as strings. Convert both to Percent. A pre_model_sync patch sanitizes the existing values first (empty / NULL / non-numeric -> 0, others normalised via flt) so the Data -> Percent column change casts cleanly under strict SQL mode, where Percent is a NOT NULL decimal column. The patch is idempotent and avoids db-specific SQL so it works on both MariaDB and Postgres.
This commit is contained in:
@@ -261,6 +261,7 @@ erpnext.patches.v14_0.update_proprietorship_to_individual
|
||||
erpnext.patches.v15_0.rename_subcontracting_fields
|
||||
erpnext.patches.v15_0.unset_incorrect_additional_discount_percentage
|
||||
erpnext.patches.v16_0.create_company_custom_fields
|
||||
erpnext.patches.v16_0.convert_commission_rate_to_percent
|
||||
|
||||
[post_model_sync]
|
||||
erpnext.patches.v15_0.rename_gross_purchase_amount_to_net_purchase_amount
|
||||
|
||||
22
erpnext/patches/v16_0/convert_commission_rate_to_percent.py
Normal file
22
erpnext/patches/v16_0/convert_commission_rate_to_percent.py
Normal file
@@ -0,0 +1,22 @@
|
||||
import frappe
|
||||
from frappe.utils import flt
|
||||
|
||||
|
||||
def execute():
|
||||
"""Sanitize the free-text commission_rate values before the Data -> Percent column change.
|
||||
|
||||
Sales Person and Sales Team stored ``commission_rate`` as Data (varchar). This runs in
|
||||
pre_model_sync so the values are clean numeric strings by the time the schema sync alters
|
||||
the column to Percent; empty or non-numeric values become 0.
|
||||
"""
|
||||
for doctype in ("Sales Person", "Sales Team"):
|
||||
if not frappe.db.has_column(doctype, "commission_rate"):
|
||||
continue
|
||||
|
||||
# Percent maps to a NOT NULL decimal column, so empty/NULL/non-numeric text must become 0
|
||||
# as well, otherwise the column type change fails under strict SQL mode.
|
||||
rows = frappe.db.get_all(doctype, fields=["name", "commission_rate"])
|
||||
for row in rows:
|
||||
cleaned = flt(row.commission_rate)
|
||||
if str(row.commission_rate) != str(cleaned):
|
||||
frappe.db.set_value(doctype, row.name, "commission_rate", cleaned, update_modified=False)
|
||||
@@ -68,7 +68,7 @@
|
||||
"fetch_from": "sales_person.commission_rate",
|
||||
"fetch_if_empty": 1,
|
||||
"fieldname": "commission_rate",
|
||||
"fieldtype": "Data",
|
||||
"fieldtype": "Percent",
|
||||
"in_list_view": 1,
|
||||
"label": "Commission Rate",
|
||||
"read_only": 1
|
||||
@@ -87,7 +87,7 @@
|
||||
"idx": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2024-03-27 13:10:38.504580",
|
||||
"modified": "2026-06-21 12:52:33.742603",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Selling",
|
||||
"name": "Sales Team",
|
||||
@@ -98,4 +98,4 @@
|
||||
"sort_order": "DESC",
|
||||
"states": [],
|
||||
"track_changes": 1
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@
|
||||
},
|
||||
{
|
||||
"fieldname": "commission_rate",
|
||||
"fieldtype": "Data",
|
||||
"fieldtype": "Percent",
|
||||
"label": "Commission Rate",
|
||||
"print_hide": 1
|
||||
},
|
||||
@@ -145,7 +145,7 @@
|
||||
"idx": 1,
|
||||
"is_tree": 1,
|
||||
"links": [],
|
||||
"modified": "2024-03-27 13:10:37.891377",
|
||||
"modified": "2026-06-21 12:52:33.742603",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Setup",
|
||||
"name": "Sales Person",
|
||||
@@ -184,4 +184,4 @@
|
||||
"sort_field": "creation",
|
||||
"sort_order": "ASC",
|
||||
"states": []
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user