From 1687e804929ee22e218ce98b33e9a72e82f99f3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B8=D0=BA=D1=82=D0=BE=D1=80=20=D0=93=D0=BB=D0=B0?= =?UTF-8?q?=D0=B4=D0=BA=D0=B8=D1=85?= Date: Thu, 21 Nov 2019 13:13:19 +0300 Subject: [PATCH 1/6] Check serial number for product --- .../management/commands/add_product_tag.py | 11 +++++++++++ .../migrations/0019_product_serial_number.py | 18 ++++++++++++++++++ apps/product/models.py | 4 ++++ 3 files changed, 33 insertions(+) create mode 100644 apps/product/migrations/0019_product_serial_number.py diff --git a/apps/product/management/commands/add_product_tag.py b/apps/product/management/commands/add_product_tag.py index 6377fcac..9ee09bdd 100644 --- a/apps/product/management/commands/add_product_tag.py +++ b/apps/product/management/commands/add_product_tag.py @@ -149,6 +149,17 @@ class Command(BaseCommand): tag.label = new_label tag.save() + + def check_serail_number(self): + category = TagCategory.objects.get(index_name='serial_number') + tags = Tag.objects.filter(category=category, products__isnull=False) + for tag in tqdm(tags, desc='Update serial number for product'): + tag.products.all().update(serial_number=tag.value) + + self.stdout.write(self.style.WARNING(f'Check serial number product end.')) + + + def handle(self, *args, **kwargs): self.remove_tags_product() self.remove_tags() diff --git a/apps/product/migrations/0019_product_serial_number.py b/apps/product/migrations/0019_product_serial_number.py new file mode 100644 index 00000000..eb8bef34 --- /dev/null +++ b/apps/product/migrations/0019_product_serial_number.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.7 on 2019-11-21 09:24 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('product', '0018_purchasedproduct'), + ] + + operations = [ + migrations.AddField( + model_name='product', + name='serial_number', + field=models.CharField(default=None, max_length=255, null=True, verbose_name='Serial number'), + ), + ] diff --git a/apps/product/models.py b/apps/product/models.py index f499afee..3d27559f 100644 --- a/apps/product/models.py +++ b/apps/product/models.py @@ -219,6 +219,10 @@ class Product(GalleryModelMixin, TranslatedFieldsMixin, BaseAttributes, HasTagsM comments = generic.GenericRelation(to='comment.Comment') awards = generic.GenericRelation(to='main.Award', related_query_name='product') + serial_number = models.CharField(max_length=255, + default=None, null=True, + verbose_name=_('Serial number')) + objects = ProductManager.from_queryset(ProductQuerySet)() class Meta: From 938b9436eb4e7a142a3cd78e3a11da2a0a873f9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B8=D0=BA=D1=82=D0=BE=D1=80=20=D0=93=D0=BB=D0=B0?= =?UTF-8?q?=D0=B4=D0=BA=D0=B8=D1=85?= Date: Thu, 21 Nov 2019 13:25:31 +0300 Subject: [PATCH 2/6] Fix name def --- apps/product/management/commands/add_product_tag.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/apps/product/management/commands/add_product_tag.py b/apps/product/management/commands/add_product_tag.py index 9ee09bdd..1ff823b0 100644 --- a/apps/product/management/commands/add_product_tag.py +++ b/apps/product/management/commands/add_product_tag.py @@ -149,8 +149,7 @@ class Command(BaseCommand): tag.label = new_label tag.save() - - def check_serail_number(self): + def check_serial_number(self): category = TagCategory.objects.get(index_name='serial_number') tags = Tag.objects.filter(category=category, products__isnull=False) for tag in tqdm(tags, desc='Update serial number for product'): @@ -158,8 +157,6 @@ class Command(BaseCommand): self.stdout.write(self.style.WARNING(f'Check serial number product end.')) - - def handle(self, *args, **kwargs): self.remove_tags_product() self.remove_tags() @@ -168,3 +165,4 @@ class Command(BaseCommand): self.add_tag() self.check_tag() self.add_product_tag() + self.check_serial_number() From 9a2f7fec39b8e9d170e417dde53e49c3312e8098 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B8=D0=BA=D1=82=D0=BE=D1=80=20=D0=93=D0=BB=D0=B0?= =?UTF-8?q?=D0=B4=D0=BA=D0=B8=D1=85?= Date: Thu, 21 Nov 2019 14:33:27 +0300 Subject: [PATCH 3/6] fix --- apps/product/management/commands/add_product_tag.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/apps/product/management/commands/add_product_tag.py b/apps/product/management/commands/add_product_tag.py index 1ff823b0..e430166d 100644 --- a/apps/product/management/commands/add_product_tag.py +++ b/apps/product/management/commands/add_product_tag.py @@ -101,14 +101,12 @@ class Command(BaseCommand): p.tags.clear() print('End clear tags product') - def remove_tags(self): print('Begin delete many tags') Tag.objects.\ filter(news__isnull=True, establishments__isnull=True).delete() print('End delete many tags') - def product_sql(self): with connections['legacy'].cursor() as cursor: cursor.execute(''' From a2087213a4265b82eddb36e1d80cd8643bb794f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B8=D0=BA=D1=82=D0=BE=D1=80=20=D0=93=D0=BB=D0=B0?= =?UTF-8?q?=D0=B4=D0=BA=D0=B8=D1=85?= Date: Thu, 21 Nov 2019 15:22:22 +0300 Subject: [PATCH 4/6] Check serial number command --- .../management/commands/add_product_tag.py | 11 +--------- .../commands/check_serial_number.py | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 10 deletions(-) create mode 100644 apps/product/management/commands/check_serial_number.py diff --git a/apps/product/management/commands/add_product_tag.py b/apps/product/management/commands/add_product_tag.py index e430166d..01f5d7f7 100644 --- a/apps/product/management/commands/add_product_tag.py +++ b/apps/product/management/commands/add_product_tag.py @@ -7,7 +7,7 @@ from tqdm import tqdm class Command(BaseCommand): - help = '''Add add product tags networks from old db to new db. + help = '''Add product tags networks from old db to new db. Run after add_product!!!''' def category_sql(self): @@ -147,14 +147,6 @@ class Command(BaseCommand): tag.label = new_label tag.save() - def check_serial_number(self): - category = TagCategory.objects.get(index_name='serial_number') - tags = Tag.objects.filter(category=category, products__isnull=False) - for tag in tqdm(tags, desc='Update serial number for product'): - tag.products.all().update(serial_number=tag.value) - - self.stdout.write(self.style.WARNING(f'Check serial number product end.')) - def handle(self, *args, **kwargs): self.remove_tags_product() self.remove_tags() @@ -163,4 +155,3 @@ class Command(BaseCommand): self.add_tag() self.check_tag() self.add_product_tag() - self.check_serial_number() diff --git a/apps/product/management/commands/check_serial_number.py b/apps/product/management/commands/check_serial_number.py new file mode 100644 index 00000000..ae2e43a3 --- /dev/null +++ b/apps/product/management/commands/check_serial_number.py @@ -0,0 +1,22 @@ +from django.core.management.base import BaseCommand +from django.db import connections +from establishment.management.commands.add_position import namedtuplefetchall +from tag.models import Tag, TagCategory +from product.models import Product, ProductType +from tqdm import tqdm + + +class Command(BaseCommand): + help = '''Check product serial number from old db to new db. + Run after add_product_tag!!!''' + + def check_serial_number(self): + category = TagCategory.objects.get(index_name='serial_number') + tags = Tag.objects.filter(category=category, products__isnull=False) + for tag in tqdm(tags, desc='Update serial number for product'): + tag.products.all().update(serial_number=tag.value) + + self.stdout.write(self.style.WARNING(f'Check serial number product end.')) + + def handle(self, *args, **kwargs): + self.check_serial_number() From 5236bca874fe03d14c550ae9496c0037ce4cebcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B8=D0=BA=D1=82=D0=BE=D1=80=20=D0=93=D0=BB=D0=B0?= =?UTF-8?q?=D0=B4=D0=BA=D0=B8=D1=85?= Date: Thu, 21 Nov 2019 15:22:43 +0300 Subject: [PATCH 5/6] Check serial number command --- apps/product/management/commands/check_serial_number.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/apps/product/management/commands/check_serial_number.py b/apps/product/management/commands/check_serial_number.py index ae2e43a3..75d1a693 100644 --- a/apps/product/management/commands/check_serial_number.py +++ b/apps/product/management/commands/check_serial_number.py @@ -1,8 +1,5 @@ from django.core.management.base import BaseCommand -from django.db import connections -from establishment.management.commands.add_position import namedtuplefetchall from tag.models import Tag, TagCategory -from product.models import Product, ProductType from tqdm import tqdm From 26b8dcd082f997883cc56628a84e254c647b26b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B8=D0=BA=D1=82=D0=BE=D1=80=20=D0=93=D0=BB=D0=B0?= =?UTF-8?q?=D0=B4=D0=BA=D0=B8=D1=85?= Date: Thu, 21 Nov 2019 15:26:43 +0300 Subject: [PATCH 6/6] Check serial number command --- apps/product/management/commands/check_serial_number.py | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/product/management/commands/check_serial_number.py b/apps/product/management/commands/check_serial_number.py index 75d1a693..d9caf69a 100644 --- a/apps/product/management/commands/check_serial_number.py +++ b/apps/product/management/commands/check_serial_number.py @@ -12,6 +12,7 @@ class Command(BaseCommand): tags = Tag.objects.filter(category=category, products__isnull=False) for tag in tqdm(tags, desc='Update serial number for product'): tag.products.all().update(serial_number=tag.value) + tag.products.clear() self.stdout.write(self.style.WARNING(f'Check serial number product end.'))