Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Drop StockedProduct and use Stock model
Marcin Gębalaf33bd7e0ce79
diff --git a/saleor/product/migrations/0009_auto_20150617_0507.py b/saleor/product/migrations/0009_auto_20150617_0507.pynew file mode 100644index 0000000000..899cbe8d1e--- /dev/null+++ b/saleor/product/migrations/0009_auto_20150617_0507.py@@ -0,0 +1,32 @@+# -*- coding: utf-8 -*-+from __future__ import unicode_literals++from django.db import models, migrations+++class Migration(migrations.Migration):++ dependencies = [+ ('product', '0008_auto_20150617_0406'),+ ]++ operations = [+ migrations.RemoveField(+ model_name='genericproduct',+ name='stock',+ ),+ migrations.RemoveField(+ model_name='genericvariant',+ name='stock',+ ),+ migrations.AlterField(+ model_name='stock',+ name='product',+ field=models.ForeignKey(related_name='stock', verbose_name='product', to='product.Product'),+ ),+ migrations.AlterField(+ model_name='stock',+ name='variant',+ field=models.ForeignKey(related_name='stock', verbose_name='variant', blank=True, to='product.ProductVariant', null=True),+ ),+ ]diff --git a/saleor/product/models/__init__.py b/saleor/product/models/__init__.pyindex 1076f42d2e..6d2e30215b 100644--- a/saleor/product/models/__init__.py+++ b/saleor/product/models/__init__.py@@ -1,10 +1,9 @@from .base import Category, Product, Stockfrom .discounts import FixedProductDiscount, get_product_discountsfrom .products import (GenericProduct, GenericVariant, PhysicalProduct,- ProductVariant, StockedProduct)+ ProductVariant)from .images import ProductImage__all__ = ['Category', 'Product', 'FixedProductDiscount','get_product_discounts', 'GenericProduct', 'GenericVariant',- 'StockedProduct', 'PhysicalProduct', 'ProductVariant',- 'ProductImage', 'Stock']+ 'PhysicalProduct', 'ProductVariant', 'ProductImage', 'Stock']diff --git a/saleor/product/models/base.py b/saleor/product/models/base.pyindex 119e2f5834..0bc520199e 100644--- a/saleor/product/models/base.py+++ b/saleor/product/models/base.py@@ -118,7 +118,7 @@ class Product(models.Model, ItemRange):return self.is_item_available()def is_item_available(self):- raise NotImplementedError()+ return any([stock_item.is_available() for stock_item in self.stock.all()])def has_variants(self):return self.variants.exists()@@ -173,16 +173,16 @@ class ProductVariant(models.Model, Item):return Truedef is_item_available(self):- return False+ return any([stock_item.is_available() for stock_item in self.stock.all()])@python_2_unicode_compatibleclass Stock(models.Model):product = models.ForeignKey(- Product, verbose_name=pgettext_lazy('Stock item field', 'product'),- editable=False)+ Product, related_name='stock',+ verbose_name=pgettext_lazy('Stock item field', 'product'))variant = models.ForeignKey(- ProductVariant,+ ProductVariant, related_name='stock',verbose_name=pgettext_lazy('Stock item field', 'variant'),blank=True, null=True)quantity = models.IntegerField(@@ -200,4 +200,8 @@ class Stock(models.Model):unique_together = ('product', 'variant', 'location')def __str__(self):- return self.product.name+ sku = self.variant.sku if self.variant else self.product.sku+ return "%s - %s - %s" % (self.product.name, sku, self.location)++ def is_available(self):+ return self.quantity > 0diff --git a/saleor/product/models/products.py b/saleor/product/models/products.pyindex 87efeebe6a..75978b9413 100644--- a/saleor/product/models/products.py+++ b/saleor/product/models/products.py@@ -1,10 +1,6 @@from __future__ import unicode_literals-from decimal import Decimal-from django.core.validators import MinValueValidatorfrom django.db import models-from django.utils.translation import pgettext_lazy-from satchless.item import StockedItemfrom .base import Product, ProductVariant@@ -23,29 +19,13 @@ class PhysicalProduct(models.Model):return self.product.weight-class StockedProduct(models.Model, StockedItem):- stock = models.IntegerField(pgettext_lazy('Product item field', 'stock'),- validators=[MinValueValidator(0)],- default=Decimal(1))-- class Meta:- abstract = True- app_label = 'product'-- def get_stock(self):- return self.stock-- def is_item_available(self):- return self.get_stock() > 0---class GenericProduct(StockedProduct, PhysicalProduct, Product):+class GenericProduct(PhysicalProduct, Product):class Meta:app_label = 'product'-class GenericVariant(StockedProduct, ProductVariant):+class GenericVariant(ProductVariant):class Meta:app_label = 'product'