From 4ecc1dea555ee90553503e43ccd8af7a979739cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hildo=20Guillardi=20J=C3=BAnior?= Date: Mon, 2 Sep 2019 15:59:09 -0300 Subject: [PATCH] Fix #386 - check by accepetd stock codes --- kicost/distributors/api_octopart.py | 2 +- kicost/distributors/api_partinfo_kitspace.py | 20 +++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/kicost/distributors/api_octopart.py b/kicost/distributors/api_octopart.py index 12b5b2f01..fd71556f8 100644 --- a/kicost/distributors/api_octopart.py +++ b/kicost/distributors/api_octopart.py @@ -76,7 +76,7 @@ def init_dist_dict(): }) # Update the `distributor_dict`with the available distributor in this module with the module is enabled. # It can be not enabled by the GUI saved configurations. - if distributors_modules_dict['api_partinfo_kitspace']['enabled']: + if distributors_modules_dict['api_octopart']['enabled']: distributor_dict.update(dists) diff --git a/kicost/distributors/api_partinfo_kitspace.py b/kicost/distributors/api_partinfo_kitspace.py index 86e97336d..16f1df65e 100644 --- a/kicost/distributors/api_partinfo_kitspace.py +++ b/kicost/distributors/api_partinfo_kitspace.py @@ -290,19 +290,21 @@ def get_part_info(query, parts, distributor_info=None): 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. + # Check if that part have stock code that is accepted to use by this module (API). + # 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 checked after the 'manf#' buv code. for d in FIELDS_CAT: part_stock = part.fields.get(d) if part_stock: 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(part_catalogue_code_dist) - part_dist_use_manfpn.remove(part_catalogue_code_dist) + if part_catalogue_code_dist in distributors_modules_dict['api_partinfo_kitspace']['distributors']: + 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(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#')