2023-03-21 11:08:13 +00:00
|
|
|
from marshmallow import fields as ma_fields
|
|
|
|
from marshmallow import validate as ma_validate
|
2018-08-03 16:15:08 +00:00
|
|
|
from marshmallow.fields import Email
|
|
|
|
|
|
|
|
from ereuse_devicehub.marshmallow import NestedOn
|
|
|
|
from ereuse_devicehub.resources.models import STR_SIZE, STR_SM_SIZE
|
|
|
|
from ereuse_devicehub.resources.schemas import Thing
|
2023-03-21 11:08:13 +00:00
|
|
|
from ereuse_devicehub.teal import enums
|
|
|
|
from ereuse_devicehub.teal.marshmallow import EnumField, Phone, SanitizedStr
|
2018-08-03 16:15:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Agent(Thing):
|
|
|
|
id = ma_fields.UUID(dump_only=True)
|
2018-09-30 10:29:33 +00:00
|
|
|
name = SanitizedStr(validate=ma_validate.Length(max=STR_SM_SIZE))
|
2023-03-21 11:08:13 +00:00
|
|
|
tax_id = SanitizedStr(
|
|
|
|
lower=True, validate=ma_validate.Length(max=STR_SM_SIZE), data_key='taxId'
|
|
|
|
)
|
2018-08-03 16:15:08 +00:00
|
|
|
country = EnumField(enums.Country)
|
|
|
|
telephone = Phone()
|
|
|
|
email = Email()
|
|
|
|
|
|
|
|
|
|
|
|
class Organization(Agent):
|
|
|
|
members = NestedOn('Membership')
|
2019-01-23 15:55:04 +00:00
|
|
|
default_of = NestedOn('Inventory')
|
2018-08-03 16:15:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Membership(Thing):
|
|
|
|
organization = NestedOn(Organization)
|
|
|
|
individual = NestedOn('Individual')
|
2018-09-30 10:29:33 +00:00
|
|
|
id = SanitizedStr(lower=True, validate=ma_validate.Length(max=STR_SIZE))
|
2018-08-03 16:15:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Individual(Agent):
|
|
|
|
member_of = NestedOn(Membership, many=True)
|
|
|
|
|
|
|
|
|
|
|
|
class Person(Individual):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class System(Individual):
|
|
|
|
pass
|