|
|
|
|
@ -178,16 +178,33 @@ class Product(models.Model): |
|
|
|
|
def in_stock(self): |
|
|
|
|
return self.variations.filter(in_stock__gt=0).count() |
|
|
|
|
|
|
|
|
|
def min_price_variation(self): |
|
|
|
|
min_v = None |
|
|
|
|
for v in self.variations.all(): |
|
|
|
|
if not min_v: |
|
|
|
|
min_v = v |
|
|
|
|
else: |
|
|
|
|
if v.get_price() < min_v.get_price(): |
|
|
|
|
min_v = v |
|
|
|
|
return min_v |
|
|
|
|
|
|
|
|
|
def min_price(self): |
|
|
|
|
retval = self.variations.filter(in_stock__gt=0).aggregate( |
|
|
|
|
Min('price'))['price__min'] or 0 |
|
|
|
|
if not retval: |
|
|
|
|
retval = self.variations.aggregate(Min('price'))['price__min'] or 0 |
|
|
|
|
return self.min_price_variation().get_price() |
|
|
|
|
|
|
|
|
|
def is_discount(self): |
|
|
|
|
return self.variations.filter(discount__gt=0).count() > 0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if retval > 10000: |
|
|
|
|
return int(retval * Decimal('.95')) |
|
|
|
|
else: |
|
|
|
|
return int(retval * Decimal('.93')) |
|
|
|
|
|
|
|
|
|
# retval = self.variations.filter(in_stock__gt=0).aggregate( |
|
|
|
|
# Min('price'))['price__min'] or 0 |
|
|
|
|
# if not retval: |
|
|
|
|
# retval = self.variations.aggregate(Min('price'))['price__min'] or 0 |
|
|
|
|
# |
|
|
|
|
# if retval > 10000: |
|
|
|
|
# return int(retval * Decimal('.95')) |
|
|
|
|
# else: |
|
|
|
|
# return int(retval * Decimal('.93')) |
|
|
|
|
|
|
|
|
|
def get_absolute_url(self): |
|
|
|
|
retval = '/store/' |
|
|
|
|
@ -197,7 +214,6 @@ class Product(models.Model): |
|
|
|
|
retval += main_category.slug + '/product-' + self.slug |
|
|
|
|
return retval |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ProductVariation(models.Model): |
|
|
|
|
product = models.ForeignKey( |
|
|
|
|
Product, verbose_name='Товар', related_name='variations') |
|
|
|
|
@ -209,7 +225,7 @@ class ProductVariation(models.Model): |
|
|
|
|
article = models.CharField( |
|
|
|
|
'Артикул', max_length=32, null=True, blank=True, default='') |
|
|
|
|
weight = models.FloatField('Вес (кг)', default=0.1, null=False, blank=False) |
|
|
|
|
# weight = models.FloatField('Вес (кг)', default=0.1, null=False, blank=False) |
|
|
|
|
discount = models.IntegerField('Скидка %', default=0, blank=False, null=False) |
|
|
|
|
|
|
|
|
|
class Meta: |
|
|
|
|
verbose_name = 'разновидность товара' |
|
|
|
|
@ -219,11 +235,13 @@ class ProductVariation(models.Model): |
|
|
|
|
return self.variation |
|
|
|
|
|
|
|
|
|
def get_price(self): |
|
|
|
|
if self.price > 10000: |
|
|
|
|
return int(self.price * Decimal('.95')) |
|
|
|
|
if self.discount: |
|
|
|
|
return int(self.price - (self.price/100*self.discount)) |
|
|
|
|
else: |
|
|
|
|
return int(self.price * Decimal('.93')) |
|
|
|
|
|
|
|
|
|
if self.price > 10000: |
|
|
|
|
return int(self.price * Decimal('.95')) |
|
|
|
|
else: |
|
|
|
|
return int(self.price * Decimal('.93')) |
|
|
|
|
|
|
|
|
|
class AttributesInProduct(models.Model): |
|
|
|
|
attribute = models.ForeignKey( |
|
|
|
|
|