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 get_finishings(cls, quote_id, is_started, is_finished): """Return the finishing(s) associated with the given quote id.""" q_finishing_rows = Quote_Finishing.select().where( Quote_Finishing.quote_id == quote_id).order_by( Quote_Finishing.finishing_id) if is_started is not None and is_finished is not None: q_finishing_rows = q_finishing_rows.where( (Quote_Finishing.finishing_is_started == is_started) & (Quote_Finishing.finishing_is_finished == is_finished)).order_by( Quote_Finishing.finishing_id) return q_finishing_rows