diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 65687c7c118..c5abaf1cb19 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -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 diff --git a/erpnext/patches/v16_0/convert_commission_rate_to_percent.py b/erpnext/patches/v16_0/convert_commission_rate_to_percent.py new file mode 100644 index 00000000000..1b0fa81e2e8 --- /dev/null +++ b/erpnext/patches/v16_0/convert_commission_rate_to_percent.py @@ -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) diff --git a/erpnext/selling/doctype/sales_team/sales_team.json b/erpnext/selling/doctype/sales_team/sales_team.json index e9d261ad066..a2cf5d66b2c 100644 --- a/erpnext/selling/doctype/sales_team/sales_team.json +++ b/erpnext/selling/doctype/sales_team/sales_team.json @@ -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 -} \ No newline at end of file +} diff --git a/erpnext/setup/doctype/sales_person/sales_person.json b/erpnext/setup/doctype/sales_person/sales_person.json index 57572c6d7d5..1486904e841 100644 --- a/erpnext/setup/doctype/sales_person/sales_person.json +++ b/erpnext/setup/doctype/sales_person/sales_person.json @@ -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": [] -} \ No newline at end of file +}