Implement converting prices #79
|
@ -164,6 +164,16 @@ class Purchase(models.Model):
|
||||||
raise ValidationError(
|
raise ValidationError(
|
||||||
f"{self.get_type_display()} must have a related purchase."
|
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)
|
super().save(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue