Skip to content

Commit

Permalink
Fix case of several catalogue code of unambigouzation #346
Browse files Browse the repository at this point in the history
  • Loading branch information
hildogjr committed Aug 11, 2019
1 parent d3d19a7 commit aafbd78
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions kicost/distributors/api_partinfo_kitspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ def emit(self, record):
logger.removeHandler(logDefaultHandler)

FIELDS_CAT = ([d + '#' for d in distributor_dict])
DISTRIBUTORS = ([d for d in distributor_dict])

# Translate from PartInfo distributor names to the names used internally by kicost.
dist_xlate = distributors_modules_dict['api_partinfo_kitspace']['dist_translation']
Expand Down Expand Up @@ -258,7 +259,7 @@ def get_part_info(query, parts, distributor_info=None):
# Get the distributor who made the offer and add their
# price/qty info to the parts list if its one of the accepted distributors.
dist = dist_xlate.get(offer['sku']['vendor'], '')
if dist_info and dist!=dist_info:
if dist_info and dist not in dist_info:
continue
if dist in distributors:

Expand Down Expand Up @@ -342,26 +343,29 @@ def get_part_info(query, parts, distributor_info=None):
# Create a PartInfo query using the manufacturer's part number or
# the distributor's SKU.
query = None
part_dist_use_manfpn = copy.copy(DISTRIBUTORS)

# Check if that part have stock code. KiCost will prioritize these codes under "manf#'
# that will be used for get information for the part hat were not filled with the
# distributor stock code. So this is chacked after the 'manf#' abov code.
for d in FIELDS_CAT:
part_stock = part.fields.get(d)
if part_stock:
part_code_dist = list({k for k, v in dist_xlate.items() if v == d[:-1]})[0]
part_catalogue_code_dist = d[:-1]
part_code_dist = list({k for k, v in dist_xlate.items() if v == part_catalogue_code_dist})[0]
query = {'sku': {'vendor': part_code_dist, 'part': part_stock}}
queries.append(query)
query_parts.append(part)
query_part_stock_code.append(d[:-1])
query_part_stock_code.append(part_catalogue_code_dist)
part_dist_use_manfpn.remove(part_catalogue_code_dist)

part_manf = part.fields.get('manf', '')
part_code = part.fields.get('manf#')
if part_code and not all([part.fields.get(f) for f in FIELDS_CAT]):
query = {'mpn': {'manufacturer': part_manf, 'part': part_code}}
queries.append(query)
query_parts.append(part)
query_part_stock_code.append(None)
query_part_stock_code.append(part_dist_use_manfpn)

# Setup progress bar to track progress of server queries.
progress = tqdm.tqdm(desc='Progress', total=len(query_parts), unit='part', miniters=1)
Expand Down

0 comments on commit aafbd78

Please sign in to comment.