OrderChangeManager: Fix for change_tax_rule and recalculate_taxes in same transaction (Z#23187299) (#4964)

* Add test case

* Do not overwrite tax_rule in PriceOperation
This commit is contained in:
luelista
2025-03-31 12:27:45 +02:00
committed by GitHub
parent 804b048dbb
commit d8ec489b13
2 changed files with 13 additions and 1 deletions

View File

@@ -2309,7 +2309,7 @@ class OrderChangeManager:
op.position.tax_rate = op.price.rate
op.position.tax_value = op.price.tax
op.position.tax_code = op.price.code
op.position.save()
op.position.save(update_fields=['price', 'tax_rate', 'tax_value', 'tax_code'])
elif isinstance(op, self.TaxRuleOperation):
if isinstance(op.position, OrderPosition):
self.order.log_action('pretix.event.order.changed.tax_rule', user=self.user, auth=self.auth, data={

View File

@@ -3243,6 +3243,18 @@ class OrderChangeManagerTests(TestCase):
assert nop.tax_rate == Decimal('0.00')
assert nop.tax_value == Decimal('0.00')
@classscope(attr='o')
def test_change_taxrate_and_keep_net(self):
self.ocm.change_tax_rule(self.op1, self.tr19)
self.ocm.recalculate_taxes(keep='net')
self.ocm.commit()
self.order.refresh_from_db()
nop = self.order.positions.first()
assert nop.price == Decimal('25.59')
assert nop.tax_rule == self.tr19
assert nop.tax_rate == Decimal('19.00')
assert nop.tax_value == Decimal('4.09')
@classscope(attr='o')
def test_change_taxrate_to_country_specific(self):
self.tr19.eu_reverse_charge = True