sport_inventary/app/utils.py

39 lines
1.1 KiB
Python

from datetime import datetime
def get_season_coeff(season_type: str, return_date: datetime = None) -> float:
if return_date is None:
return_date = datetime.now()
month = return_date.month
if month in [12, 1, 2]:
current_season = 'winter'
elif month in [6, 7, 8]:
current_season = 'summer'
else:
return 1.0
if season_type == current_season:
return 1.2
else:
return 0.8
def get_wear_coeff(wear_level: str) -> float:
coeffs = {
'low': 1.1,
'medium': 1.3,
'high': 1.5
}
return coeffs.get(wear_level, 1.0)
def calculate_item_price(base_price, quantity, wear_level, season_type, return_date=None):
base_total = float(base_price) * quantity
wear_coeff = get_wear_coeff(wear_level)
season_coeff = get_season_coeff(season_type, return_date)
return round(base_total * wear_coeff * season_coeff, 2)
def get_current_season_name():
month = datetime.now().month
if month in [12, 1, 2]:
return "зима"
elif month in [6, 7, 8]:
return "лето"
else:
return "межсезонье"