fix(pos): cannot ignore pricing rule for one particular invoice (#29222)
diff --git a/erpnext/accounts/doctype/pos_invoice/pos_invoice.py b/erpnext/accounts/doctype/pos_invoice/pos_invoice.py
index 11d59bc..134bccf 100644
--- a/erpnext/accounts/doctype/pos_invoice/pos_invoice.py
+++ b/erpnext/accounts/doctype/pos_invoice/pos_invoice.py
@@ -353,7 +353,6 @@
if not for_validate and not self.customer:
self.customer = profile.customer
- self.ignore_pricing_rule = profile.ignore_pricing_rule
self.account_for_change_amount = profile.get('account_for_change_amount') or self.account_for_change_amount
self.set_warehouse = profile.get('warehouse') or self.set_warehouse
diff --git a/erpnext/accounts/doctype/pos_invoice/test_pos_invoice.py b/erpnext/accounts/doctype/pos_invoice/test_pos_invoice.py
index 7d31e0a..56479a0 100644
--- a/erpnext/accounts/doctype/pos_invoice/test_pos_invoice.py
+++ b/erpnext/accounts/doctype/pos_invoice/test_pos_invoice.py
@@ -556,6 +556,37 @@
batch.cancel()
batch.delete()
+ def test_ignore_pricing_rule(self):
+ from erpnext.accounts.doctype.pricing_rule.test_pricing_rule import make_pricing_rule
+
+ item_price = frappe.get_doc({
+ 'doctype': 'Item Price',
+ 'item_code': '_Test Item',
+ 'price_list': '_Test Price List',
+ 'price_list_rate': '450',
+ })
+ item_price.insert()
+ pr = make_pricing_rule(selling=1, priority=5, discount_percentage=10)
+ pr.save()
+ pos_inv = create_pos_invoice(qty=1, do_not_submit=1)
+ pos_inv.items[0].rate = 300
+ pos_inv.save()
+ self.assertEquals(pos_inv.items[0].discount_percentage, 10)
+ # rate shouldn't change
+ self.assertEquals(pos_inv.items[0].rate, 405)
+
+ pos_inv.ignore_pricing_rule = 1
+ pos_inv.items[0].rate = 300
+ pos_inv.save()
+ self.assertEquals(pos_inv.ignore_pricing_rule, 1)
+ # rate should change since pricing rules are ignored
+ self.assertEquals(pos_inv.items[0].rate, 300)
+
+ item_price.delete()
+ pos_inv.delete()
+ pr.delete()
+
+
def create_pos_invoice(**args):
args = frappe._dict(args)
pos_profile = None
diff --git a/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py
index 314c894..5746a84 100644
--- a/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py
+++ b/erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py
@@ -650,7 +650,7 @@
"rate": args.rate or 0.0,
"margin_rate_or_amount": args.margin_rate_or_amount or 0.0,
"condition": args.condition or '',
- "priority": 1,
+ "priority": args.priority or 1,
"discount_amount": args.discount_amount or 0.0,
"apply_multiple_pricing_rules": args.apply_multiple_pricing_rules or 0
})
@@ -676,6 +676,8 @@
if args.get(applicable_for):
doc.db_set(applicable_for, args.get(applicable_for))
+ return doc
+
def setup_pricing_rule_data():
if not frappe.db.exists('Campaign', '_Test Campaign'):
frappe.get_doc({