mirror of
https://github.com/frappe/erpnext.git
synced 2026-08-16 16:08:39 +00:00
fix: address review comments on purchase partner commission PR
- Fix division-by-zero on PostgreSQL in purchase_partners_commission report by wrapping sum(amount_eligible_for_commission) with NULLIF(..., 0) - Replace lazy `from frappe import throw` with `frappe.throw()` in buying_controller.calculate_commission to match selling controller pattern - Fix indentation of purchase_partner() event handler in buying.js - Mirror server-side validation in JS: block commission_rate < 0 as well as > 100, with consistent error message "must be between 0 and 100" - Remove unused IntegrationTestCase import from test_purchase_partner.py - Add Purchase Partner Type fixtures (same types as Sales Partner Type) installed via setup wizard so generic records exist out of the box Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
"name": "Purchase Partners Commission",
|
||||
"owner": "Administrator",
|
||||
"prepared_report": 0,
|
||||
"query": "SELECT\n purchase_partner as \"Purchase Partner:Link/Purchase Partner:220\",\n sum(base_net_total) as \"Invoiced Amount (Excl. Tax):Currency:220\",\n sum(amount_eligible_for_commission) as \"Amount Eligible for Commission:Currency:220\",\n sum(total_commission) as \"Total Commission:Currency:170\",\n sum(total_commission)*100 / sum(amount_eligible_for_commission) as \"Average Commission Rate:Percent:220\"\nFROM\n `tabPurchase Invoice`\nWHERE\n docstatus = 1\n AND IFNULL(base_net_total, 0) > 0\n AND IFNULL(total_commission, 0) > 0\nGROUP BY\n purchase_partner\nORDER BY\n sum(total_commission) DESC",
|
||||
"query": "SELECT\n purchase_partner as \"Purchase Partner:Link/Purchase Partner:220\",\n sum(base_net_total) as \"Invoiced Amount (Excl. Tax):Currency:220\",\n sum(amount_eligible_for_commission) as \"Amount Eligible for Commission:Currency:220\",\n sum(total_commission) as \"Total Commission:Currency:170\",\n sum(total_commission)*100 / NULLIF(sum(amount_eligible_for_commission), 0) as \"Average Commission Rate:Percent:220\"\nFROM\n `tabPurchase Invoice`\nWHERE\n docstatus = 1\n AND IFNULL(base_net_total, 0) > 0\n AND IFNULL(total_commission, 0) > 0\nGROUP BY\n purchase_partner\nORDER BY\n sum(total_commission) DESC",
|
||||
"ref_doctype": "Purchase Invoice",
|
||||
"report_name": "Purchase Partners Commission",
|
||||
"report_type": "Query Report",
|
||||
|
||||
@@ -391,9 +391,7 @@ class BuyingController(SubcontractingController):
|
||||
self.round_floats_in(self, ("amount_eligible_for_commission", "commission_rate"))
|
||||
|
||||
if not (0 <= self.commission_rate <= 100.0):
|
||||
from frappe import throw
|
||||
|
||||
throw(
|
||||
frappe.throw(
|
||||
"{} {}".format(
|
||||
_(self.meta.get_label("commission_rate")),
|
||||
_("must be between 0 and 100"),
|
||||
|
||||
@@ -474,8 +474,8 @@ erpnext.buying = {
|
||||
}
|
||||
|
||||
purchase_partner() {
|
||||
this.calculate_purchase_commission();
|
||||
}
|
||||
this.calculate_purchase_commission();
|
||||
}
|
||||
|
||||
commission_rate() {
|
||||
if (
|
||||
@@ -509,8 +509,7 @@ erpnext.buying = {
|
||||
calculate_purchase_commission() {
|
||||
if (!this.frm.fields_dict.commission_rate || this.frm.doc.docstatus === 1) return;
|
||||
|
||||
if (this.frm.doc.commission_rate > 100) {
|
||||
this.frm.set_value("commission_rate", 100);
|
||||
if (this.frm.doc.commission_rate < 0 || this.frm.doc.commission_rate > 100) {
|
||||
frappe.throw(
|
||||
`${__(
|
||||
frappe.meta.get_label(
|
||||
@@ -518,7 +517,7 @@ erpnext.buying = {
|
||||
"commission_rate",
|
||||
this.frm.doc.name
|
||||
)
|
||||
)} ${__("cannot be greater than 100")}`
|
||||
)} ${__("must be between 0 and 100")}`
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
# License: GNU General Public License v3. See license.txt
|
||||
|
||||
import frappe
|
||||
from frappe.tests import IntegrationTestCase
|
||||
|
||||
from erpnext.buying.doctype.purchase_order.test_purchase_order import create_purchase_order
|
||||
from erpnext.tests.utils import ERPNextTestSuite
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
Channel Partner
|
||||
Distributor
|
||||
Dealer
|
||||
Agent
|
||||
Retailer
|
||||
Implementation Partner
|
||||
Reseller
|
||||
@@ -328,6 +328,7 @@ def install(country=None):
|
||||
("Industry Type", "industry", "industry_type.txt"),
|
||||
("UTM Source", "name", "marketing_source.txt"),
|
||||
("Sales Partner Type", "sales_partner_type", "sales_partner_type.txt"),
|
||||
("Purchase Partner Type", "purchase_partner_type", "purchase_partner_type.txt"),
|
||||
):
|
||||
records += [{"doctype": doctype, title_field: title} for title in read_lines(filename)]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user