File tree Expand file tree Collapse file tree 1 file changed +7
-10
lines changed
packages/models-library/src/models_library/api_schemas_resource_usage_tracker Expand file tree Collapse file tree 1 file changed +7
-10
lines changed Original file line number Diff line number Diff line change 11from datetime import datetime
22from decimal import Decimal
3+ from typing import Annotated
34
4- from pydantic import BaseModel , ConfigDict , field_validator
5+ from pydantic import BaseModel , BeforeValidator , PlainSerializer
56
67from ..products import ProductName
78from ..resource_tracker import CreditTransactionId
1112
1213class WalletTotalCredits (BaseModel ):
1314 wallet_id : WalletID
14- available_osparc_credits : Decimal
15-
16- model_config = ConfigDict (json_encoders = {Decimal : float })
17-
18- @field_validator ("available_osparc_credits" , mode = "before" )
19- @classmethod
20- def ensure_rounded (cls , v ):
21- return round (v , 2 )
22-
15+ available_osparc_credits : Annotated [
16+ Decimal ,
17+ BeforeValidator (lambda x : round (x , 2 )),
18+ PlainSerializer (float , return_type = float , when_used = 'json' )
19+ ]
2320
2421class CreditTransactionCreateBody (BaseModel ):
2522 product_name : ProductName
You can’t perform that action at this time.
0 commit comments