def apply( self, order: Order ): """ Apply the promotion euromania. :param Order order: order """ for chips in order.chips(): chips().set_price(price=1.0) order.promotions().append('euromania')
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 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(), )
def is_applicable(self, order: Order) -> bool: """ Check if the promotion jarramania is applicable. - 2 burribeers and 1 chips. - Everyday to 30-09-2020. Between 16-19.30 h. :param Order order: order :return boolean: is promotion applicable """ if len(order.drinks()) != 2 \ and [drink.type() != 'burribeer' for drink in order.drinks()] \ and len(order.chips()) != 1: return False day_before = datetime.utcnow() <= datetime.strptime( '2020-09-30', '%Y-%m-%d') hour_between = datetime.strptime('16:00:00', '%H:%M:%S').time() \ <= datetime.now().time() \ <= datetime.strptime('19:30:00', '%H:%M:%S').time() return day_before is True and hour_between is True