From c0dce31231b49915c801419430a7b0470bedd3da Mon Sep 17 00:00:00 2001 From: Vlad Stan Date: Thu, 2 Mar 2023 10:36:39 +0200 Subject: [PATCH] feat: validate currency for stall shipping zones --- models.py | 7 +++++++ views_api.py | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/models.py b/models.py index bd44c44..060b462 100644 --- a/models.py +++ b/models.py @@ -69,6 +69,13 @@ class PartialStall(BaseModel): shipping_zones: List[PartialZone] = [] 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): id: str diff --git a/views_api.py b/views_api.py index c03f7f4..393c15b 100644 --- a/views_api.py +++ b/views_api.py @@ -154,6 +154,8 @@ async def api_create_stall( wallet: WalletTypeInfo = Depends(require_admin_key), ) -> Stall: try: + data.validate_stall() + print("### stall", json.dumps(data.dict())) merchant = await get_merchant_for_user(wallet.wallet.user) assert merchant, "Cannot find merchat for stall" @@ -182,6 +184,8 @@ async def api_update_stall( wallet: WalletTypeInfo = Depends(require_admin_key), ) -> Stall: try: + data.validate_stall() + merchant = await get_merchant_for_user(wallet.wallet.user) assert merchant, "Cannot find merchat for stall"