from .money_amount import Money, money from .property_deposit_cap import RentPeriod # Keeps annual rent exact as a JavaScript number; the same limit here. _MAX_MINOR = 1_000_000_000_000 def holding_deposit_cap(rent: Money, rent_period: RentPeriod) -> Money: """One week's rent, the statutory maximum holding deposit: the annual rent divided by 52, rounded down once so the deposit can never exceed the cap.""" if rent.currency != "GBP": raise ValueError("rent must be in GBP, received %s" % (rent.currency,)) if rent.minor < 0: raise ValueError("rent must not be negative, received %r" % (rent.minor,)) if rent_period == "weekly": annual = rent.minor * 52 elif rent_period == "monthly": annual = rent.minor * 12 elif rent_period == "annual": annual = rent.minor else: raise ValueError('unknown rent period "%s"' % (rent_period,)) if annual > _MAX_MINOR: raise ValueError("annual rent must be at most %d minor units" % (_MAX_MINOR,)) return money(annual // 52, "GBP")