Exemplo n.º 1
0
def create_from_draft(draft):
    """Utility method to create normal objects out of draft objects.

    This is used for non-resource objects. For the resources themselves (which contain)
    an id, we have the specific implementations of the `BaseModel`.
    """
    if not draft:
        return None

    if isinstance(draft, types.CustomFieldsDraft):
        return types.CustomFields(
            type=types.TypeReference(type_id=draft.type.type_id,
                                     id=draft.type.id),
            fields=draft.fields,
        )
    if isinstance(draft, types.PriceTierDraft):
        return types.PriceTier(
            minimum_quantity=draft.minimum_quantity,
            value=_money_to_typed(
                types.Money(
                    cent_amount=draft.value.cent_amount,
                    currency_code=draft.value.currency_code,
                )),
        )

    raise ValueError(f"Unsupported type {draft.__class__}")
Exemplo n.º 2
0
 def post_load(self, data, **kwargs):
     return types.PriceTier(**data)
 def post_load(self, data):
     return types.PriceTier(**data)