Skip to content

Commit

Permalink
Merge stock types
Browse files Browse the repository at this point in the history
  • Loading branch information
hildogjr committed Jul 12, 2019
1 parent add6294 commit 2fe8cad
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 18 deletions.
28 changes: 18 additions & 10 deletions kicost/distributors/api_octopart.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,20 +340,28 @@ def get_part_info(query, parts, currency='USD'):
# Use the qty increment to select the part SKU, web page, and available quantity.
# Do this if this is the first part offer from this dist.
if not parts[i].part_num[dist]:
parts[i].part_num[dist] = offer.get('sku', '')
parts[i].url[dist] = offer.get('product_url', '')
parts[i].qty_avail[dist] = offer.get(
'in_stock_quantity', None)
parts[i].qty_increment[dist] = part_qty_increment
if not part.qty_avail[dist] or (offer.get('in_stock_quantity') and part.qty_avail[dist]<offer.get('in_stock_quantity')):
# Keeps the information of more availability.
parts[i].qty_avail[dist] = offer.get('in_stock_quantity')
if not part.moq[dist] or (offer.get('moq') and part.moq[dist]>offer.get('moq')):
# Save the link, stock code, ... of the page for minimum purchase.
part.moq[dist] = offer.get('moq') # Minimum order qty.
parts[i].part_num[dist] = offer.get('sku')
parts[i].url[dist] = offer.get('product_url')
parts[i].qty_increment[dist] = part_qty_increment
# Otherwise, check qty increment and see if its the smallest for this part & dist.
elif part_qty_increment < parts[i].qty_increment[dist]:
# This part looks more like a cut-tape version, so
# update the SKU, web page, and available quantity.
parts[i].part_num[dist] = offer.get('sku', '')
parts[i].url[dist] = offer.get('product_url', '')
parts[i].qty_avail[dist] = offer.get(
'in_stock_quantity', None)
parts[i].qty_increment[dist] = part_qty_increment
if not part.qty_avail[dist] or (offer.get('in_stock_quantity') and part.qty_avail[dist]<offer.get('in_stock_quantity')):
# Keeps the information of more availability.
parts[i].qty_avail[dist] = offer.get('in_stock_quantity')
if not part.moq[dist] or (offer.get('moq') and part.moq[dist]>offer.get('moq')):
# Save the link, stock code, ... of the page for minimum purchase.
part.moq[dist] = offer.get('moq') # Minimum order qty.
parts[i].part_num[dist] = offer.get('sku')
parts[i].url[dist] = offer.get('product_url')
parts[i].qty_increment[dist] = part_qty_increment

# Don't bother with any extra info from the distributor.
parts[i].info_dist[dist] = {}
Expand Down
18 changes: 12 additions & 6 deletions kicost/distributors/api_partinfo_kitspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,12 +300,18 @@ def get_part_info(query, parts):
part_qty_increment = float("inf")

# Use the qty increment to select the part SKU, web page, and available quantity.
# Do this if this is the first part offer from this dist.
part.part_num[dist] = offer.get('sku', '').get('part', '')
part.url[dist] = offer.get('product_url', '') # Page to purchase.
part.qty_avail[dist] = offer.get('in_stock_quantity', None) # In stock.
part.moq[dist] = offer.get('moq', None) # Minimum order qty.s
part.qty_increment[dist] = part_qty_increment
# Do this if this is the first part offer from this dist. Each distributor can have
# differente stock codes for the same part in different quantities / delivery package
# style: cut-tape, reel, ...
if not part.qty_avail[dist] or (offer.get('in_stock_quantity') and part.qty_avail[dist]<offer.get('in_stock_quantity')):
# Keeps the information of more availability.
part.qty_avail[dist] = offer.get('in_stock_quantity') # In stock.
if not part.moq[dist] or (offer.get('moq') and part.moq[dist]>offer.get('moq')):
# Save the link, stock code, ... of the page for minimum purchase.
part.moq[dist] = offer.get('moq') # Minimum order qty.
part.url[dist] = offer.get('product_url', '') # Page to purchase the minimum quantity.
part.part_num[dist] = offer.get('sku', '').get('part', '')
part.qty_increment[dist] = part_qty_increment

# Don't bother with any extra info from the distributor.
part.info_dist[dist] = {}
Expand Down
2 changes: 1 addition & 1 deletion kicost/distributors/dist_local_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def query_part_info(parts, distributors, currency=DEFAULT_CURRENCY):
part.qty_increment = {dist: None for dist in distributors}
part.info_dist = {dist: {} for dist in distributors}
part.currency = {dist: DEFAULT_CURRENCY for dist in distributors} # Default currency.
part.moq = {dist: 1 for dist in distributors} # Minimum order quantity allowd by the distributor.
part.moq = {dist: None for dist in distributors} # Minimum order quantity allowd by the distributor.

# Loop through the parts looking for those sourced by local distributors
# that won't be found online. Place any user-added info for these parts
Expand Down
2 changes: 1 addition & 1 deletion kicost/kicost.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def kicost(in_file, eda_name, out_filename,
part.qty_increment = {dist: None for dist in dist_list}
part.info_dist = {dist: {} for dist in dist_list}
part.currency = {dist: DEFAULT_CURRENCY for dist in dist_list} # Default currency.
part.moq = {dist: 1 for dist in dist_list} # Minimum order quantity allowd by the distributor.
part.moq = {dist: None for dist in dist_list} # Minimum order quantity allowd by the distributor.
#distributor.get_dist_parts_info(parts, distributor_dict, dist_list, currency)
#TODO The calls bellow should became the call above of just one function in the `distributors` pachage/folder.
#distributor_class.get_dist_parts_info(parts, distributor_dict, currency) #TODOlocal_template.query_part_info(parts, distributor_dict, currency)
Expand Down

0 comments on commit 2fe8cad

Please sign in to comment.