mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
fix migration coverage for company
This commit is contained in:
parent
a4c6d0e6c5
commit
fe767775bc
@ -14,11 +14,11 @@ So a simplified version of the migration is implemented.
|
|||||||
TESTING = 'test' in sys.argv
|
TESTING = 'test' in sys.argv
|
||||||
|
|
||||||
def clear():
|
def clear():
|
||||||
if not TESTING:
|
if not TESTING: # pragma: no cover
|
||||||
os.system('cls' if os.name == 'nt' else 'clear')
|
os.system('cls' if os.name == 'nt' else 'clear')
|
||||||
|
|
||||||
|
|
||||||
def reverse_association(apps, schema_editor):
|
def reverse_association(apps, schema_editor): # pragma: no cover
|
||||||
"""
|
"""
|
||||||
This is the 'reverse' operation of the manufacturer reversal.
|
This is the 'reverse' operation of the manufacturer reversal.
|
||||||
This operation is easier:
|
This operation is easier:
|
||||||
@ -108,7 +108,7 @@ def associate_manufacturers(apps, schema_editor):
|
|||||||
|
|
||||||
if len(row) > 0:
|
if len(row) > 0:
|
||||||
return row[0]
|
return row[0]
|
||||||
return ''
|
return '' # pragma: no cover
|
||||||
|
|
||||||
cursor = connection.cursor()
|
cursor = connection.cursor()
|
||||||
|
|
||||||
@ -139,7 +139,7 @@ def associate_manufacturers(apps, schema_editor):
|
|||||||
""" Attempt to link Part to an existing Company """
|
""" Attempt to link Part to an existing Company """
|
||||||
|
|
||||||
# Matches a company name directly
|
# Matches a company name directly
|
||||||
if name in companies.keys():
|
if name in companies.keys(): # pragma: no cover
|
||||||
print(" - Part[{pk}]: '{n}' maps to existing manufacturer".format(pk=part_id, n=name))
|
print(" - Part[{pk}]: '{n}' maps to existing manufacturer".format(pk=part_id, n=name))
|
||||||
|
|
||||||
manufacturer_id = companies[name]
|
manufacturer_id = companies[name]
|
||||||
@ -150,7 +150,7 @@ def associate_manufacturers(apps, schema_editor):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
# Have we already mapped this
|
# Have we already mapped this
|
||||||
if name in links.keys():
|
if name in links.keys(): # pragma: no cover
|
||||||
print(" - Part[{pk}]: Mapped '{n}' - manufacturer <{c}>".format(pk=part_id, n=name, c=links[name]))
|
print(" - Part[{pk}]: Mapped '{n}' - manufacturer <{c}>".format(pk=part_id, n=name, c=links[name]))
|
||||||
|
|
||||||
manufacturer_id = links[name]
|
manufacturer_id = links[name]
|
||||||
@ -196,10 +196,10 @@ def associate_manufacturers(apps, schema_editor):
|
|||||||
# Case-insensitive matching
|
# Case-insensitive matching
|
||||||
ratio = fuzz.partial_ratio(name.lower(), text.lower())
|
ratio = fuzz.partial_ratio(name.lower(), text.lower())
|
||||||
|
|
||||||
if ratio > threshold:
|
if ratio > threshold: # pragma: no cover
|
||||||
matches.append({'name': name, 'match': ratio})
|
matches.append({'name': name, 'match': ratio})
|
||||||
|
|
||||||
if len(matches) > 0:
|
if len(matches) > 0: # pragma: no cover
|
||||||
return [match['name'] for match in sorted(matches, key=lambda item: item['match'], reverse=True)]
|
return [match['name'] for match in sorted(matches, key=lambda item: item['match'], reverse=True)]
|
||||||
else:
|
else:
|
||||||
return []
|
return []
|
||||||
@ -212,12 +212,12 @@ def associate_manufacturers(apps, schema_editor):
|
|||||||
name = get_manufacturer_name(part_id)
|
name = get_manufacturer_name(part_id)
|
||||||
|
|
||||||
# Skip empty names
|
# Skip empty names
|
||||||
if not name or len(name) == 0:
|
if not name or len(name) == 0: # pragma: no cover
|
||||||
print(" - Part[{pk}]: No manufacturer_name provided, skipping".format(pk=part_id))
|
print(" - Part[{pk}]: No manufacturer_name provided, skipping".format(pk=part_id))
|
||||||
return
|
return
|
||||||
|
|
||||||
# Can be linked to an existing manufacturer
|
# Can be linked to an existing manufacturer
|
||||||
if link_part(part_id, name):
|
if link_part(part_id, name): # pragma: no cover
|
||||||
return
|
return
|
||||||
|
|
||||||
# Find a list of potential matches
|
# Find a list of potential matches
|
||||||
@ -226,12 +226,12 @@ def associate_manufacturers(apps, schema_editor):
|
|||||||
clear()
|
clear()
|
||||||
|
|
||||||
# Present a list of options
|
# Present a list of options
|
||||||
if not TESTING:
|
if not TESTING: # pragma: no cover
|
||||||
print("----------------------------------")
|
print("----------------------------------")
|
||||||
|
|
||||||
print("Checking part [{pk}] ({idx} of {total})".format(pk=part_id, idx=idx+1, total=total))
|
print("Checking part [{pk}] ({idx} of {total})".format(pk=part_id, idx=idx+1, total=total))
|
||||||
|
|
||||||
if not TESTING:
|
if not TESTING: # pragma: no cover
|
||||||
print("Manufacturer name: '{n}'".format(n=name))
|
print("Manufacturer name: '{n}'".format(n=name))
|
||||||
print("----------------------------------")
|
print("----------------------------------")
|
||||||
print("Select an option from the list below:")
|
print("Select an option from the list below:")
|
||||||
@ -249,7 +249,7 @@ def associate_manufacturers(apps, schema_editor):
|
|||||||
if TESTING:
|
if TESTING:
|
||||||
# When running unit tests, simply select the name of the part
|
# When running unit tests, simply select the name of the part
|
||||||
response = '0'
|
response = '0'
|
||||||
else:
|
else: # pragma: no cover
|
||||||
response = str(input("> ")).strip()
|
response = str(input("> ")).strip()
|
||||||
|
|
||||||
# Attempt to parse user response as an integer
|
# Attempt to parse user response as an integer
|
||||||
@ -263,7 +263,7 @@ def associate_manufacturers(apps, schema_editor):
|
|||||||
return
|
return
|
||||||
|
|
||||||
# Options 1) - n) select an existing manufacturer
|
# Options 1) - n) select an existing manufacturer
|
||||||
else:
|
else: # pragma: no cover
|
||||||
n = n - 1
|
n = n - 1
|
||||||
|
|
||||||
if n < len(matches):
|
if n < len(matches):
|
||||||
@ -287,7 +287,7 @@ def associate_manufacturers(apps, schema_editor):
|
|||||||
else:
|
else:
|
||||||
print("Please select a valid option")
|
print("Please select a valid option")
|
||||||
|
|
||||||
except ValueError:
|
except ValueError: # pragma: no cover
|
||||||
# User has typed in a custom name!
|
# User has typed in a custom name!
|
||||||
|
|
||||||
if not response or len(response) == 0:
|
if not response or len(response) == 0:
|
||||||
@ -312,7 +312,7 @@ def associate_manufacturers(apps, schema_editor):
|
|||||||
print("")
|
print("")
|
||||||
clear()
|
clear()
|
||||||
|
|
||||||
if not TESTING:
|
if not TESTING: # pragma: no cover
|
||||||
print("---------------------------------------")
|
print("---------------------------------------")
|
||||||
print("The SupplierPart model needs to be migrated,")
|
print("The SupplierPart model needs to be migrated,")
|
||||||
print("as the new 'manufacturer' field maps to a 'Company' reference.")
|
print("as the new 'manufacturer' field maps to a 'Company' reference.")
|
||||||
@ -339,7 +339,7 @@ def associate_manufacturers(apps, schema_editor):
|
|||||||
for index, row in enumerate(results):
|
for index, row in enumerate(results):
|
||||||
pk, MPN, SKU, manufacturer_id, manufacturer_name = row
|
pk, MPN, SKU, manufacturer_id, manufacturer_name = row
|
||||||
|
|
||||||
if manufacturer_id is not None:
|
if manufacturer_id is not None: # pragma: no cover
|
||||||
print(f" - SupplierPart <{pk}> already has a manufacturer associated (skipping)")
|
print(f" - SupplierPart <{pk}> already has a manufacturer associated (skipping)")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
def reverse_empty_email(apps, schema_editor):
|
def reverse_empty_email(apps, schema_editor): # pragma: no cover
|
||||||
Company = apps.get_model('company', 'Company')
|
Company = apps.get_model('company', 'Company')
|
||||||
for company in Company.objects.all():
|
for company in Company.objects.all():
|
||||||
if company.email == None:
|
if company.email == None:
|
||||||
|
@ -42,7 +42,7 @@ def migrate_currencies(apps, schema_editor):
|
|||||||
|
|
||||||
suffix = suffix.strip().upper()
|
suffix = suffix.strip().upper()
|
||||||
|
|
||||||
if suffix not in currency_codes:
|
if suffix not in currency_codes: # pragma: no cover
|
||||||
logger.warning(f"Missing suffix: '{suffix}'")
|
logger.warning(f"Missing suffix: '{suffix}'")
|
||||||
|
|
||||||
while suffix not in currency_codes:
|
while suffix not in currency_codes:
|
||||||
@ -78,7 +78,7 @@ def migrate_currencies(apps, schema_editor):
|
|||||||
if count > 0:
|
if count > 0:
|
||||||
logger.info(f"Updated {count} SupplierPriceBreak rows")
|
logger.info(f"Updated {count} SupplierPriceBreak rows")
|
||||||
|
|
||||||
def reverse_currencies(apps, schema_editor):
|
def reverse_currencies(apps, schema_editor): # pragma: no cover
|
||||||
"""
|
"""
|
||||||
Reverse the "update" process.
|
Reverse the "update" process.
|
||||||
|
|
||||||
|
@ -15,12 +15,12 @@ def supplierpart_make_manufacturer_parts(apps, schema_editor):
|
|||||||
for supplier_part in supplier_parts:
|
for supplier_part in supplier_parts:
|
||||||
print(f'{supplier_part.supplier.name[:15].ljust(15)} | {supplier_part.SKU[:15].ljust(15)}\t', end='')
|
print(f'{supplier_part.supplier.name[:15].ljust(15)} | {supplier_part.SKU[:15].ljust(15)}\t', end='')
|
||||||
|
|
||||||
if supplier_part.manufacturer_part:
|
if supplier_part.manufacturer_part: # pragma: no cover
|
||||||
print(f'[ERROR: MANUFACTURER PART ALREADY EXISTS]')
|
print(f'[ERROR: MANUFACTURER PART ALREADY EXISTS]')
|
||||||
continue
|
continue
|
||||||
|
|
||||||
part = supplier_part.part
|
part = supplier_part.part
|
||||||
if not part:
|
if not part: # pragma: no cover
|
||||||
print(f'[ERROR: SUPPLIER PART IS NOT CONNECTED TO PART]')
|
print(f'[ERROR: SUPPLIER PART IS NOT CONNECTED TO PART]')
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ def supplierpart_make_manufacturer_parts(apps, schema_editor):
|
|||||||
|
|
||||||
print(f'{"-"*10}\nDone\n')
|
print(f'{"-"*10}\nDone\n')
|
||||||
|
|
||||||
def supplierpart_populate_manufacturer_info(apps, schema_editor):
|
def supplierpart_populate_manufacturer_info(apps, schema_editor): # pragma: no cover
|
||||||
Part = apps.get_model('part', 'Part')
|
Part = apps.get_model('part', 'Part')
|
||||||
ManufacturerPart = apps.get_model('company', 'ManufacturerPart')
|
ManufacturerPart = apps.get_model('company', 'ManufacturerPart')
|
||||||
SupplierPart = apps.get_model('company', 'SupplierPart')
|
SupplierPart = apps.get_model('company', 'SupplierPart')
|
||||||
|
Loading…
Reference in New Issue
Block a user