Skip to content

Commit

Permalink
Archive related Product when PriceList is deleted
Browse files Browse the repository at this point in the history
Products and PricedProducts are created when a PriceList is created
or edited. When a PriceList is deleted, the related PricedProduct is
deleted. However, the Product was not deleted/archived. This caused
issues with there being multiple Products for the same resource. Fix
this by archiving the existing Product when a PriceList is deleted.

Refs STAM-24
  • Loading branch information
jopesy committed Dec 9, 2024
1 parent 966f581 commit b82b732
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions respa_pricing/models/price.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from django.utils.duration import duration_string
from django.utils.functional import cached_property
from django.utils.translation import ugettext_lazy as _
from django.utils.timezone import now

from payments.utils import (
convert_aftertax_to_pretax,
Expand Down Expand Up @@ -202,6 +203,13 @@ class Meta:
def __str__(self):
return self.name

def delete(self, *args, **kwargs):
priced_product = getattr(self, "priced_product", None)
if priced_product:
priced_product.product.archived_at = now()
priced_product.product.save()
super().delete(*args, **kwargs)

@cached_property
def price_type(self):
price_types = (
Expand Down

0 comments on commit b82b732

Please sign in to comment.