2018-08-08 19:25:53 +00:00
|
|
|
from marshmallow import fields as f
|
|
|
|
|
|
|
|
from ereuse_devicehub.marshmallow import NestedOn
|
2023-03-21 11:08:13 +00:00
|
|
|
from ereuse_devicehub.resources.action import schemas as s_action
|
2020-08-17 14:45:18 +00:00
|
|
|
from ereuse_devicehub.resources.deliverynote import schemas as s_deliverynote
|
2019-02-03 16:12:53 +00:00
|
|
|
from ereuse_devicehub.resources.device import schemas as s_device
|
2020-08-17 14:45:18 +00:00
|
|
|
from ereuse_devicehub.resources.enums import TransferState
|
2018-08-08 19:25:53 +00:00
|
|
|
from ereuse_devicehub.resources.lot import models as m
|
|
|
|
from ereuse_devicehub.resources.models import STR_SIZE
|
|
|
|
from ereuse_devicehub.resources.schemas import Thing
|
2023-03-21 11:08:13 +00:00
|
|
|
from ereuse_devicehub.teal.marshmallow import URL, EnumField, SanitizedStr
|
2018-08-08 19:25:53 +00:00
|
|
|
|
2021-11-18 10:48:57 +00:00
|
|
|
TRADE_VALUES = (
|
|
|
|
'id',
|
|
|
|
'user_from.email',
|
|
|
|
'user_to.email',
|
|
|
|
'user_from.id',
|
|
|
|
'user_to.id',
|
|
|
|
'user_to.code',
|
2023-03-21 11:08:13 +00:00
|
|
|
'user_from.code',
|
2021-11-18 10:48:57 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-03-21 11:08:13 +00:00
|
|
|
DOCUMENTS_VALUES = ('id', 'file_name', 'total_weight', 'trading')
|
2021-11-18 10:48:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Old_Lot(Thing):
|
2018-08-08 19:25:53 +00:00
|
|
|
id = f.UUID(dump_only=True)
|
2018-09-30 10:29:33 +00:00
|
|
|
name = SanitizedStr(validate=f.validate.Length(max=STR_SIZE), required=True)
|
2018-11-06 17:08:57 +00:00
|
|
|
description = SanitizedStr(description=m.Lot.description.comment)
|
2018-09-11 19:50:40 +00:00
|
|
|
closed = f.Boolean(missing=False, description=m.Lot.closed.comment)
|
2019-02-03 16:12:53 +00:00
|
|
|
devices = NestedOn(s_device.Device, many=True, dump_only=True)
|
2018-09-12 12:53:14 +00:00
|
|
|
children = NestedOn('Lot', many=True, dump_only=True)
|
|
|
|
parents = NestedOn('Lot', many=True, dump_only=True)
|
2018-10-05 15:13:23 +00:00
|
|
|
url = URL(dump_only=True, description=m.Lot.url.__doc__)
|
2023-03-21 11:08:13 +00:00
|
|
|
amount = f.Integer(
|
|
|
|
validate=f.validate.Range(min=0, max=100), description=m.Lot.amount.__doc__
|
|
|
|
)
|
2019-12-11 01:49:47 +00:00
|
|
|
# author_id = NestedOn(s_user.User,only_query='author_id')
|
2020-04-01 17:11:14 +00:00
|
|
|
owner_id = f.UUID(data_key='ownerID')
|
2019-12-16 18:17:30 +00:00
|
|
|
transfer_state = EnumField(TransferState, description=m.Lot.transfer_state.comment)
|
2019-12-19 00:38:03 +00:00
|
|
|
receiver_address = SanitizedStr(validate=f.validate.Length(max=42))
|
2020-03-04 17:49:55 +00:00
|
|
|
deliverynote = NestedOn(s_deliverynote.Deliverynote, dump_only=True)
|
2021-06-15 13:22:49 +00:00
|
|
|
documents = NestedOn('TradeDocument', many=True, dump_only=True)
|
2021-11-18 10:48:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Lot(Thing):
|
|
|
|
id = f.UUID(dump_only=True)
|
|
|
|
name = SanitizedStr(validate=f.validate.Length(max=STR_SIZE), required=True)
|
|
|
|
description = SanitizedStr(description=m.Lot.description.comment)
|
|
|
|
trade = f.Nested(s_action.Trade, dump_only=True, only=TRADE_VALUES)
|
2023-03-21 11:08:13 +00:00
|
|
|
documents = f.Nested(
|
|
|
|
'TradeDocument', many=True, dump_only=True, only=DOCUMENTS_VALUES
|
|
|
|
)
|