def verify_calc(self, item, item_quantity): """Подсобная функция для работы функции verify(). Проверяет наличие на складе ингредиентов, входящих в сложный товар на момент продажи. В случае недостатка предлагает совершить мгновенный приход товара. Возвращает True или False в зависимости от итогового наличия необходиомого количества товара на складе для продажи.""" result = True for calc in queries.item_calculation(item): if calc.ingredient.calculation: for calc2 in queries.item_calculation(calc.ingredient): quantity = int(queries.items_in_storage( calc2.ingredient)) need_quantity = (item_quantity * calc2.quantity * calc.quantity) if quantity < need_quantity: if tkMessageBox.askyesno(u'Внимание!', u'Вы пытаетесь продать %d единицы товара "%s".' % (need_quantity, calc2.ingredient.name) + u'\nНа складе имеется всего %d единицы!'% quantity + u'\nВыполнить мгновенную поставку товара?'): incoming = panel() if not queries.execute_incoming_express( calc2.ingredient, incoming) or (need_quantity > incoming + quantity): result = False else: result = False else: quantity = int(queries.items_in_storage(calc.ingredient)) need_quantity = item_quantity * calc.quantity if quantity < need_quantity: if tkMessageBox.askyesno(u'Внимание!', u'Вы пытаетесь продать %d единицы товара "%s".' % (need_quantity, calc.ingredient.name) + u'\nНа складе имеется всего %d единицы!'% quantity + u'\nВыполнить мгновенную поставку товара?'): incoming = panel() if not queries.execute_incoming_express( calc.ingredient, incoming) or (need_quantity > incoming + quantity): result = False else: result = False return result
def verify(self): """Проверяет наличие на складе товаров, входящих в счет, на момент продажи, в случае недостатка предлагает совершить мгновенный приход товара. Возвращает True или False в зависимости от итогового наличия необходиомого количества товара на складе для продажи.""" all_present = True for item, item_quantity in zip(self.bill, self.quantity): if item.calculation: if not self.verify_calc(item, item_quantity): all_present = False else: quantity = int(queries.items_in_storage(item)) if quantity < item_quantity: if tkMessageBox.askyesno(u'Внимание!', u'Вы пытаетесь продать %d единицы товара "%s".' % (item_quantity, item.name) + u'\nНа складе имеется всего %d единицы!' % quantity + u'\nВыполнить мгновенную поставку товара?'): incoming = panel() if not queries.execute_incoming_express(item, incoming) or (item_quantity > incoming + quantity): all_present = False else: all_present = False return all_present