Skip to content

Instantly share code, notes, and snippets.

@uds5501
Created April 25, 2019 02:57
Show Gist options
  • Save uds5501/2fc3d66f8557669f970346589aca1afc to your computer and use it in GitHub Desktop.
Save uds5501/2fc3d66f8557669f970346589aca1afc to your computer and use it in GitHub Desktop.
tax schema
from marshmallow_jsonapi import fields
from marshmallow_jsonapi.flask import Relationship
from app.api.helpers.utilities import dasherize
from app.api.schema.base import SoftDeletionSchema
from utils.common import use_defaults
@use_defaults()
class TaxSchemaPublic(SoftDeletionSchema):
class Meta:
type_ = 'tax'
self_view = 'v1.tax_detail'
self_view_kwargs = {'id': '<id>'}
inflect = dasherize
id = fields.Str(dump_only=True)
name = fields.Str(required=True)
rate = fields.Float(validate=lambda n: 0 <= n <= 100, required=True)
is_tax_included_in_price = fields.Boolean(default=False)
event = Relationship(attribute='event',
self_view='v1.tax_event',
self_view_kwargs={'id': '<id>'},
related_view='v1.event_detail',
related_view_kwargs={'tax_id': '<id>'},
schema='EventSchemaPublic',
type_='event')
class TaxSchema(TaxSchemaPublic):
class Meta:
type_ = 'tax'
self_view = 'v1.tax_detail'
self_view_kwargs = {'id': '<id>'}
inflect = dasherize
country = fields.Str(allow_none=True)
tax_id = fields.Str(required=True)
should_send_invoice = fields.Boolean(default=False)
is_invoice_sent = fields.Boolean(default=False)
registered_company = fields.Str(allow_none=True)
address = fields.Str(allow_none=True)
city = fields.Str(allow_none=True)
state = fields.Str(allow_none=True)
zip = fields.Integer(allow_none=True)
invoice_footer = fields.Str(allow_none=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment