diff --git a/.gitignore b/.gitignore index bed364c2..e5012c76 100644 --- a/.gitignore +++ b/.gitignore @@ -109,4 +109,3 @@ ENV/ .vscode/ .DS_Store /app.py - diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index cb04f425..2cc5333d 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -20,14 +20,14 @@ from sqlalchemy_utils import ColorType from sqlalchemy.dialects.postgresql import UUID from stdnum import imei, meid from teal.db import CASCADE_DEL, POLYMORPHIC_ID, POLYMORPHIC_ON, ResourceNotFound, URL, \ - check_lower, check_range + check_lower, check_range, IntEnum from teal.enums import Layouts from teal.marshmallow import ValidationError from teal.resource import url_for_resource from ereuse_devicehub.db import db from ereuse_devicehub.resources.enums import BatteryTechnology, CameraFacing, ComputerChassis, \ - DataStorageInterface, DisplayTech, PrinterTechnology, RamFormat, RamInterface, Severity + DataStorageInterface, DisplayTech, PrinterTechnology, RamFormat, RamInterface, Severity, TransferState from ereuse_devicehub.resources.models import STR_SM_SIZE, Thing from ereuse_devicehub.resources.user.models import User @@ -387,6 +387,13 @@ class Computer(Device): nullable=False, default=lambda: g.user.id) author = db.relationship(User, primaryjoin=author_id == User.id) + transfer_state = db.Column(IntEnum(TransferState), default=TransferState.Initial, nullable=False) + transfer_state.comment = TransferState.__doc__ + receiver_id = db.Column(CIText(), + db.ForeignKey(User.ethereum_address), + nullable=True) + receiver = db.relationship(User, primaryjoin=receiver_id == User.ethereum_address) + delivery_note_address = db.Column(CIText(), nullable=True) def __init__(self, chassis, **kwargs) -> None: chassis = ComputerChassis(chassis) diff --git a/ereuse_devicehub/resources/device/models.pyi b/ereuse_devicehub/resources/device/models.pyi index 77740a76..f50a8577 100644 --- a/ereuse_devicehub/resources/device/models.pyi +++ b/ereuse_devicehub/resources/device/models.pyi @@ -143,13 +143,18 @@ class Computer(DisplayMixin, Device): chassis = ... # type: Column deposit = ... # type: Column author_id = ... # type: Column + transfer_state = ... # type: Column + receiver_id = ... # type: Column + delivery_note_address = ... # type: Column def __init__(self, **kwargs) -> None: super().__init__(**kwargs) self.components = ... # type: Set[Component] self.actions_parent = ... # type: Set[e.Action] self.chassis = ... # type: ComputerChassis - self.author_id = ... + self.author_id = ... # type: UUID + self.transfer_state = ... + self.receiver_id = ... # type: str @property def actions(self) -> List: diff --git a/ereuse_devicehub/resources/device/schemas.py b/ereuse_devicehub/resources/device/schemas.py index ec9b85a2..36f96698 100644 --- a/ereuse_devicehub/resources/device/schemas.py +++ b/ereuse_devicehub/resources/device/schemas.py @@ -1,6 +1,6 @@ import datetime -from marshmallow import post_load, pre_load +from marshmallow import post_load, pre_load, fields as f from marshmallow.fields import Boolean, Date, DateTime, Float, Integer, List, Str, String, UUID from marshmallow.validate import Length, OneOf, Range from sqlalchemy.util import OrderedSet @@ -128,6 +128,9 @@ class Computer(Device): # author_id = NestedOn(s_user.User,only_query='author_id') author_id = UUID(dump_only=True, data_key='author_id') + transfer_state = EnumField(enums.TransferState, description=m.Computer.transfer_state.comment) + receiver_id = SanitizedStr(validate=f.validate.Length(max=42)) + class Desktop(Computer): __doc__ = m.Desktop.__doc__