Skip to content

Commit

Permalink
HG-195 - fixed import_madrid_data command. CIF duplicate now don't sk…
Browse files Browse the repository at this point in the history
…ip the saving
  • Loading branch information
jbc25 committed Jun 4, 2024
1 parent 7bcc066 commit 2855f2f
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions market/management/commands/import_madrid_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def import_consumers(consumers, node):
current = 0
invalid = 0
duplicated = 0
cif_duplicated = 0
save_errors = 0

for item in consumers:
Expand All @@ -65,14 +66,7 @@ def import_consumers(consumers, node):
if item['inactive'] or item['is_guest_account']:
continue

uuids_to_ignore = [
'1bb8e193-2f4c-43b4-88dc-4a201a0bef08',
'ead1aa61-8334-4a47-88e9-1197c1f08326',
'2d9d5dd4-e0ff-496b-a41e-721a1ac26a9d',
'cfba9d2f-6a65-4ad5-a62d-82704604c2c2',
'e42ddb47-ff07-453b-acc6-762cf0083281',
'd827fb30-cbd5-4c97-9ec1-66d9fa3d092a',
]
uuids_to_ignore = []

if item['id'] in uuids_to_ignore:
continue
Expand All @@ -81,16 +75,21 @@ def import_consumers(consumers, node):
email = item['email']

if not cif or len(cif) > 30:
print(f"Invalid consumer nif: {item['name']} - {email} - {cif}")
print(f"Invalid consumer nif: {item['name']} - {email} - {cif}. SKIPPING...")
invalid += 1
continue

existing_consumer = Consumer.objects.filter(Q(cif=cif) | Q(email=email) | Q(owner__email=email)).first()
existing_consumer = Consumer.objects.filter(Q(email=email) | Q(owner__email=email)).first()
if existing_consumer:
duplicated += 1
print(f"Consumer already exists: {email} - {cif}")
print(f"Consumer email already exists: {email}. SKIPPING...")
continue

existing_consumer_cif = Consumer.objects.filter(cif=cif).first()
if existing_consumer_cif:
cif_duplicated += 1
print(f"Consumer CIF already exists: {cif}. SAVING ANYWAY...")

try:
user_created = User.objects.create(
email=item['email'],
Expand Down Expand Up @@ -121,7 +120,7 @@ def import_consumers(consumers, node):
save_errors += 1
print(f"Consumer save error: {email} - {cif} - {error}. Current: {current}")

print(f'Invalid: {invalid}, duplicated: {duplicated}, save_errors: {save_errors}')
print(f'Invalid: {invalid}, duplicated email: {duplicated}, duplicated CIF: {cif_duplicated}, save_errors: {save_errors}')


def set_social_profiles(provider_data, provider_instance):
Expand Down Expand Up @@ -206,6 +205,7 @@ def import_providers(providers, node):
current = 0
invalid = 0
duplicated = 0
cif_duplicated = 0
save_errors = 0

for item in providers:
Expand All @@ -220,16 +220,21 @@ def import_providers(providers, node):
email = item['email']

if not cif or len(cif) > 30:
print(f"Invalid provider nif: {item['name']} - {email} - {cif}")
print(f"Invalid provider nif: {item['name']} - {email} - {cif}. SKIPPING...")
invalid += 1
continue

existing_provider = Provider.objects.filter(Q(cif=cif) | Q(email=email) | Q(owner__email=email)).first()
existing_provider = Provider.objects.filter(Q(email=email) | Q(owner__email=email)).first()
if existing_provider:
duplicated += 1
print(f"Provider already exists: {item['email']} - {cif}")
print(f"Provider already exists: {item['email']}. SKIPPING...")
continue

existing_provider_cif = Provider.objects.filter(cif=cif).first()
if existing_provider_cif:
cif_duplicated += 1
print(f"Provider CIF already exists: {cif}. SAVING ANYWAY...")

try:
user_created = User.objects.create(
email=item['email'],
Expand Down Expand Up @@ -278,7 +283,7 @@ def import_providers(providers, node):
save_errors += 1
print(f"Provider save error: {email} - {cif} - {error}. Current: {current}")

print(f'Invalid: {invalid}, duplicated: {duplicated}, save_errors: {save_errors}')
print(f'Invalid: {invalid}, duplicated email: {duplicated}, duplicated CIF: {cif_duplicated}, save_errors: {save_errors}')


class Command(BaseCommand):
Expand Down

0 comments on commit 2855f2f

Please sign in to comment.