def _create_price_from_draft( self, draft: typing.Optional[types.TypedMoneyDraft] ) -> typing.Optional[types.TypedMoney]: if draft is None: return None if isinstance(draft, types.CentPrecisionMoneyDraft): return types.CentPrecisionMoney( cent_amount=draft.cent_amount, currency_code=draft.currency_code ) elif isinstance(draft, types.HighPrecisionMoneyDraft): return types.HighPrecisionMoney( cent_amount=draft.cent_amount, currency_code=draft.currency_code, precise_amount=draft.precise_amount, ) elif isinstance(draft, types.Money): return types.CentPrecisionMoney( cent_amount=draft.cent_amount, currency_code=draft.currency_code ) else: return types.TypedMoney( cent_amount=draft.cent_amount, currency_code=draft.currency_code, type=draft.type, )
def post_load(self, data, **kwargs): del data["type"] return types.HighPrecisionMoney(**data)