diff --git a/store/migrations/0062_productvariation_has_discount.py b/store/migrations/0062_productvariation_has_discount.py new file mode 100644 index 0000000..a3d863d --- /dev/null +++ b/store/migrations/0062_productvariation_has_discount.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='Со скидкой'), + ), + ] diff --git a/store/models.py b/store/models.py index 089afc3..f6c0be2 100644 --- a/store/models.py +++ b/store/models.py @@ -292,9 +292,22 @@ class ProductVariation(models.Model): 'В наличии (шт.)', default=1, null=False, blank=False) article = models.CharField( 'Артикул', max_length=32, null=True, blank=True, default='') - weight = models.FloatField('Вес (кг)', default=0.1, null=False, blank=False) - discount = models.IntegerField('Скидка %', default=0, blank=False, null=False) - delivery_date = models.CharField('Дата доставки', default=None, blank=True, null=True, max_length=20) + weight = models.FloatField( + verbose_name='Вес (кг)', default=0.1, null=False, blank=False) + 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: verbose_name = 'разновидность товара' @@ -307,8 +320,14 @@ class ProductVariation(models.Model): # import pdb; pdb.set_trace() # from django.core.mail import mail_admins # 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))) else: if self.discount: