add ProductVariation.has_discount boolean field

master
Stepan Krapivin 8 years ago
parent 4ad070c9bc
commit c95c522754
  1. 20
      store/migrations/0062_productvariation_has_discount.py
  2. 29
      store/models.py

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.3 on 2017-11-07 16:56
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('store', '0061_auto_20170603_0220'),
]
operations = [
migrations.AddField(
model_name='productvariation',
name='has_discount',
field=models.BooleanField(default=True, help_text='Если не указано, то скидка при расчёте цены не учитывается', verbose_name='Со скидкой'),
),
]

@ -292,9 +292,22 @@ class ProductVariation(models.Model):
'В наличии (шт.)', default=1, null=False, blank=False) 'В наличии (шт.)', default=1, null=False, blank=False)
article = models.CharField( article = models.CharField(
'Артикул', max_length=32, null=True, blank=True, default='') 'Артикул', max_length=32, null=True, blank=True, default='')
weight = models.FloatField('Вес (кг)', default=0.1, null=False, blank=False) weight = models.FloatField(
discount = models.IntegerField('Скидка %', default=0, blank=False, null=False) verbose_name='Вес (кг)', default=0.1, null=False, blank=False)
delivery_date = models.CharField('Дата доставки', default=None, blank=True, null=True, max_length=20) discount = models.IntegerField(
verbose_name='Скидка %', default=0, blank=False, null=False)
delivery_date = models.CharField(
verbose_name='Дата доставки',
default=None,
blank=True,
null=True,
max_length=20
)
has_discount = models.BooleanField(
verbose_name='Со скидкой',
help_text="Если не указано, то скидка при расчёте цены не учитывается",
default=True
)
class Meta: class Meta:
verbose_name = 'разновидность товара' verbose_name = 'разновидность товара'
@ -307,8 +320,14 @@ class ProductVariation(models.Model):
# import pdb; pdb.set_trace() # import pdb; pdb.set_trace()
# from django.core.mail import mail_admins # from django.core.mail import mail_admins
# mail_admins('auth', '{} {}'.format(profile, self.product.brand.slug)) # mail_admins('auth', '{} {}'.format(profile, self.product.brand.slug))
if profile and profile.is_authenticated() and self.product.brand.slug in ['beuchat',
'scorpena'] and profile.sale: if not self.has_discount:
return int(self.price)
if profile\
and profile.is_authenticated()\
and self.product.brand.slug in ['beuchat', 'scorpena']\
and profile.sale:
return int(self.price - (self.price / Decimal(100) * Decimal(profile.sale))) return int(self.price - (self.price / Decimal(100) * Decimal(profile.sale)))
else: else:
if self.discount: if self.discount:

Loading…
Cancel
Save