mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-22 06:29:20 +00:00
fix: validate total commission amount to be greater than 0
This commit is contained in:
@@ -10,16 +10,21 @@ from frappe.utils import get_link_to_form
|
|||||||
class SalesCommission(Document):
|
class SalesCommission(Document):
|
||||||
def validate(self):
|
def validate(self):
|
||||||
self.validate_from_to_dates()
|
self.validate_from_to_dates()
|
||||||
|
self.validate_amount()
|
||||||
self.validate_salary_component()
|
self.validate_salary_component()
|
||||||
self.calculate_total_contribution_and_total_commission_amount()
|
self.calculate_total_contribution_and_total_commission_amount()
|
||||||
|
|
||||||
def validate_from_to_dates(self):
|
def validate_from_to_dates(self):
|
||||||
return super().validate_from_to_dates("from_date", "to_date")
|
return super().validate_from_to_dates("from_date", "to_date")
|
||||||
|
|
||||||
|
def validate_amount(self):
|
||||||
|
if self.total_commission_amount <= 0:
|
||||||
|
frappe.throw(_("Total Commission Amount should be greater than 0"))
|
||||||
|
|
||||||
def validate_salary_component(self):
|
def validate_salary_component(self):
|
||||||
if self.pay_via_salary:
|
if self.pay_via_salary and not frappe.db.get_single_value(
|
||||||
if not frappe.db.get_single_value("Payroll Settings", "salary_component_for_sales_commission"):
|
"Payroll Settings", "salary_component_for_sales_commission"):
|
||||||
frappe.throw(_("Please set {0} in {1}").format(frappe.bold("Salary Component for Sales Commission"), get_link_to_form("Payroll Settings", "Payroll Settings")))
|
frappe.throw(_("Please set {0} in {1}").format(frappe.bold("Salary Component for Sales Commission"), get_link_to_form("Payroll Settings", "Payroll Settings")))
|
||||||
|
|
||||||
def on_submit(self):
|
def on_submit(self):
|
||||||
self.db_set("status", "Unpaid")
|
self.db_set("status", "Unpaid")
|
||||||
@@ -114,13 +119,14 @@ class SalesCommission(Document):
|
|||||||
self.db_set("status", "Paid")
|
self.db_set("status", "Paid")
|
||||||
|
|
||||||
def add_references(self, doc):
|
def add_references(self, doc):
|
||||||
reference = {}
|
reference = {
|
||||||
reference['reference_doctype'] = "Sales Commission"
|
'reference_doctype': 'Sales Commission',
|
||||||
reference['reference_name'] = self.name
|
'reference_name': self.name,
|
||||||
reference['due_date'] = self.to_date
|
'due_date': self.to_date,
|
||||||
reference['total_amount'] = self.total_commission_amount
|
'total_amount': self.total_commission_amount,
|
||||||
reference['outstanding_amount'] = self.total_commission_amount
|
'outstanding_amount': self.total_commission_amount,
|
||||||
reference['allocated_amount'] = self.total_commission_amount
|
'allocated_amount': self.total_commission_amount,
|
||||||
|
}
|
||||||
doc.append("references", reference)
|
doc.append("references", reference)
|
||||||
|
|
||||||
def add(record, sales_person):
|
def add(record, sales_person):
|
||||||
|
|||||||
Reference in New Issue
Block a user