Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Stock app PoC

Artur Smęt39083288f6df
diff --git a/saleor/stock/__init__.py b/saleor/stock/__init__.py
new file mode 100644
index 0000000000..8b13789179
--- /dev/null
+++ b/saleor/stock/__init__.py
@@ -0,0 +1 @@
+
diff --git a/saleor/stock/migrations/0001_initial.py b/saleor/stock/migrations/0001_initial.py
new file mode 100644
index 0000000000..d3f3aafab9
--- /dev/null
+++ b/saleor/stock/migrations/0001_initial.py
@@ -0,0 +1,71 @@
+# -*- coding: utf-8 -*-
+from south.utils import datetime_utils as datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+ # Adding model 'StockRecord'
+ db.create_table(u'stock_stockrecord', (
+ (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('sku', self.gf('django.db.models.fields.CharField')(unique=True, max_length=32)),
+ ('in_stock', self.gf('django.db.models.fields.IntegerField')()),
+ ('price', self.gf('django_prices.models.PriceField')(currency='AED', max_digits=12, decimal_places=4)),
+ ('allow_overselling', self.gf('django.db.models.fields.BooleanField')(default=False)),
+ ('product', self.gf('django.db.models.fields.related.ForeignKey')(related_name=u'stockrecords', to=orm['product.Product'])),
+ ))
+ db.send_create_signal(u'stock', ['StockRecord'])
+
+
+ def backwards(self, orm):
+ # Deleting model 'StockRecord'
+ db.delete_table(u'stock_stockrecord')
+
+
+ models = {
+ u'product.brand': {
+ 'Meta': {'object_name': 'Brand'},
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '50', 'null': 'True'})
+ },
+ u'product.category': {
+ 'Meta': {'object_name': 'Category'},
+ 'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ u'level': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+ u'lft': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+ 'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "u'children'", 'null': 'True', 'to': u"orm['product.Category']"}),
+ u'rght': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+ 'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '50'}),
+ u'tree_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'})
+ },
+ u'product.product': {
+ 'Meta': {'object_name': 'Product'},
+ 'brand': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['product.Brand']"}),
+ 'category': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "u'products'", 'to': u"orm['product.Category']"}),
+ 'description': ('django.db.models.fields.TextField', [], {}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'is_organic': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'name': ('django.db.models.fields.CharField', [], {'default': "u''", 'max_length': '128', 'blank': 'True'}),
+ 'package_size': ('django.db.models.fields.IntegerField', [], {}),
+ 'sku': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '32'}),
+ 'unit': ('django.db.models.fields.CharField', [], {'max_length': '3'}),
+ 'unit_value': ('django.db.models.fields.DecimalField', [], {'max_digits': '6', 'decimal_places': '2'})
+ },
+ u'stock.stockrecord': {
+ 'Meta': {'object_name': 'StockRecord'},
+ 'allow_overselling': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'in_stock': ('django.db.models.fields.IntegerField', [], {}),
+ 'price': ('django_prices.models.PriceField', [], {'currency': "'AED'", 'max_digits': '12', 'decimal_places': '4'}),
+ 'product': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "u'stockrecords'", 'to': u"orm['product.Product']"}),
+ 'sku': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '32'})
+ }
+ }
+
+ complete_apps = ['stock']
\ No newline at end of file
diff --git a/saleor/stock/migrations/0002_auto__add_partner__add_field_stockrecord_partner.py b/saleor/stock/migrations/0002_auto__add_partner__add_field_stockrecord_partner.py
new file mode 100644
index 0000000000..766105680c
--- /dev/null
+++ b/saleor/stock/migrations/0002_auto__add_partner__add_field_stockrecord_partner.py
@@ -0,0 +1,81 @@
+# -*- coding: utf-8 -*-
+from south.utils import datetime_utils as datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+ # Adding model 'Partner'
+ db.create_table(u'stock_partner', (
+ (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+ ('name', self.gf('django.db.models.fields.CharField')(max_length=50)),
+ ))
+ db.send_create_signal(u'stock', ['Partner'])
+
+ # Adding field 'StockRecord.partner'
+ db.add_column(u'stock_stockrecord', 'partner',
+ self.gf('django.db.models.fields.related.ForeignKey')(to=orm['stock.Partner'], null=True),
+ keep_default=False)
+
+
+ def backwards(self, orm):
+ # Deleting model 'Partner'
+ db.delete_table(u'stock_partner')
+
+ # Deleting field 'StockRecord.partner'
+ db.delete_column(u'stock_stockrecord', 'partner_id')
+
+
+ models = {
+ u'product.brand': {
+ 'Meta': {'object_name': 'Brand'},
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '50', 'null': 'True'})
+ },
+ u'product.category': {
+ 'Meta': {'object_name': 'Category'},
+ 'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ u'level': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+ u'lft': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+ 'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "u'children'", 'null': 'True', 'to': u"orm['product.Category']"}),
+ u'rght': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
+ 'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '50'}),
+ u'tree_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'})
+ },
+ u'product.product': {
+ 'Meta': {'object_name': 'Product'},
+ 'brand': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['product.Brand']"}),
+ 'category': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "u'products'", 'to': u"orm['product.Category']"}),
+ 'description': ('django.db.models.fields.TextField', [], {}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'is_organic': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'name': ('django.db.models.fields.CharField', [], {'default': "u''", 'max_length': '128', 'blank': 'True'}),
+ 'package_size': ('django.db.models.fields.IntegerField', [], {}),
+ 'sku': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '32'}),
+ 'unit': ('django.db.models.fields.CharField', [], {'max_length': '3'}),
+ 'unit_value': ('django.db.models.fields.DecimalField', [], {'max_digits': '6', 'decimal_places': '2'})
+ },
+ u'stock.partner': {
+ 'Meta': {'object_name': 'Partner'},
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+ },
+ u'stock.stockrecord': {
+ 'Meta': {'object_name': 'StockRecord'},
+ 'allow_overselling': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'in_stock': ('django.db.models.fields.IntegerField', [], {}),
+ 'partner': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['stock.Partner']", 'null': 'True'}),
+ 'price': ('django_prices.models.PriceField', [], {'currency': "'AED'", 'max_digits': '12', 'decimal_places': '4'}),
+ 'product': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "u'stockrecords'", 'to': u"orm['product.Product']"}),
+ 'sku': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '32'})
+ }
+ }
+
+ complete_apps = ['stock']
\ No newline at end of file
diff --git a/saleor/stock/migrations/__init__.py b/saleor/stock/migrations/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/saleor/stock/models.py b/saleor/stock/models.py
new file mode 100644
index 0000000000..9cc6438ea3
--- /dev/null
+++ b/saleor/stock/models.py
@@ -0,0 +1,33 @@
+from __future__ import unicode_literals
+
+from django.conf import settings
+from django.db import models
+from django.utils.translation import pgettext_lazy
+from django.utils.encoding import python_2_unicode_compatible
+from django_prices.models import PriceField
+
+from ..product.models import Product
+
+
+@python_2_unicode_compatible
+class Partner(models.Model):
+ name = models.CharField(max_length=50)
+
+ def __str__(self):
+ return self.name
+
+
+@python_2_unicode_compatible
+class StockRecord(models.Model):
+ partner = models.ForeignKey(Partner, null=True)
+ sku = models.CharField(
+ pgettext_lazy('Product field', 'sku'), max_length=32, unique=True)
+ in_stock = models.PositiveIntegerField()
+ price = PriceField(pgettext_lazy('Product field', 'price'),
+ max_digits=12, decimal_places=4,
+ currency=settings.DEFAULT_CURRENCY)
+ allow_overselling = models.BooleanField(default=False)
+ product = models.ForeignKey(Product, related_name='stockrecords')
+
+ def __str__(self):
+ return self.sku