Merge pull request #24522 from rohitwaghchaure/fixed-pricing-rule-travis-issues-develop

fix: test cases for pricing rule
This commit is contained in:
rohitwaghchaure 2021-02-01 23:07:37 +05:30 committed by GitHub
commit f9642eb333
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 8 deletions

View File

@ -56,6 +56,7 @@ class TestPricingRule(unittest.TestCase):
self.assertEqual(details.get("discount_percentage"), 10)
prule = frappe.get_doc(test_record.copy())
prule.priority = 1
prule.applicable_for = "Customer"
prule.title = "_Test Pricing Rule for Customer"
self.assertRaises(MandatoryError, prule.insert)
@ -261,6 +262,7 @@ class TestPricingRule(unittest.TestCase):
"rate_or_discount": "Discount Percentage",
"rate": 0,
"discount_percentage": 17.5,
"priority": 1,
"company": "_Test Company"
}).insert()
@ -557,6 +559,7 @@ def make_pricing_rule(**args):
"rate": args.rate or 0.0,
"margin_rate_or_amount": args.margin_rate_or_amount or 0.0,
"condition": args.condition or '',
"priority": 1,
"apply_multiple_pricing_rules": args.apply_multiple_pricing_rules or 0
})

View File

@ -59,18 +59,17 @@ def sorted_by_priority(pricing_rules, args, doc=None):
pricing_rules_list = []
pricing_rule_dict = {}
priority = []
for pricing_rule in pricing_rules:
pricing_rule = filter_pricing_rules(args, pricing_rule, doc)
if pricing_rule:
if not pricing_rule.get('priority'):
pricing_rules_list.append(pricing_rule)
else:
priority.append(cint(pricing_rule.get('priority')))
pricing_rule['priority'] = 1
if pricing_rule.get('apply_multiple_pricing_rules'):
pricing_rule_dict.setdefault(cint(pricing_rule.get("priority")), []).append(pricing_rule)
if priority:
pricing_rules_list.extend(pricing_rule_dict.get(min(priority)))
for key in sorted(pricing_rule_dict):
pricing_rules_list.extend(pricing_rule_dict.get(key))
return pricing_rules_list or pricing_rules

View File

@ -624,8 +624,8 @@ class calculate_taxes_and_totals(object):
for d in get_applied_pricing_rules(item.pricing_rules):
pricing_rule = frappe.get_cached_doc('Pricing Rule', d)
if (pricing_rule.margin_rate_or_amount and pricing_rule.currency == self.doc.currency and
pricing_rule.margin_type in ['Amount', 'Percentage']):
if pricing_rule.margin_rate_or_amount and ((pricing_rule.currency == self.doc.currency and
pricing_rule.margin_type in ['Amount', 'Percentage']) or pricing_rule.margin_type == 'Percentage'):
item.margin_type = pricing_rule.margin_type
item.margin_rate_or_amount = pricing_rule.margin_rate_or_amount
has_margin = True