def get_materials(cls, quote_id): """Return the material(s) associated with the given quote id.""" q_material_rows = Quote_Material.select().where( Quote_Material.quote_id == quote_id).order_by( Quote_Material.material_id) return q_material_rows
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