Skip to content

Commit

Permalink
fix: promotional scheme min and max amount configuration
Browse files Browse the repository at this point in the history
(cherry picked from commit a8fd92d)
  • Loading branch information
rohitwaghchaure authored and mergify[bot] committed Sep 12, 2022
1 parent 82440e3 commit 702c16e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
other_fields = [
"min_qty",
"max_qty",
"min_amt",
"max_amt",
"min_amount",
"max_amount",
"priority",
"warehouse",
"threshold_percentage",
Expand Down Expand Up @@ -246,7 +246,11 @@ def prepare_pricing_rule(
def set_args(args, pr, doc, child_doc, discount_fields, child_doc_fields):
pr.update(args)
for field in other_fields + discount_fields:
pr.set(field, child_doc_fields.get(field))
target_field = field
if target_field in ["min_amount", "max_amount"]:
target_field = "min_amt" if field == "min_amount" else "max_amt"

pr.set(target_field, child_doc_fields.get(field))

pr.promotional_scheme_id = child_doc_fields.name
pr.promotional_scheme = doc.name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,23 @@ def test_change_applicable_for_in_promotional_scheme(self):
price_rules = frappe.get_all("Pricing Rule", filters={"promotional_scheme": ps.name})
self.assertEqual(price_rules, [])

def test_min_max_amount_configuration(self):
ps = make_promotional_scheme()
ps.price_discount_slabs[0].min_amount = 10
ps.price_discount_slabs[0].max_amount = 1000
ps.save()

price_rules_data = frappe.db.get_value(
"Pricing Rule", {"promotional_scheme": ps.name}, ["min_amt", "max_amt"], as_dict=1
)

self.assertEqual(price_rules_data.min_amt, 10)
self.assertEqual(price_rules_data.max_amt, 1000)

frappe.delete_doc("Promotional Scheme", ps.name)
price_rules = frappe.get_all("Pricing Rule", filters={"promotional_scheme": ps.name})
self.assertEqual(price_rules, [])


def make_promotional_scheme(**args):
args = frappe._dict(args)
Expand Down

0 comments on commit 702c16e

Please sign in to comment.