added test cases
diff --git a/erpnext/accounts/doctype/pricing_rule/pricing_rule.json b/erpnext/accounts/doctype/pricing_rule/pricing_rule.json
index c681c89..cc8ed4b 100644
--- a/erpnext/accounts/doctype/pricing_rule/pricing_rule.json
+++ b/erpnext/accounts/doctype/pricing_rule/pricing_rule.json
@@ -504,10 +504,10 @@
},
{
"default": "0",
- "depends_on": "eval:in_list(['Discount Percentage', 'Discount Amount'], doc.rate_or_discount) && doc.apply_multiple_pricing_rules",
+ "depends_on": "eval:in_list(['Discount Percentage'], doc.rate_or_discount) && doc.apply_multiple_pricing_rules",
"fieldname": "apply_discount_on_rate",
"fieldtype": "Check",
- "label": "Apply Discount on Rate"
+ "label": "Apply Discount on Discounted Rate"
},
{
"default": "0",
@@ -563,7 +563,7 @@
"icon": "fa fa-gift",
"idx": 1,
"links": [],
- "modified": "2020-08-26 12:24:44.740734",
+ "modified": "2020-10-28 16:53:14.416172",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Pricing Rule",
diff --git a/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py
index 3555ca8..22a031c 100644
--- a/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py
+++ b/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py
@@ -385,7 +385,7 @@
so.load_from_db()
self.assertEqual(so.items[1].is_free_item, 1)
self.assertEqual(so.items[1].item_code, "_Test Item 2")
-
+
def test_cumulative_pricing_rule(self):
frappe.delete_doc_if_exists('Pricing Rule', '_Test Cumulative Pricing Rule')
test_record = {
@@ -429,34 +429,61 @@
details = get_item_details(args)
self.assertTrue(details)
-
+
def test_pricing_rule_for_condition(self):
frappe.delete_doc_if_exists("Pricing Rule", "_Test Pricing Rule")
-
+
make_pricing_rule(selling=1, margin_type="Percentage", \
condition="customer=='_Test Customer 1' and is_return==0", discount_percentage=10)
-
+
# Incorrect Customer and Correct is_return value
si = create_sales_invoice(do_not_submit=True, customer="_Test Customer 2", is_return=0)
si.items[0].price_list_rate = 1000
si.submit()
item = si.items[0]
self.assertEquals(item.rate, 100)
-
+
# Correct Customer and Incorrect is_return value
si = create_sales_invoice(do_not_submit=True, customer="_Test Customer 1", is_return=1, qty=-1)
si.items[0].price_list_rate = 1000
si.submit()
item = si.items[0]
self.assertEquals(item.rate, 100)
-
+
# Correct Customer and correct is_return value
si = create_sales_invoice(do_not_submit=True, customer="_Test Customer 1", is_return=0)
si.items[0].price_list_rate = 1000
si.submit()
item = si.items[0]
self.assertEquals(item.rate, 900)
-
+
+ def test_multiple_pricing_rules(self):
+ make_pricing_rule(discount_percentage=20, selling=1, priority=1, apply_multiple_pricing_rules=1,
+ title="_Test Pricing Rule 1")
+ make_pricing_rule(discount_percentage=10, selling=1, title="_Test Pricing Rule 2", priority=2,
+ apply_multiple_pricing_rules=1)
+ si = create_sales_invoice(do_not_submit=True, customer="_Test Customer 1", qty=1)
+ self.assertEqual(si.items[0].discount_percentage, 30)
+ si.delete()
+
+ frappe.delete_doc_if_exists("Pricing Rule", "_Test Pricing Rule 1")
+ frappe.delete_doc_if_exists("Pricing Rule", "_Test Pricing Rule 2")
+
+ def test_multiple_pricing_rules_with_apply_discount_on_discounted_rate(self):
+ frappe.delete_doc_if_exists("Pricing Rule", "_Test Pricing Rule")
+
+ make_pricing_rule(discount_percentage=20, selling=1, priority=1, apply_multiple_pricing_rules=1,
+ title="_Test Pricing Rule 1")
+ make_pricing_rule(discount_percentage=10, selling=1, priority=2,
+ apply_discount_on_rate=1, title="_Test Pricing Rule 2", apply_multiple_pricing_rules=1)
+
+ si = create_sales_invoice(do_not_submit=True, customer="_Test Customer 1", qty=1)
+ self.assertEqual(si.items[0].discount_percentage, 28)
+ si.delete()
+
+ frappe.delete_doc_if_exists("Pricing Rule", "_Test Pricing Rule 1")
+ frappe.delete_doc_if_exists("Pricing Rule", "_Test Pricing Rule 2")
+
def make_pricing_rule(**args):
args = frappe._dict(args)
@@ -468,6 +495,7 @@
"applicable_for": args.applicable_for,
"selling": args.selling or 0,
"currency": "USD",
+ "apply_discount_on_rate": args.apply_discount_on_rate or 0,
"buying": args.buying or 0,
"min_qty": args.min_qty or 0.0,
"max_qty": args.max_qty or 0.0,
@@ -476,9 +504,13 @@
"rate": args.rate or 0.0,
"margin_type": args.margin_type,
"margin_rate_or_amount": args.margin_rate_or_amount or 0.0,
- "condition": args.condition or ''
+ "condition": args.condition or '',
+ "apply_multiple_pricing_rules": args.apply_multiple_pricing_rules or 0
})
+ if args.get("priority"):
+ doc.priority = args.get("priority")
+
apply_on = doc.apply_on.replace(' ', '_').lower()
child_table = {'Item Code': 'items', 'Item Group': 'item_groups', 'Brand': 'brands'}
doc.append(child_table.get(doc.apply_on), {
diff --git a/erpnext/accounts/doctype/pricing_rule/utils.py b/erpnext/accounts/doctype/pricing_rule/utils.py
index 1a58b1d..b003328 100644
--- a/erpnext/accounts/doctype/pricing_rule/utils.py
+++ b/erpnext/accounts/doctype/pricing_rule/utils.py
@@ -14,9 +14,8 @@
from erpnext.setup.doctype.item_group.item_group import get_child_item_groups
from erpnext.stock.doctype.warehouse.warehouse import get_child_warehouses
from erpnext.stock.get_item_details import get_conversion_factor
-from frappe import _, throw
-from frappe.utils import cint, flt, get_datetime, get_link_to_form, getdate, today
-
+from frappe import _, bold
+from frappe.utils import cint, flt, get_link_to_form, getdate, today, fmt_money
class MultiplePricingRuleConflict(frappe.ValidationError): pass
@@ -299,12 +298,13 @@
fieldname = field
if fieldname:
- msg = _("""If you {0} {1} quantities of the item <b>{2}</b>, the scheme <b>{3}</b>
- will be applied on the item.""").format(type_of_transaction, args.get(fieldname), item_code, args.rule_description)
+ msg = (_("If you {0} {1} quantities of the item {2}, the scheme {3} will be applied on the item.")
+ .format(type_of_transaction, args.get(fieldname), bold(item_code), bold(args.rule_description)))
if fieldname in ['min_amt', 'max_amt']:
- msg = _("""If you {0} {1} worth item <b>{2}</b>, the scheme <b>{3}</b> will be applied on the item.
- """).format(frappe.fmt_money(type_of_transaction, args.get(fieldname)), item_code, args.rule_description)
+ msg = (_("If you {0} {1} worth item {2}, the scheme {3} will be applied on the item.")
+ .format(type_of_transaction, fmt_money(args.get(fieldname), currency=args.get("currency")),
+ bold(item_code), bold(args.rule_description)))
frappe.msgprint(msg)