mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-21 14:09:19 +00:00
fix(test): pass price_list_rate only if pricing rule has to be removed
(cherry picked from commit 6fa406dd04)
This commit is contained in:
committed by
mergify-bot
parent
fc67f02ffc
commit
91f65da4ec
@@ -586,23 +586,29 @@ class TestPOSInvoice(unittest.TestCase):
|
|||||||
item_price.insert()
|
item_price.insert()
|
||||||
pr = make_pricing_rule(selling=1, priority=5, discount_percentage=10)
|
pr = make_pricing_rule(selling=1, priority=5, discount_percentage=10)
|
||||||
pr.save()
|
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
|
try:
|
||||||
pos_inv.items[0].rate = 300
|
pos_inv = create_pos_invoice(qty=1, do_not_submit=1)
|
||||||
pos_inv.save()
|
pos_inv.items[0].rate = 300
|
||||||
self.assertEquals(pos_inv.ignore_pricing_rule, 1)
|
pos_inv.save()
|
||||||
# rate should change since pricing rules are ignored
|
self.assertEquals(pos_inv.items[0].discount_percentage, 10)
|
||||||
self.assertEquals(pos_inv.items[0].rate, 300)
|
# rate shouldn't change
|
||||||
|
self.assertEquals(pos_inv.items[0].rate, 405)
|
||||||
|
|
||||||
item_price.delete()
|
pos_inv.ignore_pricing_rule = 1
|
||||||
pos_inv.delete()
|
pos_inv.save()
|
||||||
pr.delete()
|
self.assertEquals(pos_inv.ignore_pricing_rule, 1)
|
||||||
|
# rate should reset since pricing rules are ignored
|
||||||
|
self.assertEquals(pos_inv.items[0].rate, 450)
|
||||||
|
|
||||||
|
pos_inv.items[0].rate = 300
|
||||||
|
pos_inv.save()
|
||||||
|
self.assertEquals(pos_inv.items[0].rate, 300)
|
||||||
|
|
||||||
|
finally:
|
||||||
|
item_price.delete()
|
||||||
|
pos_inv.delete()
|
||||||
|
pr.delete()
|
||||||
|
|
||||||
|
|
||||||
def create_pos_invoice(**args):
|
def create_pos_invoice(**args):
|
||||||
|
|||||||
@@ -251,13 +251,16 @@ def get_pricing_rule_for_item(args, price_list_rate=0, doc=None, for_validate=Fa
|
|||||||
"parent": args.parent,
|
"parent": args.parent,
|
||||||
"parenttype": args.parenttype,
|
"parenttype": args.parenttype,
|
||||||
"child_docname": args.get('child_docname'),
|
"child_docname": args.get('child_docname'),
|
||||||
"price_list_rate": args.get('price_list_rate')
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if args.ignore_pricing_rule or not args.item_code:
|
if args.ignore_pricing_rule or not args.item_code:
|
||||||
if frappe.db.exists(args.doctype, args.name) and args.get("pricing_rules"):
|
if frappe.db.exists(args.doctype, args.name) and args.get("pricing_rules"):
|
||||||
item_details = remove_pricing_rule_for_item(args.get("pricing_rules"),
|
item_details = remove_pricing_rule_for_item(
|
||||||
item_details, args.get('item_code'))
|
args.get("pricing_rules"),
|
||||||
|
item_details,
|
||||||
|
item_code=args.get("item_code"),
|
||||||
|
rate=args.get("price_list_rate"),
|
||||||
|
)
|
||||||
return item_details
|
return item_details
|
||||||
|
|
||||||
update_args_for_pricing_rule(args)
|
update_args_for_pricing_rule(args)
|
||||||
@@ -310,8 +313,12 @@ def get_pricing_rule_for_item(args, price_list_rate=0, doc=None, for_validate=Fa
|
|||||||
if not doc: return item_details
|
if not doc: return item_details
|
||||||
|
|
||||||
elif args.get("pricing_rules"):
|
elif args.get("pricing_rules"):
|
||||||
item_details = remove_pricing_rule_for_item(args.get("pricing_rules"),
|
item_details = remove_pricing_rule_for_item(
|
||||||
item_details, args.get('item_code'))
|
args.get("pricing_rules"),
|
||||||
|
item_details,
|
||||||
|
item_code=args.get("item_code"),
|
||||||
|
rate=args.get("price_list_rate"),
|
||||||
|
)
|
||||||
|
|
||||||
return item_details
|
return item_details
|
||||||
|
|
||||||
@@ -392,7 +399,7 @@ def apply_price_discount_rule(pricing_rule, item_details, args):
|
|||||||
item_details[field] += (pricing_rule.get(field, 0)
|
item_details[field] += (pricing_rule.get(field, 0)
|
||||||
if pricing_rule else args.get(field, 0))
|
if pricing_rule else args.get(field, 0))
|
||||||
|
|
||||||
def remove_pricing_rule_for_item(pricing_rules, item_details, item_code=None):
|
def remove_pricing_rule_for_item(pricing_rules, item_details, item_code=None, rate=None):
|
||||||
from erpnext.accounts.doctype.pricing_rule.utils import (
|
from erpnext.accounts.doctype.pricing_rule.utils import (
|
||||||
get_applied_pricing_rules,
|
get_applied_pricing_rules,
|
||||||
get_pricing_rule_items,
|
get_pricing_rule_items,
|
||||||
@@ -405,7 +412,7 @@ def remove_pricing_rule_for_item(pricing_rules, item_details, item_code=None):
|
|||||||
if pricing_rule.rate_or_discount == 'Discount Percentage':
|
if pricing_rule.rate_or_discount == 'Discount Percentage':
|
||||||
item_details.discount_percentage = 0.0
|
item_details.discount_percentage = 0.0
|
||||||
item_details.discount_amount = 0.0
|
item_details.discount_amount = 0.0
|
||||||
item_details.rate = item_details.get('price_list_rate', 0)
|
item_details.rate = rate or 0.0
|
||||||
|
|
||||||
if pricing_rule.rate_or_discount == 'Discount Amount':
|
if pricing_rule.rate_or_discount == 'Discount Amount':
|
||||||
item_details.discount_amount = 0.0
|
item_details.discount_amount = 0.0
|
||||||
@@ -436,9 +443,12 @@ def remove_pricing_rules(item_list):
|
|||||||
out = []
|
out = []
|
||||||
for item in item_list:
|
for item in item_list:
|
||||||
item = frappe._dict(item)
|
item = frappe._dict(item)
|
||||||
if item.get('pricing_rules'):
|
if item.get("pricing_rules"):
|
||||||
out.append(remove_pricing_rule_for_item(item.get("pricing_rules"),
|
out.append(
|
||||||
item, item.item_code))
|
remove_pricing_rule_for_item(
|
||||||
|
item.get("pricing_rules"), item, item.item_code, item.get("price_list_rate")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
return out
|
return out
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user