def get_order_discount_event(discount_obj: dict): currency = discount_obj["currency"] amount = prices.Money(Decimal(discount_obj["amount_value"]), currency) old_amount = None old_amount_value = discount_obj.get("old_amount_value") if old_amount_value: old_amount = prices.Money(Decimal(old_amount_value), currency) return OrderEventDiscountObject( value=discount_obj.get("value"), amount=amount, value_type=discount_obj.get("value_type"), reason=discount_obj.get("reason"), old_value_type=discount_obj.get("old_value_type"), old_value=discount_obj.get("old_value"), old_amount=old_amount, )
def resolve_balance(root: models.GiftCardEvent, _info): balance = root.parameters.get("balance") if balance is None: return None currency = balance["currency"] balance_data = {} for field in [ "initial_balance", "old_initial_balance", "current_balance", "old_current_balance", ]: amount = balance.get(field) if amount is not None: balance_data[field] = prices.Money(Decimal(amount), currency) return GiftCardEventBalance(**balance_data)