* calculate full_price with promocode
This commit is contained in:
parent
01b1d6a4f5
commit
8145bb4ae3
|
|
@ -194,7 +194,7 @@ def generate_checklist_id():
|
|||
|
||||
class ChecklistQuerySet(models.QuerySet):
|
||||
def with_base_related(self):
|
||||
return self.select_related('manager', 'category', 'payment_method')\
|
||||
return self.select_related('manager', 'category', 'payment_method', 'promocode')\
|
||||
.prefetch_related(Prefetch('images', to_attr='_images'))
|
||||
|
||||
def default_ordering(self):
|
||||
|
|
@ -277,7 +277,6 @@ class Checklist(models.Model):
|
|||
# TODO: replace real_price by parser
|
||||
real_price = models.DecimalField('Реальная цена', max_digits=10, decimal_places=2, null=True, blank=True)
|
||||
|
||||
# TODO: choose from Promocode table
|
||||
# promo
|
||||
promocode = models.ForeignKey('Promocode', verbose_name='Промокод', on_delete=models.PROTECT, null=True, blank=True)
|
||||
comment = models.CharField('Комментарий', max_length=200, null=True, blank=True)
|
||||
|
|
@ -325,7 +324,25 @@ class Checklist(models.Model):
|
|||
|
||||
@property
|
||||
def full_price(self) -> Decimal:
|
||||
return self.price_rub + GlobalSettings.load().delivery_price_CN + self.delivery_price_CN_RU
|
||||
price = self.price_rub
|
||||
|
||||
free_delivery = False
|
||||
no_comission = False
|
||||
|
||||
if self.promocode_id:
|
||||
promocode = self.promocode
|
||||
price -= promocode.discount * self.price_rub
|
||||
|
||||
free_delivery = promocode.free_delivery
|
||||
no_comission = promocode.no_comission
|
||||
|
||||
if not free_delivery:
|
||||
price += GlobalSettings.load().delivery_price_CN + self.delivery_price_CN_RU
|
||||
|
||||
if not no_comission:
|
||||
price += self.commission_rub
|
||||
|
||||
return price
|
||||
|
||||
@property
|
||||
def delivery_price_CN_RU(self) -> Decimal:
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user