Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.84 KB | None | 0 0
  1. def calculate_cost(items, d):
  2.     #items = list of dictionery {SKUID, qty}, d = costing date
  3.     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)
  4.  
  5.     if len(p) < 1:
  6.         raise ValueError('Error: No cost to calculate. (Items not exist or date out of range?)')
  7.  
  8.     total_mat_cost = 0
  9.     total_log_cost = 0
  10.     for i in items:
  11.         unpackable_item = get_unpackable_item()
  12.         if int(i['SKUID']) in unpackable_item:
  13.             pass
  14.         else:
  15.             current_p = p.find(lambda row: row.SKUID == int(i['SKUID'])).first()
  16.  
  17.             total_mat_cost = total_mat_cost + (current_p.mat_cost * float(i['qty']))
  18.             total_log_cost = total_log_cost + (current_p.log_cost * float(i['qty']))
  19.  
  20.     return total_mat_cost, total_log_cost
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement