Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def calculate_cost(items, d):
- #items = list of dictionery {SKUID, qty}, d = costing date
- p = current.db((current.db.Product_Costing.valid_from <= d) & (current.db.Product_Costing.valid_to >= d)).select(current.db.Product_Costing.SKUID, current.db.Product_Costing.mat_cost, current.db.Product_Costing.log_cost)
- if len(p) < 1:
- raise ValueError('Error: No cost to calculate. (Items not exist or date out of range?)')
- total_mat_cost = 0
- total_log_cost = 0
- for i in items:
- unpackable_item = get_unpackable_item()
- if int(i['SKUID']) in unpackable_item:
- pass
- else:
- current_p = p.find(lambda row: row.SKUID == int(i['SKUID'])).first()
- total_mat_cost = total_mat_cost + (current_p.mat_cost * float(i['qty']))
- total_log_cost = total_log_cost + (current_p.log_cost * float(i['qty']))
- return total_mat_cost, total_log_cost
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement