Skip to content

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

Add warehouse model

Mira Szewczyk5d167f5f827c
diff --git a/saleor/settings.py b/saleor/settings.py
index b0032c8b5e..cb2be51e5f 100644
--- a/saleor/settings.py
+++ b/saleor/settings.py
@@ -217,6 +217,7 @@ INSTALLED_APPS = [
"saleor.data_feeds",
"saleor.page",
"saleor.payment",
+ "saleor.warehouse",
"saleor.webhook",
"saleor.wishlist",
# External apps
diff --git a/saleor/warehouse/__init__.py b/saleor/warehouse/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/saleor/warehouse/migrations/0001_initial.py b/saleor/warehouse/migrations/0001_initial.py
new file mode 100644
index 0000000000..6a1758bef7
--- /dev/null
+++ b/saleor/warehouse/migrations/0001_initial.py
@@ -0,0 +1,80 @@
+# Generated by Django 2.2.6 on 2019-11-07 11:58
+
+import uuid
+
+import django_countries.fields
+import phonenumber_field.modelfields
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ initial = True
+
+ dependencies = [("shipping", "0017_django_price_2")]
+
+ operations = [
+ migrations.CreateModel(
+ name="Warehouse",
+ fields=[
+ (
+ "uuid",
+ models.UUIDField(
+ default=uuid.UUID("57f55712-10e6-4687-a406-123915c84d86"),
+ primary_key=True,
+ serialize=False,
+ ),
+ ),
+ (
+ "name",
+ models.CharField(max_length=50, verbose_name="Warehouse name"),
+ ),
+ (
+ "company_name",
+ models.CharField(max_length=100, verbose_name="Legal company name"),
+ ),
+ (
+ "street_address",
+ models.CharField(max_length=256, verbose_name="Street name"),
+ ),
+ ("city", models.CharField(blank=True, max_length=256)),
+ (
+ "postal_code",
+ models.CharField(
+ blank=True, max_length=20, verbose_name="Zip code"
+ ),
+ ),
+ ("country", django_countries.fields.CountryField(max_length=2)),
+ (
+ "country_area",
+ models.CharField(
+ blank=True, max_length=128, verbose_name="State/province"
+ ),
+ ),
+ (
+ "email",
+ models.EmailField(
+ blank=True,
+ default="",
+ max_length=254,
+ verbose_name="Email address",
+ ),
+ ),
+ (
+ "phone",
+ phonenumber_field.modelfields.PhoneNumberField(
+ blank=True,
+ default="",
+ max_length=128,
+ region=None,
+ verbose_name="Phone number",
+ ),
+ ),
+ ("shipping_region", models.ManyToManyField(to="shipping.ShippingZone")),
+ ],
+ options={
+ "ordering": ("-name",),
+ "permissions": (("manage_warehouses", "Manage warehouses."),),
+ },
+ )
+ ]
diff --git a/saleor/warehouse/migrations/__init__.py b/saleor/warehouse/migrations/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/saleor/warehouse/models.py b/saleor/warehouse/models.py
new file mode 100644
index 0000000000..d6f017db12
--- /dev/null
+++ b/saleor/warehouse/models.py
@@ -0,0 +1,73 @@
+import uuid
+
+from django.db import models
+from django.forms.models import model_to_dict
+from django.utils.translation import pgettext_lazy
+from django_countries.fields import Country, CountryField
+from phonenumber_field.modelfields import PhoneNumber, PhoneNumberField
+
+from saleor.shipping.models import ShippingZone
+
+
+class Warehouse(models.Model):
+ uuid = models.UUIDField(default=uuid.uuid4(), primary_key=True)
+ name = models.CharField(
+ pgettext_lazy("Warehouse field description", "Warehouse name"), max_length=50
+ )
+ company_name = models.CharField(
+ pgettext_lazy("Warehouse field description", "Legal company name"),
+ max_length=100,
+ )
+
+ shipping_region = models.ManyToManyField(ShippingZone)
+
+ street_address = models.CharField(
+ pgettext_lazy("Warehouse field description", "Street name"), max_length=256
+ )
+ city = models.CharField(max_length=256, blank=True)
+ postal_code = models.CharField(
+ pgettext_lazy("Warehouse field description", "Zip code"),
+ max_length=20,
+ blank=True,
+ )
+ country = CountryField()
+ country_area = models.CharField(
+ pgettext_lazy("Warehouse field description", "State/province"),
+ max_length=128,
+ blank=True,
+ )
+
+ email = models.EmailField(
+ pgettext_lazy("Warehouse field description", "Email address"),
+ blank=True,
+ default="",
+ )
+ phone = PhoneNumberField(
+ pgettext_lazy("Warehouse field description", "Phone number"),
+ blank=True,
+ default="",
+ )
+
+ def __str__(self):
+ return self.name
+
+ def as_data(self):
+ """Return the address as a dict suitable for passing as kwargs.
+
+ Result does not contain the primary key or an associated user.
+ """
+ data = model_to_dict(self, exclude=["id", "site"])
+ if isinstance(data["country"], Country):
+ data["country"] = data["country"].code
+ if isinstance(data["phone"], PhoneNumber):
+ data["phone"] = data["phone"].as_e164
+ return data
+
+ class Meta:
+ ordering = ("-name",)
+ permissions = (
+ (
+ "manage_warehouses",
+ pgettext_lazy("Permission description", "Manage warehouses."),
+ ),
+ )