Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
import json
from typing import Optional

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


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