diff --git a/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py index 25140745ebaf590d75c45665e64c94fd64160504..ea01f3be0c94bd610a5064dd9f1b502ebcbbddf8 100644 --- a/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py +++ b/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py @@ -1300,6 +1300,72 @@ class TestPricingRule(unittest.TestCase): item_group_rule.delete() item_code_rule.delete() + def test_pricing_rule_override(self): + """ + Pricing rule validation on save can be overriden by adding a server script triggered `Before Validate` + with the following code: `doc.flags.ignore_pricing_rule = True` + """ + + from erpnext.selling.doctype.quotation.test_quotation import make_quotation + + test_record = { + "doctype": "Pricing Rule", + "title": "_Test Pricing Rule", + "apply_on": "Item Code", + "items": [{"item_code": "_Test Item"}], + "currency": "USD", + "selling": 1, + "rate_or_discount": "Discount Percentage", + "rate": 0, + "discount_percentage": 10, + "company": "_Test Company", + } + frappe.get_doc(test_record.copy()).insert() + + item_price = frappe.new_doc("Item Price") + item_price.item_code = "_Test Item" + item_price.uom = "_Test UOM" + item_price.price_list = "Standard Selling" + item_price.price_list_rate = 100.0 + item_price.insert() + + quotation = make_quotation( + company="_Test Company", currency="USD", item="_Test Item", uom="_Test UOM", do_not_submit=True + ) + + self.assertEqual(quotation.items[0].rate, 90.0) + + quotation.items[0].rate = 100 + quotation.items[0].discount_percentage = 0.0 + quotation.items[0].discount_amount = 0.0 + quotation.flags.ignore_pricing_rule = True + quotation.save() + + quotation.reload() + self.assertEqual(quotation.items[0].rate, 100.0) + + quotation.items[0].rate = 100 + quotation.items[0].discount_percentage = 0.0 + quotation.items[0].discount_amount = 0.0 + quotation.flags.ignore_pricing_rule = False + quotation.save() + + quotation.reload() + self.assertEqual(quotation.items[0].rate, 90.0) + + quotation.append( + "items", + { + "item_code": "_Test Item", + "qty": 10, + "uom": "_Test UOM", + }, + ) + quotation.save() + self.assertEqual(quotation.items[1].rate, 90.0) + + frappe.delete_doc("Item Price", item_price.name, force=True) + test_dependencies = ["Campaign"]