Reset converted_price when currency or price changes
This commit is contained in:
parent
bf9f3d5f56
commit
4db8d1a63b
|
@ -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)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue