Check serial number command

This commit is contained in:
Виктор Гладких 2019-11-21 15:22:22 +03:00
parent 9acb9e4a22
commit a2087213a4
2 changed files with 23 additions and 10 deletions

View File

@ -7,7 +7,7 @@ from tqdm import tqdm
class Command(BaseCommand): 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!!!''' Run after add_product!!!'''
def category_sql(self): def category_sql(self):
@ -147,14 +147,6 @@ class Command(BaseCommand):
tag.label = new_label tag.label = new_label
tag.save() 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): def handle(self, *args, **kwargs):
self.remove_tags_product() self.remove_tags_product()
self.remove_tags() self.remove_tags()
@ -163,4 +155,3 @@ class Command(BaseCommand):
self.add_tag() self.add_tag()
self.check_tag() self.check_tag()
self.add_product_tag() self.add_product_tag()
self.check_serial_number()

View File

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