def dec_item(self, db: DBManager, product_id, quantity=1): """ decrease number of order item :param db: link to DBManager :param product_id: :param quantity: :return: """ if self.order.id > 0: # return quantity of product to store if self.order_items._dec(product_id=product_id, quantity=quantity): if db.increase_product(product_id=product_id, quantity=quantity): self.order_items._save(db)
def _del(self, db: DBManager, order_spec, product_id): """ delete order item position :param db: :param product_id: :return: """ if product_id in self._orders: order_item = self._orders[product_id] numbers = self.number_positions if db.increase_product(product_id=product_id, quantity=order_item.quantity): if numbers > 1: if 1 < order_item.number < numbers or order_item.number == numbers: self.current_prev(db) elif order_item.number == 1: self.current_next(db) order_item.delete(db) self._orders = OrderedDict() self._load(db=db, order_spec=order_spec)