From b2e11527cbe011f1c7844c9447189e287fb291ee Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 27 May 2022 16:32:54 +0200 Subject: [PATCH] fix model transfer --- ereuse_devicehub/inventory/models.py | 7 ++++++- .../migrations/versions/054a3aea9f08_transfer.py | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/ereuse_devicehub/inventory/models.py b/ereuse_devicehub/inventory/models.py index ad725faf..a3fe9b8e 100644 --- a/ereuse_devicehub/inventory/models.py +++ b/ereuse_devicehub/inventory/models.py @@ -8,6 +8,7 @@ from teal.db import CASCADE_OWN from ereuse_devicehub.db import db from ereuse_devicehub.resources.models import Thing +from ereuse_devicehub.resources.user.models import User class Transfer(Thing): @@ -18,7 +19,7 @@ class Transfer(Thing): id = Column(UUID(as_uuid=True), primary_key=True, default=uuid4) code = Column(CIText(), default='', nullable=False) - closed = Boolean(default=False) + closed = Column(Boolean, nullable=False, default=False) date = Column(db.TIMESTAMP(timezone=True)) description = Column(CIText(), default='', nullable=True) lot_id = db.Column( @@ -31,3 +32,7 @@ class Transfer(Thing): backref=backref('transfer', lazy=True, uselist=False, cascade=CASCADE_OWN), primaryjoin='Transfer.lot_id == Lot.id', ) + user_from_id = db.Column(UUID(as_uuid=True), db.ForeignKey(User.id), nullable=True) + user_from = db.relationship(User, primaryjoin=user_from_id == User.id) + user_to_id = db.Column(UUID(as_uuid=True), db.ForeignKey(User.id), nullable=True) + user_to = db.relationship(User, primaryjoin=user_to_id == User.id) diff --git a/ereuse_devicehub/migrations/versions/054a3aea9f08_transfer.py b/ereuse_devicehub/migrations/versions/054a3aea9f08_transfer.py index a6b4767e..3fbcba8d 100644 --- a/ereuse_devicehub/migrations/versions/054a3aea9f08_transfer.py +++ b/ereuse_devicehub/migrations/versions/054a3aea9f08_transfer.py @@ -50,8 +50,12 @@ def upgrade(): comment='A comment about the action.', ), sa.Column('date', sa.TIMESTAMP(timezone=True), nullable=True), - sa.Column('lot_id', postgresql.UUID(as_uuid=True), nullable=True), + sa.Column('lot_id', postgresql.UUID(as_uuid=True), nullable=False), + sa.Column('user_to_id', postgresql.UUID(as_uuid=True), nullable=True), + sa.Column('user_from_id', postgresql.UUID(as_uuid=True), nullable=True), sa.ForeignKeyConstraint(['lot_id'], [f'{get_inv()}.lot.id']), + sa.ForeignKeyConstraint(['user_from_id'], ['common.user.id']), + sa.ForeignKeyConstraint(['user_to_id'], ['common.user.id']), sa.PrimaryKeyConstraint('id'), schema=f'{get_inv()}', )