feat: validate currency for stall shipping zones

This commit is contained in:
Vlad Stan 2023-03-02 10:36:39 +02:00
parent 16a6104b25
commit c0dce31231
2 changed files with 11 additions and 0 deletions

View file

@ -69,6 +69,13 @@ class PartialStall(BaseModel):
shipping_zones: List[PartialZone] = [] shipping_zones: List[PartialZone] = []
config: StallConfig = StallConfig() config: StallConfig = StallConfig()
def validate_stall(self):
for z in self.shipping_zones:
if z.currency != self.currency:
raise ValueError(
f"Sipping zone '{z.name}' has different currency than stall."
)
class Stall(PartialStall): class Stall(PartialStall):
id: str id: str

View file

@ -154,6 +154,8 @@ async def api_create_stall(
wallet: WalletTypeInfo = Depends(require_admin_key), wallet: WalletTypeInfo = Depends(require_admin_key),
) -> Stall: ) -> Stall:
try: try:
data.validate_stall()
print("### stall", json.dumps(data.dict())) print("### stall", json.dumps(data.dict()))
merchant = await get_merchant_for_user(wallet.wallet.user) merchant = await get_merchant_for_user(wallet.wallet.user)
assert merchant, "Cannot find merchat for stall" assert merchant, "Cannot find merchat for stall"
@ -182,6 +184,8 @@ async def api_update_stall(
wallet: WalletTypeInfo = Depends(require_admin_key), wallet: WalletTypeInfo = Depends(require_admin_key),
) -> Stall: ) -> Stall:
try: try:
data.validate_stall()
merchant = await get_merchant_for_user(wallet.wallet.user) merchant = await get_merchant_for_user(wallet.wallet.user)
assert merchant, "Cannot find merchat for stall" assert merchant, "Cannot find merchat for stall"