mirror of
https://github.com/frappe/erpnext.git
synced 2026-02-16 03:03:50 +00:00
fix: validate that discount amount cannot exceed total before discount
(cherry picked from commit f4f79d99e4)
# Conflicts:
# erpnext/controllers/taxes_and_totals.py
This commit is contained in:
@@ -7,8 +7,12 @@ import json
|
||||
import frappe
|
||||
from frappe import _, scrub
|
||||
from frappe.model.document import Document
|
||||
<<<<<<< HEAD
|
||||
from frappe.utils import cint, flt, round_based_on_smallest_currency_fraction
|
||||
from frappe.utils.deprecations import deprecated
|
||||
=======
|
||||
from frappe.utils import cint, flt, fmt_money, round_based_on_smallest_currency_fraction
|
||||
>>>>>>> f4f79d99e4 (fix: validate that discount amount cannot exceed total before discount)
|
||||
|
||||
import erpnext
|
||||
from erpnext.accounts.doctype.journal_entry.journal_entry import get_exchange_rate
|
||||
@@ -682,6 +686,22 @@ class calculate_taxes_and_totals:
|
||||
self.doc.precision("discount_amount"),
|
||||
)
|
||||
|
||||
discount_amount = self.doc.discount_amount or 0
|
||||
grand_total = self.doc.grand_total
|
||||
|
||||
# validate that discount amount cannot exceed the total before discount
|
||||
if grand_total * (discount_amount - grand_total) > 0:
|
||||
frappe.throw(
|
||||
_(
|
||||
"Additional Discount Amount ({discount_amount}) cannot exceed "
|
||||
"the total before such discount ({total_before_discount})"
|
||||
).format(
|
||||
discount_amount=self.doc.get_formatted("discount_amount"),
|
||||
total_before_discount=self.doc.get_formatted("grand_total"),
|
||||
),
|
||||
title=_("Invalid Discount Amount"),
|
||||
)
|
||||
|
||||
def apply_discount_amount(self):
|
||||
if self.doc.discount_amount:
|
||||
if not self.doc.apply_discount_on:
|
||||
|
||||
Reference in New Issue
Block a user