def _check_input(self, sound_effects_number: int, colour: Colours, has_batteries: bool, name: str, description: str, product_id: str) -> None: CheckInput.check_type(sound_effects_number, int) CheckInput.check_type(colour, Colours) CheckInput.check_type(has_batteries, bool) CheckInput.check_all_input_type([name, description, product_id], str) CheckInput.check_value_is_lower_equal_than_threshold( sound_effects_number, 0)
def check_if_item_enough(self, product_id: str, count: int) -> bool: """ Checks if the inventory has enough stock for exporting this item. :return: True if it has enough items, False if not """ CheckInput.check_type(product_id, str) CheckInput.check_type(count, int) CheckInput.check_value_is_lower_equal_than_threshold(count, 0) item = self.get_item_by_product_id(product_id) if item is None: return False return self._items[item] >= count
def export_items(self, item: Item, count: int = 1) -> None: """ Exports Items from the inventory. :param item: Item :param count: the number of item, default is 1 """ CheckInput.check_type(item, Item) CheckInput.check_type(count, int) CheckInput.check_value_is_lower_equal_than_threshold(count, 0) if item not in self._items.keys(): raise KeyError(item, "Inventory doesn't have this item") if self._items[item] < count: raise ValueError("The Inventory doesn't have enough stock for %s" % item) self._items[item] -= count
def import_items(self, item: Item, count: int = 100) -> None: """ Add Items stock. If the item already existed in the inventory, increase the count. Else put the item into inventory. :param item: Item :param count: the number of item, default is 1 """ CheckInput.check_type(item, Item) CheckInput.check_type(count, int) CheckInput.check_value_is_lower_equal_than_threshold(count, 0) if count < 100: count = 100 if item in self._items.keys(): self._items[item] += count return None self._items[item] = count
def _check_input(self, has_nut: bool, has_lactose: bool, pack_size: int, name: str, description: str, product_id: str) -> None: CheckInput.check_type(pack_size, int) CheckInput.check_value_is_lower_equal_than_threshold(pack_size, 0) CheckInput.check_all_input_type([has_nut, has_lactose], bool) CheckInput.check_all_input_type([name, description, product_id], str)