Skip to content

Commit

Permalink
Merge pull request #903 from gurch101/remove-product-category
Browse files Browse the repository at this point in the history
Remove product category field (SH-423)
  • Loading branch information
tulimaki committed Nov 5, 2016
2 parents 435825b + 82bbdfb commit 27f2065
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 68 deletions.
17 changes: 1 addition & 16 deletions shuup/admin/locale/en/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-10-25 05:02+0000\n"
"POT-Creation-Date: 2016-11-05 01:06+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: en <LL@li.org>\n"
Expand Down Expand Up @@ -110,12 +110,6 @@ msgstr ""
msgid "Set this category as a primary for selected products."
msgstr ""

msgid "Default Category"
msgstr ""

msgid "Update product default category while setting primary category."
msgstr ""

msgid "Additional Category"
msgstr ""

Expand Down Expand Up @@ -1013,12 +1007,6 @@ msgstr ""
msgid "Currency"
msgstr ""

msgid "Languages"
msgstr ""

msgid "Supported Languages"
msgstr ""

msgid "Shop name"
msgstr ""

Expand All @@ -1045,9 +1033,6 @@ msgstr ""
msgid "Domain"
msgstr ""

msgid "Please select the languages supported by your shop"
msgstr ""

msgid "Please enter your shop details"
msgstr ""

Expand Down
8 changes: 0 additions & 8 deletions shuup/admin/modules/categories/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ class CategoryProductForm(forms.Form):
help_text=_("Set this category as a primary for selected products."),
model=Product,
required=False)
update_product_category = forms.BooleanField(
label=_("Default Category"),
help_text=_("Update product default category while setting primary category."),
required=False)
additional_products = Select2MultipleField(
label=_("Additional Category"),
help_text=_("Add selected products to this category"),
Expand Down Expand Up @@ -92,8 +88,6 @@ def save(self):
shop_product.visibility_groups = visibility_groups
shop_product.save()
shop_product.categories.add(self.category)
if data.get("update_product_category", False):
Product.objects.filter(id=shop_product.product_id).update(category_id=self.category.id)

additional_product_ids = [int(product_id) for product_id in data.get("additional_products", [])]
for shop_product in ShopProduct.objects.filter(shop_id=self.shop.id, product_id__in=additional_product_ids):
Expand All @@ -106,6 +100,4 @@ def save(self):
shop_product.categories.remove(self.category)
shop_product.primary_category = None
shop_product.save()

Product.objects.filter(id=shop_product.product_id).update(category_id=None)
shop_product.categories.remove(self.category)
4 changes: 1 addition & 3 deletions shuup/admin/modules/products/views/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from shuup.admin.utils.picotable import ChoicesFilter, Column, TextFilter
from shuup.admin.utils.views import PicotableListView
from shuup.core.models import Category, Product, ProductMode
from shuup.core.models import Product, ProductMode


class ProductListView(PicotableListView):
Expand All @@ -26,7 +26,6 @@ class ProductListView(PicotableListView):
Column("barcode", _(u"Barcode"), display="barcode", filter_config=TextFilter(_("Filter by barcode..."))),
Column("type", _(u"Type")),
Column("mode", _(u"Mode"), filter_config=ChoicesFilter(ProductMode.choices)),
Column("category", _(u"Primary Category"), filter_config=ChoicesFilter(Category.objects.all(), "category")),
]

mass_actions = [
Expand Down Expand Up @@ -57,5 +56,4 @@ def get_object_abstract(self, instance, item):
{"title": _(u"Barcode"), "text": item.get("barcode")},
{"title": _(u"SKU"), "text": item.get("sku")},
{"title": _(u"Type"), "text": item.get("type")},
{"title": _(u"Primary Category"), "text": item.get("category")}
]
7 changes: 2 additions & 5 deletions shuup/core/locale/en/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-10-25 18:30+0000\n"
"POT-Creation-Date: 2016-11-05 01:06+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: en <LL@li.org>\n"
"Language: en\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: en\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"Generated-By: Babel 2.1.1\n"

Expand Down Expand Up @@ -894,9 +894,6 @@ msgstr ""
msgid "cost center"
msgstr ""

msgid "only used for administration and reporting"
msgstr ""

msgid "width (mm)"
msgstr ""

Expand Down
19 changes: 19 additions & 0 deletions shuup/core/migrations/0011_remove_product_category.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.11 on 2016-11-05 00:17
from __future__ import unicode_literals

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('shuup', '0010_update_managers'),
]

operations = [
migrations.RemoveField(
model_name='product',
name='category',
),
]
3 changes: 0 additions & 3 deletions shuup/core/models/_categories.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,6 @@ def soft_delete(self, user=None):
shop_product.categories.remove(self)
shop_product.primary_category = None
shop_product.save()
for product in self.primary_products.all():
product.category = None
product.save()
for child in self.children.all():
child.parent = None
child.save()
Expand Down
7 changes: 0 additions & 7 deletions shuup/core/models/_products.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,6 @@ class Product(TaxableItem, AttributableMixin, TranslatableModel):
accounting_identifier = models.CharField(max_length=32, blank=True, verbose_name=_('bookkeeping account'))
profit_center = models.CharField(max_length=32, verbose_name=_('profit center'), blank=True)
cost_center = models.CharField(max_length=32, verbose_name=_('cost center'), blank=True)
# Category is duplicated here because not all products necessarily belong in Shops (i.e. have
# ShopProduct instances), but they should nevertheless be searchable by category in other
# places, such as administration UIs.
category = models.ForeignKey(
"Category", related_name='primary_products', blank=True, null=True,
verbose_name=_('primary category'),
help_text=_("only used for administration and reporting"), on_delete=models.PROTECT)

# Physical dimensions
width = MeasurementField(unit="mm", verbose_name=_('width (mm)'))
Expand Down
12 changes: 0 additions & 12 deletions shuup_tests/admin/test_category_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ def test_products_form_add():
category.save()
product = create_product("test_product", shop=shop)
shop_product = product.get_shop_instance(shop)
product_category = product.category
assert (product_category is None)
assert (category not in shop_product.categories.all())
data = {
"primary_products": ["%s" % product.id]
Expand All @@ -83,7 +81,6 @@ def test_products_form_add():
assert (category in shop_product.categories.all())
assert (shop_product.visibility_limit.value == category.visibility.value)
assert (shop_product.visibility == ShopProductVisibility.NOT_VISIBLE)
assert (product.category is None)


@pytest.mark.django_db
Expand All @@ -93,8 +90,6 @@ def test_products_form_update_default_category():
category.shops.add(shop)
product = create_product("test_product", shop=shop)
shop_product = product.get_shop_instance(shop)
product_category = product.category
assert (product_category is None)
assert (category not in shop_product.categories.all())
data = {
"primary_products": ["%s" % product.id],
Expand All @@ -107,7 +102,6 @@ def test_products_form_update_default_category():
product.refresh_from_db()
assert (shop_product.primary_category == category)
assert (category in shop_product.categories.all())
assert (product.category == category)


@pytest.mark.django_db
Expand Down Expand Up @@ -138,15 +132,11 @@ def test_products_form_remove():
category = get_default_category()
category.shops.add(shop)
product = create_product("test_product", shop=shop)
product.category = category
product.save()
shop_product = product.get_shop_instance(shop)
shop_product.primary_category = category
shop_product.save()
shop_product.categories.add(category)

product.refresh_from_db()
assert (product.category == category)
shop_product.refresh_from_db()
assert (shop_product.primary_category == category)
assert (shop_product.categories.count() == 1)
Expand All @@ -161,8 +151,6 @@ def test_products_form_remove():

category.refresh_from_db()
assert (category.shop_products.count() == 0)
product.refresh_from_db()
assert (product.category is None)
shop_product.refresh_from_db()
assert (shop_product.primary_category is None)
assert (shop_product.categories.count() == 0)
Expand Down
2 changes: 1 addition & 1 deletion shuup_tests/campaigns/test_multiple_campaigns.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_multiple_campaigns_cheapest_price(rf):

category = get_default_category()
supplier = get_default_supplier()
product = create_product(printable_gibberish(), shop=shop, supplier=supplier, default_price=product_price, category=category)
product = create_product(printable_gibberish(), shop=shop, supplier=supplier, default_price=product_price)
shop_product = product.get_shop_instance(shop)
shop_product.categories.add(category)

Expand Down
2 changes: 0 additions & 2 deletions shuup_tests/core/test_categories.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ def test_category_deletion(admin_user):
shop_product = get_default_shop_product()
shop_product.categories.add(category)
shop_product.primary_category = category
shop_product.product.category = category
shop_product.save()

assert category.status == CategoryStatus.INVISIBLE
Expand All @@ -130,7 +129,6 @@ def test_category_deletion(admin_user):

assert shop_product.categories.count() == 0
assert shop_product.primary_category is None
assert shop_product.product.category is None
assert category.status == CategoryStatus.DELETED
assert category.children.count() == 0
# the child category still exists
Expand Down
11 changes: 0 additions & 11 deletions shuup_tests/core/test_foreignkeys.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,6 @@ def test_tax_class_removal():
assert Product.objects.filter(pk=product.pk).exists()


@pytest.mark.django_db
def test_category_removal():
product = get_product()
category = get_default_category()
product.category = category
product.save()
with pytest.raises(NotImplementedError):
category.delete()
assert Product.objects.filter(pk=product.pk).exists()


# -------------- CONTACT ----------------
@pytest.mark.django_db
def test_shipping_method_removal():
Expand Down

0 comments on commit 27f2065

Please sign in to comment.