Adding MoveOnDocument in migration and fixing schema
This commit is contained in:
parent
74af5add3c
commit
6cd28a3e3a
|
@ -29,18 +29,14 @@ def upgrade():
|
|||
op.add_column("trade_document", sa.Column("weight", sa.Float(decimal_return_scale=2), nullable=True), schema=f'{get_inv()}')
|
||||
|
||||
# DataWipeDocument table
|
||||
op.create_table('recycle_document',
|
||||
sa.Column('id', sa.BigInteger(), nullable=False),
|
||||
sa.Column('trade_document_id', sa.BigInteger(), nullable=False),
|
||||
sa.Column(
|
||||
'lot_id',
|
||||
postgresql.UUID(as_uuid=True),
|
||||
nullable=False
|
||||
),
|
||||
op.create_table('move_on_document',
|
||||
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
|
||||
sa.Column("weight", sa.Float(decimal_return_scale=2), nullable=True),
|
||||
sa.ForeignKeyConstraint(['lot_id'], [f'{get_inv()}.lot.id'],),
|
||||
sa.ForeignKeyConstraint(['trade_document_id'], [f'{get_inv()}.trade_document.id'], ),
|
||||
sa.ForeignKeyConstraint(['id'], [f'{get_inv()}.document.id'], ),
|
||||
sa.Column('container_from_id', sa.BigInteger(), nullable=False),
|
||||
sa.Column('container_to_id', sa.BigInteger(), nullable=False),
|
||||
sa.ForeignKeyConstraint(['container_from_id'], [f'{get_inv()}.trade_document.id'], ),
|
||||
sa.ForeignKeyConstraint(['container_to_id'], [f'{get_inv()}.trade_document.id'], ),
|
||||
sa.ForeignKeyConstraint(['id'], [f'{get_inv()}.action.id'], ),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
schema=f'{get_inv()}'
|
||||
)
|
||||
|
@ -48,4 +44,4 @@ def upgrade():
|
|||
|
||||
def downgrade():
|
||||
op.drop_column('trade_document', 'weight', schema=f'{get_inv()}')
|
||||
op.drop_table('recycle_document', schema=f'{get_inv()}')
|
||||
op.drop_table('move_on_document', schema=f'{get_inv()}')
|
||||
|
|
|
@ -315,6 +315,6 @@ class MigrateFromDef(ActionDef):
|
|||
SCHEMA = schemas.MigrateFrom
|
||||
|
||||
|
||||
class MoveOnContainerDef(ActionDef):
|
||||
class MoveOnDocumentDef(ActionDef):
|
||||
VIEW = None
|
||||
SCHEMA = schemas.MoveOnContainer
|
||||
SCHEMA = schemas.MoveOnDocument
|
||||
|
|
|
@ -1651,7 +1651,7 @@ class MakeAvailable(ActionWithMultipleDevices):
|
|||
pass
|
||||
|
||||
|
||||
class MoveOnContainer(JoinedTableMixin, ActionWithMultipleTradeDocuments):
|
||||
class MoveOnDocument(JoinedTableMixin, ActionWithMultipleTradeDocuments):
|
||||
"""Action than certify one movement of some indescriptible material of
|
||||
one container to an other."""
|
||||
|
||||
|
@ -1664,7 +1664,7 @@ class MoveOnContainer(JoinedTableMixin, ActionWithMultipleTradeDocuments):
|
|||
)
|
||||
container_from = db.relationship(
|
||||
'TradeDocument',
|
||||
primaryjoin='MoveOnContainer.container_from_id == TradeDocument.id',
|
||||
primaryjoin='MoveOnDocument.container_from_id == TradeDocument.id',
|
||||
)
|
||||
container_from_id.comment = """This is the trade document used as container in a incoming lot"""
|
||||
|
||||
|
@ -1675,7 +1675,7 @@ class MoveOnContainer(JoinedTableMixin, ActionWithMultipleTradeDocuments):
|
|||
)
|
||||
container_to = db.relationship(
|
||||
'TradeDocument',
|
||||
primaryjoin='MoveOnContainer.container_to_id == TradeDocument.id',
|
||||
primaryjoin='MoveOnDocument.container_to_id == TradeDocument.id',
|
||||
)
|
||||
container_to_id.comment = """This is the trade document used as container in a outgoing lot"""
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ import copy
|
|||
from datetime import datetime, timedelta
|
||||
from dateutil.tz import tzutc
|
||||
from flask import current_app as app, g
|
||||
from marshmallow import Schema as MarshmallowSchema, ValidationError, fields as f, validates_schema
|
||||
from marshmallow import Schema as MarshmallowSchema, ValidationError, fields as f, validates_schema, pre_load
|
||||
from marshmallow.fields import Boolean, DateTime, Decimal, Float, Integer, Nested, String, \
|
||||
TimeDelta, UUID
|
||||
from marshmallow.validate import Length, OneOf, Range
|
||||
|
@ -25,6 +25,7 @@ from ereuse_devicehub.resources.models import STR_BIG_SIZE, STR_SIZE
|
|||
from ereuse_devicehub.resources.schemas import Thing
|
||||
from ereuse_devicehub.resources.user import schemas as s_user
|
||||
from ereuse_devicehub.resources.user.models import User
|
||||
from ereuse_devicehub.resources.tradedocument.models import TradeDocument
|
||||
|
||||
|
||||
class Action(Thing):
|
||||
|
@ -842,8 +843,20 @@ class MigrateFrom(Migrate):
|
|||
__doc__ = m.MigrateFrom.__doc__
|
||||
|
||||
|
||||
class MoveOnContainer(Migrate):
|
||||
__doc__ = m.MoveOnContainer.__doc__
|
||||
class MoveOnDocument(Action):
|
||||
__doc__ = m.MoveOnDocument.__doc__
|
||||
weight = Integer()
|
||||
container_from = NestedOn('TradeDocument', only_query='id')
|
||||
container_to = NestedOn('TradeDocument', only_query='id')
|
||||
|
||||
@pre_load
|
||||
def extract_container(self, data):
|
||||
id_hash = data['container_to']
|
||||
docs = TradeDocument.query.filter_by(owner=g.user, file_hash=id_hash).all()
|
||||
if len(docs) > 1:
|
||||
txt = 'This document it is associated in more than one lot'
|
||||
raise ValidationError(txt)
|
||||
if len(docs) < 1:
|
||||
txt = 'This document not exist'
|
||||
raise ValidationError(txt)
|
||||
data['container_to'] = docs[0].id
|
||||
|
|
Reference in a new issue