def is_applicable( self, order: Order ) -> bool: """ Check if the promotion 15% burrimenu is applicable. The same number of hamburgers, drinks and chips. :param Order order: order :return boolean: is promotion applicable """ return len(order.hamburgers()) == len(order.chips()) == len(order.drinks())
def apply( self, order: Order ): """ Apply the promotion burrimenu. 15% hamburgers. :param Order order: order :return order: order with promotion applied """ for hamburger in order.hamburgers(): hamburger.set_price(price=hamburger.price() * (100 - 15) / 100) order.promotions().append('burrimenu')
def calculate( self, order: Order ) -> float: """ Calculate the total price of all items. :param Order order: order :return float: price """ for drink in order.drinks(): drink.set_price(price=PriceDrink().calculate(drink=drink)) for chips in order.chips(): chips.set_price(price=PriceChips().calculate(chips=chips)) for hamburger in order.hamburgers(): hamburger.set_price(price=PriceHamburger().calculate(hamburger=hamburger)) if PromotionBurrimenu().is_applicable(order=order): PromotionBurrimenu().apply(order=order) if PromotionEuromania().is_applicable(order=order): PromotionEuromania().apply(order=order) total = 0.0 if PromotionJarramania().is_applicable(order=order): total = 3.0 PromotionJarramania().apply(order=order) else: for item in order.hamburgers() + order.drinks() + order.chips(): total += item.price() order.set_price(price=total) return total
def normalize(order: Order) -> Dict[str, Union[str, int]]: return dict( barista=order.barista() or None, hamburgers=[ HamburgerNormalizer.normalize(hamburger=hamburger) for hamburger in order.hamburgers() ], chips=[ ChipsNormalizer.normalize(chips=chips) for chips in order.chips() ], drinks=[ DrinkNormalizer.normalize(drink=drink) for drink in order.drinks() ], price=order.price(), dt_created=order.dt_created(), is_ready=order.is_ready(), promotions=order.promotions(), )