Skip to content

Commit

Permalink
New discountable full support for enabling double discount
Browse files Browse the repository at this point in the history
  • Loading branch information
joamag committed Dec 13, 2018
1 parent e19b211 commit 2017dcf
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 6 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ discount value for a bundle (bag or order) the arguments provided are the discou
value should be a valid float value for the discount (defaults to `None`)
* `BUDY_JOIN_DISCOUNT` (`bool`) - If both the voucher and the base discount values should be applied at the same time for
an order and/or bag or if instead only the largest of both should be used (defaults to `True`)
* `BUDY_FULL_DISCOUNTABLE` (`bool`) - If the discountable value (value eligible to be discounted) should include both the
sub total and the shipping costs, meaning that a end customer may not pay the shipping costs at all (if the discount covers that
value) or if otherwise only the sub total is eligible for discount (defaults to `False`)
* `BUDY_FULL_DISCOUNTABLE` (`bool`) - If the discountable value (value eligible to be discounted) should use the sub total
amount including lines with line level discount together with the shipping costs, meaning that an end customer may not pay the shipping costs
at all (if the discount covers that value) and also benefit from double discount (line and global level) or if otherwise only the
sub total with no line level discount (and without shipping costs) is eligible for discount (defaults to `False`)
* `BUDY_SHIPPING` (`str`) - String with the definition of the lambda function to be called for calculus of the
shipping costs for a bundle (bag or order) the arguments provided are the sub total, taxes, quantity and bundle and the return
value should be a valid float value for the shipping costs (defaults to `None`)
Expand Down
8 changes: 5 additions & 3 deletions src/budy/models/bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,10 @@ class Bundle(base.BudyBase):
initial = False,
safe = True,
observations = """If the bundle should be fully discountable,
meaning that the shipping costs may also be affected by discount,
in effect making them considered as discountable"""
meaning that the sub total value to be used as the discountable
base is going to include lines with line level discount and that
the shipping costs may also be affected by discount, in effect
making them considered as discountable"""
)

ip_address = appier.field(
Expand Down Expand Up @@ -538,7 +540,7 @@ def calculate_s(self):

@property
def discountable(self):
return self.undiscounted_sub_total + self.shipping_cost if\
return self.sub_total + self.shipping_cost if\
self.discountable_full else self.undiscounted_sub_total

@property
Expand Down
56 changes: 56 additions & 0 deletions src/budy/test/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,62 @@ def test_discountable_full(self):
self.assertEqual(order.shipping_cost, 10.0)
self.assertEqual(order.discountable, 20.0)

product = budy.Product(
short_description = "product",
gender = "Male",
price = 10.0,
price_compare = 12.0
)
product.save()

order = budy.Order(
discountable_full = True,
shipping_fixed = 10.0
)
order.save()

order_line = budy.OrderLine(quantity = 2.0)
order_line.product = product
order_line.save()
order.add_line_s(order_line)

self.assertEqual(order.sub_total, 20.0)
self.assertEqual(order.discount, 0.0)
self.assertEqual(order.total, 30.0)
self.assertEqual(order.payable, 30.0)
self.assertEqual(order.shipping_cost, 10.0)
self.assertEqual(order.discountable, 30.0)

order.discount_fixed = 20.0
order.save()

self.assertEqual(order.sub_total, 20.0)
self.assertEqual(order.discount, 20.0)
self.assertEqual(order.total, 10.0)
self.assertEqual(order.payable, 10.0)
self.assertEqual(order.shipping_cost, 10.0)
self.assertEqual(order.discountable, 30.0)

order.discount_fixed = 30.0
order.save()

self.assertEqual(order.sub_total, 20.0)
self.assertEqual(order.discount, 30.0)
self.assertEqual(order.total, 0.0)
self.assertEqual(order.payable, 0.0)
self.assertEqual(order.shipping_cost, 10.0)
self.assertEqual(order.discountable, 30.0)

order.discountable_full = False
order.save()

self.assertEqual(order.sub_total, 20.0)
self.assertEqual(order.discount, 0.0)
self.assertEqual(order.total, 30.0)
self.assertEqual(order.payable, 30.0)
self.assertEqual(order.shipping_cost, 10.0)
self.assertEqual(order.discountable, 0.0)

def test_taxes(self):
product = budy.Product(
short_description = "product",
Expand Down

0 comments on commit 2017dcf

Please sign in to comment.