Skip to content

Commit

Permalink
Merge 0dd0c25 into 7777e43
Browse files Browse the repository at this point in the history
  • Loading branch information
acsonefho committed Jun 14, 2019
2 parents 7777e43 + 0dd0c25 commit 55bfe60
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
10 changes: 6 additions & 4 deletions sale_promotion_rule/models/sale_promotion_rule.py
Expand Up @@ -264,13 +264,15 @@ def _remove_promotions_lines(self, lines):
@api.multi
def _apply(self, orders):
for rule in self:
orders = orders.filtered(
orders_valid = orders.filtered(
lambda o, r=rule: r._is_promotion_valid(o))
rule._apply_rule_to_order_lines(orders.mapped('order_line'))
if not orders_valid:
continue
rule._apply_rule_to_order_lines(orders_valid.mapped('order_line'))
if rule.rule_type == 'coupon':
orders.write({'coupon_promotion_rule_id': rule.id})
orders_valid.write({'coupon_promotion_rule_id': rule.id})
else:
orders.write({'promotion_rule_ids': [(4, rule.id)]})
orders_valid.write({'promotion_rule_ids': [(4, rule.id)]})

@api.multi
def _apply_rule_to_order_lines(self, lines):
Expand Down
19 changes: 19 additions & 0 deletions sale_promotion_rule/tests/test_promotion.py
Expand Up @@ -128,3 +128,22 @@ def test_exclusive_rule(self):
self.assertEqual(
self.promotion_rule_coupon, self.sale.applied_promotion_rule_ids
)

def test_multi_promotion_rules(self):
"""
Ensure it's working in case of multi available promotions.
So the first promotion rule (promotion_rule_auto) should be check
(and not available due to minimal amount), then the promo_copy should
be check and applied.
:return:
"""
promo_copy = self.promotion_rule_auto.copy({
'name': 'Almost free',
})
self.promotion_rule_auto.write({
'minimal_amount': 999999,
})
self.sale.apply_promotions()
for line in self.sale.order_line:
self.check_discount_rule_set(line, promo_copy)
return

0 comments on commit 55bfe60

Please sign in to comment.