Add employee fix

This commit is contained in:
Виктор Гладких 2019-11-05 16:33:38 +03:00
parent ea1ddfa320
commit 22982f3332

View File

@ -2,7 +2,7 @@ from django.core.management.base import BaseCommand
from django.db import connections from django.db import connections
from establishment.management.commands.add_position import namedtuplefetchall from establishment.management.commands.add_position import namedtuplefetchall
from establishment.models import Employee from establishment.models import Employee
from django.db.models import Q
class Command(BaseCommand): class Command(BaseCommand):
@ -30,8 +30,7 @@ class Command(BaseCommand):
def handle(self, *args, **options): def handle(self, *args, **options):
objects = [] objects = []
for e in self.employees_sql(): for e in self.employees_sql():
count = Employee.objects.filter(old_id=e.profile_id).count() count = Employee.objects.filter(Q(old_id=e.profile_id) | Q(name=e.name)).count()
count += Employee.objects.filter(name=e.name).count()
if count == 0: if count == 0:
objects.append(Employee(name=e.name, old_id=e.profile_id)) objects.append(Employee(name=e.name, old_id=e.profile_id))
print(e.name) print(e.name)