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()