def get_selection(session_id): session = Session.objects(id=session_id)[0] selection = session.selection if selection is None: selection = RVDSelection() return utility.update_selection(session, selection) return selection.get_safe()
def save_selection(session: Session, items: list, subtotal: dict, part: CartItem = None) -> dict: selection = RVDSelection(items=items, subtotal=subtotal, part=part) selection = calc_subtotal(selection) selection = copy_selection_parameters(selection) session.selection = selection session.save() return selection.get_safe()
def del_item_from_selection(session_id: str, item_index: int): session: QuerySet = Session.objects(id=session_id) session: Session = session[0] selection = session.selection if selection is None: selection = RVDSelection() if item_index >= len(selection.items): return selection.get_safe() del selection.items[item_index] return utility.update_selection(session, selection)
def calc_subtotal(selection: RVDSelection) -> RVDSelection: price = 0 total_amount = selection.subtotal.get('amount', 1) selected_items = selection.items for obj in selection.items: p = RVDPrice.calc_cart_item_price(obj, selection.subtotal['job_type']) obj.price = p.price obj.total_price = p.full_price price += obj.total_price selection.subtotal['price'] = RVDPrice.round_price(price) selection.subtotal['total_price'] = RVDPrice.round_price(price * total_amount) selection.subtotal['name'] = create_selection_name(selected_items) selection.subtotal['amount'] = total_amount return selection
def add_item_to_selection(session_id: str, part: dict, job_type: str): session: QuerySet = Session.objects(id=session_id) session: Session = session[0] selection = session.selection if selection is None: selection = RVDSelection() selection.items.append(utility.get_cart_item(job_type, part)) return utility.update_selection(session, selection)
def create_selection() -> RVDSelection: return calc_subtotal(RVDSelection())
def update_selection(session: Session, selection: RVDSelection) -> dict: session.selection = calc_subtotal(selection) session.save() return selection.get_safe()