feat: pricing rule enhancements
diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py
index 8184e92..b3880be 100644
--- a/erpnext/controllers/taxes_and_totals.py
+++ b/erpnext/controllers/taxes_and_totals.py
@@ -59,9 +59,12 @@
if item.discount_percentage == 100:
item.rate = 0.0
- elif not item.rate:
+ elif (not item.rate or item.discount_percentage > 0) and item.price_list_rate:
item.rate = flt(item.price_list_rate *
(1.0 - (item.discount_percentage / 100.0)), item.precision("rate"))
+ item.discount_amount = item.price_list_rate * (item.discount_percentage / 100.0)
+ elif item.discount_amount and item.price_list_rate:
+ item.rate = item.price_list_rate - item.discount_amount
if item.doctype in ['Quotation Item', 'Sales Order Item', 'Delivery Note Item', 'Sales Invoice Item']:
item.rate_with_margin, item.base_rate_with_margin = self.calculate_margin(item)
@@ -69,8 +72,8 @@
if flt(item.rate_with_margin) > 0:
item.rate = flt(item.rate_with_margin * (1.0 - (item.discount_percentage / 100.0)), item.precision("rate"))
item.discount_amount = item.rate_with_margin - item.rate
- elif flt(item.price_list_rate) > 0:
- item.discount_amount = item.price_list_rate - item.rate
+ elif flt(item.price_list_rate) > 0 and not item.discount_amount:
+ item.discount_amount = item.price_list_rate - item.rate
item.net_rate = item.rate
item.amount = flt(item.rate * item.qty, item.precision("amount"))
@@ -537,16 +540,17 @@
rate_with_margin = 0.0
base_rate_with_margin = 0.0
if item.price_list_rate:
- if item.pricing_rule and not self.doc.ignore_pricing_rule:
- pricing_rule = frappe.get_doc('Pricing Rule', item.pricing_rule)
+ if item.pricing_rules and not self.doc.ignore_pricing_rule:
+ for d in item.pricing_rules.split(','):
+ pricing_rule = frappe.get_doc('Pricing Rule', d)
- if (pricing_rule.margin_type == 'Amount' and pricing_rule.currency == self.doc.currency)\
- or (pricing_rule.margin_type == 'Percentage'):
- item.margin_type = pricing_rule.margin_type
- item.margin_rate_or_amount = pricing_rule.margin_rate_or_amount
- else:
- item.margin_type = None
- item.margin_rate_or_amount = 0.0
+ if (pricing_rule.margin_type == 'Amount' and pricing_rule.currency == self.doc.currency)\
+ or (pricing_rule.margin_type == 'Percentage'):
+ item.margin_type = pricing_rule.margin_type
+ item.margin_rate_or_amount = pricing_rule.margin_rate_or_amount
+ else:
+ item.margin_type = None
+ item.margin_rate_or_amount = 0.0
if item.margin_type and item.margin_rate_or_amount:
margin_value = item.margin_rate_or_amount if item.margin_type == 'Amount' else flt(item.price_list_rate) * flt(item.margin_rate_or_amount) / 100