Source code for tdw_catalog.metadata_template.currency

import json
from typing import Optional

from tdw_catalog.utils import MetadataFieldType, CurrencyFieldValue
import tdw_catalog.metadata_template.field as field


[docs]class Field(field.MetadataTemplateField[CurrencyFieldValue]): """ A field for currency values Attributes ---------- currency : Optional[str] An optional three character string representation for this currency type (e.g. USD) amount: Optional[float] An optional fractional amount of currency for this currency field """ def __init__(self, key: str, currency: Optional[str], amount: Optional[float], optional: Optional[bool]) -> None: default_value = CurrencyFieldValue(value=amount, currency=currency) super().__init__(key, default_value, optional) default_value: Optional[CurrencyFieldValue] def serialize(self) -> dict: res = super().serialize() res["default_value"] = json.dumps({ "value": self.default_value.value, "currency": self.default_value.currency }) res["field_type"] = MetadataFieldType.FT_CURRENCY return res