Fix error in price calculation in connection with free prices and bundles

This commit is contained in:
Raphael Michel
2020-07-21 17:23:08 +02:00
parent 8bebea61f1
commit 7bd9a01f5e
2 changed files with 27 additions and 3 deletions

View File

@@ -47,8 +47,6 @@ def get_price(item: Item, variation: ItemVariation = None,
eu_reverse_charge=False,
)
price = tax_rule.tax(price, invoice_address=invoice_address, subtract_from_gross=bundled_sum)
if force_custom_price and custom_price is not None and custom_price != "":
if custom_price_is_net:
price = tax_rule.tax(custom_price, base_price_is='net', invoice_address=invoice_address,
@@ -56,17 +54,22 @@ def get_price(item: Item, variation: ItemVariation = None,
else:
price = tax_rule.tax(custom_price, base_price_is='gross', invoice_address=invoice_address,
subtract_from_gross=bundled_sum)
if item.free_price and custom_price is not None and custom_price != "":
elif item.free_price and custom_price is not None and custom_price != "":
if not isinstance(custom_price, Decimal):
custom_price = Decimal(str(custom_price).replace(",", "."))
if custom_price > 100000000:
raise ValueError('price_too_high')
price = tax_rule.tax(price, invoice_address=invoice_address)
if custom_price_is_net:
price = tax_rule.tax(max(custom_price, price.net), base_price_is='net',
invoice_address=invoice_address, subtract_from_gross=bundled_sum)
else:
price = tax_rule.tax(max(custom_price, price.gross), base_price_is='gross',
invoice_address=invoice_address, subtract_from_gross=bundled_sum)
else:
price = tax_rule.tax(price, invoice_address=invoice_address, subtract_from_gross=bundled_sum)
price.gross = round_decimal(price.gross, item.event.currency)
price.net = round_decimal(price.net, item.event.currency)

View File

@@ -2722,6 +2722,27 @@ class CartBundleTest(CartTestMixin, TestCase):
assert a.item == self.trans
assert a.price == 1.5
@classscope(attr='orga')
def test_simple_bundle_main_enforce_free_price_minimum(self):
self.ticket.free_price = True
self.ticket.save()
self.cm.add_new_items([
{
'item': self.ticket.pk,
'variation': None,
'price': '21.50',
'count': 1
}
])
self.cm.commit()
cp = CartPosition.objects.get(addon_to__isnull=True)
assert cp.item == self.ticket
assert cp.price == 23 - 1.5
assert cp.addons.count() == 1
a = cp.addons.get()
assert a.item == self.trans
assert a.price == 1.5
@classscope(attr='orga')
def test_voucher_on_base_product(self):
v = self.event.vouchers.create(code="foo", item=self.ticket)