|
|
@@ -386,3 +386,63 @@ class TestAnAbsoluteDiscountBenefit(TestCase):
|
|
386
|
386
|
assert line.line_price_excl_tax_incl_discounts == D(0)
|
|
387
|
387
|
assert line.line_price_incl_tax_incl_discounts == D(0)
|
|
388
|
388
|
assert basket.total_incl_tax == 0
|
|
|
389
|
+
|
|
|
390
|
+ def test_is_discountable_works_on_child_level(self):
|
|
|
391
|
+ rng = factories.RangeFactory(includes_all_products=True, name="klaazien")
|
|
|
392
|
+ benefit = factories.BenefitFactory(
|
|
|
393
|
+ range=rng, type=models.Benefit.PERCENTAGE, value=5, max_affected_items=100
|
|
|
394
|
+ )
|
|
|
395
|
+ condition = models.ValueCondition.objects.create(
|
|
|
396
|
+ range=rng,
|
|
|
397
|
+ type=models.Condition.COUNT,
|
|
|
398
|
+ value=1
|
|
|
399
|
+ )
|
|
|
400
|
+
|
|
|
401
|
+ factories.ConditionalOfferFactory(
|
|
|
402
|
+ priority=99999,
|
|
|
403
|
+ exclusive=False,
|
|
|
404
|
+ condition=condition,
|
|
|
405
|
+ benefit=benefit
|
|
|
406
|
+ )
|
|
|
407
|
+
|
|
|
408
|
+ basket = factories.create_basket(empty=True)
|
|
|
409
|
+
|
|
|
410
|
+ prod1 = factories.create_product(title="Gert is friends with Berrie", is_discountable=True, price=100)
|
|
|
411
|
+
|
|
|
412
|
+ parent_discountable_product = factories.create_product(structure='parent', is_discountable=True)
|
|
|
413
|
+ child = factories.create_product(
|
|
|
414
|
+ title="Undiscountable variant",
|
|
|
415
|
+ structure='child',
|
|
|
416
|
+ parent=parent_discountable_product,
|
|
|
417
|
+ is_discountable=False,
|
|
|
418
|
+ price=100
|
|
|
419
|
+ )
|
|
|
420
|
+
|
|
|
421
|
+ parent_product = factories.create_product(structure='parent', is_discountable=False)
|
|
|
422
|
+ child_discountable = factories.create_product(
|
|
|
423
|
+ title="Discountable variant ", structure='child', parent=parent_product, is_discountable=True, price=200)
|
|
|
424
|
+
|
|
|
425
|
+ basket.add_product(prod1, quantity=1)
|
|
|
426
|
+ basket.add_product(child, quantity=2)
|
|
|
427
|
+ basket.add_product(child_discountable, quantity=3)
|
|
|
428
|
+
|
|
|
429
|
+ Applicator().apply(basket)
|
|
|
430
|
+ line = basket.all_lines()
|
|
|
431
|
+ product_actual = benefit.can_apply_benefit(line[0])
|
|
|
432
|
+ assert product_actual
|
|
|
433
|
+ assert prod1.is_discountable
|
|
|
434
|
+ assert line[0].has_discount
|
|
|
435
|
+ assert line[0].discount_value == D(5)
|
|
|
436
|
+
|
|
|
437
|
+ variant_actual = benefit.can_apply_benefit(line[1])
|
|
|
438
|
+ assert not variant_actual
|
|
|
439
|
+ assert parent_discountable_product.is_discountable
|
|
|
440
|
+ assert not child.is_discountable
|
|
|
441
|
+ assert line[1].discount_value == D(0)
|
|
|
442
|
+
|
|
|
443
|
+ variant_discountable_actual = benefit.can_apply_benefit(line[2])
|
|
|
444
|
+ assert variant_discountable_actual
|
|
|
445
|
+ assert not parent_product.is_discountable
|
|
|
446
|
+ assert child_discountable.is_discountable
|
|
|
447
|
+ assert line[2].has_discount
|
|
|
448
|
+ assert line[2].discount_value == D(30)
|