24 lines
No EOL
736 B
Python
24 lines
No EOL
736 B
Python
from typing import Optional, Union
|
|
|
|
def normaliser_type_tiers(type_tiers: Union[str, int, None]) -> Optional[str]:
|
|
if type_tiers is None:
|
|
return None
|
|
|
|
# Conversion int → string
|
|
mapping_int = {
|
|
0: "client",
|
|
1: "fournisseur",
|
|
2: "prospect",
|
|
3: "all"
|
|
}
|
|
|
|
# Si c'est un int, on convertit
|
|
if isinstance(type_tiers, int):
|
|
return mapping_int.get(type_tiers, "all")
|
|
|
|
# Si c'est une string qui ressemble à un int
|
|
if isinstance(type_tiers, str) and type_tiers.isdigit():
|
|
return mapping_int.get(int(type_tiers), "all")
|
|
|
|
# Sinon on retourne tel quel (string normale)
|
|
return type_tiers.lower() if isinstance(type_tiers, str) else None |