Skip to content

Commit

Permalink
fix: currency wise pricing rule not working
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitwaghchaure authored and conncampbell committed Jan 9, 2022
1 parent a33101e commit 48a810a
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
69 changes: 69 additions & 0 deletions erpnext/accounts/doctype/pricing_rule/test_pricing_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,75 @@ def test_item_price_with_pricing_rule(self):
frappe.get_doc("Item Price", {"item_code": "Water Flask"}).delete()
item.delete()

def test_pricing_rule_for_different_currency(self):
make_item("Test Sanitizer Item")

pricing_rule_record = {
"doctype": "Pricing Rule",
"title": "_Test Sanitizer Rule",
"apply_on": "Item Code",
"items": [{
"item_code": "Test Sanitizer Item",
}],
"selling": 1,
"currency": "INR",
"rate_or_discount": "Rate",
"rate": 0,
"priority": 2,
"margin_type": "Percentage",
"margin_rate_or_amount": 0.0,
"company": "_Test Company"
}

rule = frappe.get_doc(pricing_rule_record)
rule.rate_or_discount = 'Rate'
rule.rate = 100.0
rule.insert()

rule1 = frappe.get_doc(pricing_rule_record)
rule1.currency = 'USD'
rule1.rate_or_discount = 'Rate'
rule1.rate = 2.0
rule1.priority = 1
rule1.insert()

args = frappe._dict({
"item_code": "Test Sanitizer Item",
"company": "_Test Company",
"price_list": "_Test Price List",
"currency": "USD",
"doctype": "Sales Invoice",
"conversion_rate": 1,
"price_list_currency": "_Test Currency",
"plc_conversion_rate": 1,
"order_type": "Sales",
"customer": "_Test Customer",
"name": None,
"transaction_date": frappe.utils.nowdate()
})

details = get_item_details(args)
self.assertEqual(details.price_list_rate, 2.0)


args = frappe._dict({
"item_code": "Test Sanitizer Item",
"company": "_Test Company",
"price_list": "_Test Price List",
"currency": "INR",
"doctype": "Sales Invoice",
"conversion_rate": 1,
"price_list_currency": "_Test Currency",
"plc_conversion_rate": 1,
"order_type": "Sales",
"customer": "_Test Customer",
"name": None,
"transaction_date": frappe.utils.nowdate()
})

details = get_item_details(args)
self.assertEqual(details.price_list_rate, 100.0)

def test_pricing_rule_for_transaction(self):
make_item("Water Flask 1")
frappe.delete_doc_if_exists('Pricing Rule', '_Test Pricing Rule')
Expand Down
5 changes: 5 additions & 0 deletions erpnext/accounts/doctype/pricing_rule/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,11 @@ def filter_pricing_rules(args, pricing_rules, doc=None):
else:
p.variant_of = None

if len(pricing_rules) > 1:
filtered_rules = list(filter(lambda x: x.currency==args.get('currency'), pricing_rules))
if filtered_rules:
pricing_rules = filtered_rules

# find pricing rule with highest priority
if pricing_rules:
max_priority = max(cint(p.priority) for p in pricing_rules)
Expand Down

0 comments on commit 48a810a

Please sign in to comment.