Implement converting prices #79

Merged
lukas merged 22 commits from converted_prices into main 2024-11-11 16:36:58 +00:00
1 changed files with 10 additions and 0 deletions
Showing only changes of commit 4db8d1a63b - Show all commits

View File

@ -164,6 +164,16 @@ class Purchase(models.Model):
raise ValidationError(
f"{self.get_type_display()} must have a related purchase."
)
if self.pk is not None:
# Retrieve the existing instance from the database
existing_purchase = Purchase.objects.get(pk=self.pk)
# If price has changed, reset converted fields
if (
existing_purchase.price != self.price
or existing_purchase.price_currency != self.price_currency
):
self.converted_price = None
self.converted_currency = None
super().save(*args, **kwargs)