Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: qty filter not working if apply_multiple_pricing_rules is enabled #28877

Merged

Conversation

nextchamp-saqib
Copy link
Member

@nextchamp-saqib nextchamp-saqib commented Dec 14, 2021

filter_pricing_rules doesn't work in case of apply_multiple_pricing_rules checked
sorted_by_priority filters the pricing rules, if no pricing rules are found after filtering, all the pricing rules are returned back

def sorted_by_priority(pricing_rules, args, doc=None):
# If more than one pricing rules, then sort by priority
pricing_rules_list = []
pricing_rule_dict = {}
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_rule['priority'] = 1
if pricing_rule.get('apply_multiple_pricing_rules'):
pricing_rule_dict.setdefault(cint(pricing_rule.get("priority")), []).append(pricing_rule)
for key in sorted(pricing_rule_dict):
pricing_rules_list.extend(pricing_rule_dict.get(key))
return pricing_rules_list or pricing_rules

Testing Info
  1. Create a Pricing Rule for Buy 3 Get 10% Discount
    CleanShot 2021-12-14 at 15 00 25
  2. Create a Pricing Rule for Buy 3 Get 1 Free
    CleanShot 2021-12-14 at 15 01 09
  3. Create a Sales Invoice and the item on which the free item rule is set.
  4. Even if the Qty is < 3, the free item is added in the Sales Invoice
    CleanShot 2021-12-14 at 15 06 23

@codecov
Copy link

codecov bot commented Dec 14, 2021

Codecov Report

Merging #28877 (3da2cac) into develop (e85da7a) will increase coverage by 9.35%.
The diff coverage is 100.00%.

@@             Coverage Diff             @@
##           develop   #28877      +/-   ##
===========================================
+ Coverage    48.62%   57.98%   +9.35%     
===========================================
  Files         1127     1091      -36     
  Lines        67241    67842     +601     
===========================================
+ Hits         32699    39338    +6639     
+ Misses       34542    28504    -6038     
Impacted Files Coverage Δ
erpnext/accounts/doctype/pricing_rule/utils.py 70.55% <100.00%> (+23.34%) ⬆️
...tch_item_expiry_status/batch_item_expiry_status.py 69.23% <0.00%> (-25.00%) ⬇️
...wise_balance_history/batch_wise_balance_history.py 68.96% <0.00%> (-22.42%) ⬇️
...t/product_bundle_balance/product_bundle_balance.py 81.81% <0.00%> (-13.64%) ⬇️
erpnext/stock/doctype/price_list/price_list.py 62.74% <0.00%> (-11.77%) ⬇️
...er_invariant_check/stock_ledger_invariant_check.py 43.18% <0.00%> (-1.82%) ⬇️
...e/employee_benefit_claim/employee_benefit_claim.py 88.28% <0.00%> (-1.57%) ⬇️
...ype/account/chart_of_accounts/chart_of_accounts.py 77.39% <0.00%> (-0.54%) ⬇️
erpnext/hr/doctype/attendance/attendance.py 40.54% <0.00%> (-0.42%) ⬇️
...evenue_and_expense/deferred_revenue_and_expense.py 61.30% <0.00%> (-0.31%) ⬇️
... and 388 more

@ankush ankush modified the milestones: v13.17, v13.18 Dec 15, 2021
@ankush ankush modified the milestones: v13.18, v13.19 Jan 4, 2022
@nextchamp-saqib
Copy link
Member Author

nextchamp-saqib commented Jan 20, 2022

@deepeshgarg007 review once again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants