Add tests

This commit is contained in:
Raphael Michel
2025-08-13 13:08:07 +02:00
parent 0cc2155aa5
commit cb2815a7f0
7 changed files with 449 additions and 66 deletions
+73
View File
@@ -2156,6 +2156,24 @@ class OrderChangeManagerTests(TestCase):
assert nop.price == Decimal('12.00')
assert nop.subevent == se1
@classscope(attr='o')
def test_add_item_with_rounding(self):
self.order.tax_rounding_mode = "sum_by_net"
self.order.save()
self.ocm.add_position(self.ticket, None, None, None)
self.ocm.commit()
self.order.refresh_from_db()
assert self.order.positions.count() == 3
op1, op2, op3 = self.order.positions.all()
assert op1.price == Decimal("23.01")
assert op1.price_includes_rounding_correction == Decimal("0.01")
assert op2.price == Decimal("23.01")
assert op2.price_includes_rounding_correction == Decimal("0.01")
assert op3.price == Decimal("23.00")
assert op3.price_includes_rounding_correction == Decimal("0.00")
assert self.order.total == Decimal("69.02")
assert self.order.transactions.count() == 7
@classscope(attr='o')
def test_reissue_invoice(self):
generate_invoice(self.order)
@@ -2563,6 +2581,61 @@ class OrderChangeManagerTests(TestCase):
assert p.amount == Decimal('23.00')
assert p.state == OrderPayment.PAYMENT_STATE_CONFIRMED
@classscope(attr='o')
def test_split_with_rounding_change(self):
# Order starts with 2*100€ tickets, but rounding corrects it to 199€. Then, it gets split, so its now 100 + 100
# and 1€ is pending. Nasty, but we didn't choose the EN16931 rounding method…
self.order.status = Order.STATUS_PAID
self.order.tax_rounding_mode = "sum_by_net"
self.order.save()
self.op1.price = Decimal("100.00")
self.op1._calculate_tax(tax_rule=self.tr19)
self.op1.save()
self.op2.price = Decimal("100.00")
self.op2._calculate_tax(tax_rule=self.tr19)
self.op2.save()
self.order.refresh_from_db()
self.ocm.regenerate_secret(self.op1)
self.ocm.commit() # Force re-rounding
self.order.refresh_from_db()
self.ocm = OrderChangeManager(self.order, None)
assert self.order.total == Decimal("199.99")
self.order.payments.create(
provider='manual',
state=OrderPayment.PAYMENT_STATE_CONFIRMED,
amount=self.order.total,
)
# Split
self.ocm.split(self.op2)
self.ocm.commit()
self.order.refresh_from_db()
self.op2.refresh_from_db()
# First order
assert self.order.total == Decimal('100.00')
assert not self.order.fees.exists()
assert self.order.pending_sum == Decimal('0.01')
assert self.order.status == Order.STATUS_PENDING
r = self.order.refunds.last()
assert r.provider == 'offsetting'
assert r.amount == Decimal('100.00')
assert r.state == OrderRefund.REFUND_STATE_DONE
# New order
assert self.op2.order != self.order
o2 = self.op2.order
assert o2.total == Decimal('100.00')
assert o2.status == Order.STATUS_PAID
assert o2.positions.count() == 1
assert o2.fees.count() == 0
assert o2.pending_sum == Decimal('0.00')
p = o2.payments.last()
assert p.provider == 'offsetting'
assert p.amount == Decimal('100.00')
assert p.state == OrderPayment.PAYMENT_STATE_CONFIRMED
@classscope(attr='o')
def test_split_and_change_higher(self):
self.order.status = Order.STATUS_PAID