def calculate_total_price(cls, quote_id, num_sheets): """ Return the total price for all materials and finishings of a quote. """ # Retrieve Quote_Material row associated with given quote number q_materials_rows = Quote_Material.select().where( Quote_Material.quote_id == quote_id) # Retrieve all of quote's materials prices total_materials_price = 0 for q_material in q_materials_rows: logging.debug("Material: {}; Price: {}".format( q_material.material_id.material_name, q_material.material_id.material_price)) # add material's price total_materials_price += q_material.material_id.material_price # Retrieve Quote_Finishing row associated with given quote number q_finishings_rows = Quote_Finishing.select().where( Quote_Finishing.quote_id == quote_id) # Retrieve all of quote's finishings prices total_finishings_price = 0 for q_finishing in q_finishings_rows: logging.debug("Finishing: {}; Price: {}".format( q_finishing.finishing_id.finishing_name, q_finishing.finishing_id.finishing_price)) # add finishing's price total_finishings_price += q_finishing.finishing_id.finishing_price # Retrieve paper associated with quote id q_paper_row = Quote_Paper.select().where( Quote_Paper.quote_id == quote_id) # Retrieve paper's price for paper in q_paper_row: paper_price = paper.paper_id.paper_price # log totals logging.debug(("Material price: {}; Finishing price: {}; " "Paper price: {}").format( total_materials_price, total_finishings_price, paper_price)) # multiply total price by number of sheets total_price = num_sheets * total_materials_price total_price += num_sheets * total_finishings_price total_price += num_sheets * paper_price # log total price logging.debug("Sheets: {}; Total price: {}".format( num_sheets, total_price)) return total_price
def impose(cls, quote_number): """Return the number of jobs that can fit in the chosen paper.""" logging.debug("################## Imposing new job ##################") # Retrieve Quote_Paper row associated with given quote number rows = Quote_Paper.select().where(Quote_Paper.quote_id == quote_number) # assert quote exists and is unique assert len(rows) == 1 # access only row for row in rows: # Retrieve paper size paper_width = row.paper_id.paper_width paper_length = row.paper_id.paper_length # Retrieve job size job_width = row.quote_id.quote_dimention_width job_length = row.quote_id.quote_dimention_length # Retrive job bleed job_bleed = row.quote_id.quote_printing_bleed # Retrieve quote's number of copies num_copies = row.quote_id.quote_copies # store results results = [] # call impose results = calc_impose( paper_width, paper_length, job_width, job_length, job_bleed) # info logging logging.debug(("Paper: {}\" x {}\"; Job: {}\" x {}\"; " "Bleed: {}\"; Copies: {}").format( paper_width, paper_length, job_width, job_length, job_bleed, num_copies)) # sort results in descending order results.sort(reverse=True) # get best result best_result = results[0] best_sheets = math.ceil(num_copies / best_result) # display results for imposing in results: sheets = math.ceil(num_copies / imposing) logging.debug("++++ Fit: {}; Sheets: {}".format(imposing, sheets)) # return best result return best_result, best_sheets