Build action moveOn

This commit is contained in:
Cayo Puigdefabregas 2021-09-03 16:06:53 +02:00
parent 1aaf0a9ae7
commit 0d73bb1f63
5 changed files with 76 additions and 61 deletions

View file

@ -24,6 +24,7 @@ def get_inv():
raise ValueError("Inventory value is not specified") raise ValueError("Inventory value is not specified")
return INV return INV
def upgrade(): def upgrade():
op.add_column("trade_document", sa.Column("weight", sa.Float(decimal_return_scale=2), nullable=True), schema=f'{get_inv()}') op.add_column("trade_document", sa.Column("weight", sa.Float(decimal_return_scale=2), nullable=True), schema=f'{get_inv()}')

View file

@ -62,6 +62,15 @@ _sorted_actions = {
'order_by': lambda: Action.end_time, 'order_by': lambda: Action.end_time,
'collection_class': SortedSet 'collection_class': SortedSet
} }
def sorted_actions_by(data):
return {
'order_by': lambda: data,
'collection_class': SortedSet
}
"""For db.backref, return the actions sorted by end_time.""" """For db.backref, return the actions sorted by end_time."""
@ -1642,6 +1651,35 @@ class MakeAvailable(ActionWithMultipleDevices):
pass pass
class MoveOnContainer(JoinedTableMixin, ActionWithMultipleTradeDocuments):
"""Action than certify one movement of some indescriptible material of
one container to an other."""
weight = db.Column(db.Float(nullable=True))
weight.comment = """Weight than go to recycling"""
container_from_id = db.Column(
db.BigInteger,
db.ForeignKey('trade_document.id'),
nullable=False
)
container_from = db.relationship(
'TradeDocument',
primaryjoin='MoveOnContainer.container_from_id == TradeDocument.id',
)
container_from_id.comment = """This is the trade document used as container in a incoming lot"""
container_to_id = db.Column(
db.BigInteger,
db.ForeignKey('trade_document.id'),
nullable=False
)
container_to = db.relationship(
'TradeDocument',
primaryjoin='MoveOnContainer.container_to_id == TradeDocument.id',
)
container_to_id.comment = """This is the trade document used as container in a outgoing lot"""
class Migrate(JoinedTableMixin, ActionWithMultipleDevices): class Migrate(JoinedTableMixin, ActionWithMultipleDevices):
"""Moves the devices to a new database/inventory. Devices cannot be """Moves the devices to a new database/inventory. Devices cannot be
modified anymore at the previous database. modified anymore at the previous database.

View file

@ -33,8 +33,8 @@ from ereuse_devicehub.resources.documents.device_row import (DeviceRow, StockRow
from ereuse_devicehub.resources.lot import LotView from ereuse_devicehub.resources.lot import LotView
from ereuse_devicehub.resources.lot.models import Lot from ereuse_devicehub.resources.lot.models import Lot
from ereuse_devicehub.resources.hash_reports import insert_hash, ReportHash, verify_hash from ereuse_devicehub.resources.hash_reports import insert_hash, ReportHash, verify_hash
from ereuse_devicehub.resources.documents.models import RecycleDocument # from ereuse_devicehub.resources.documents.models import RecycleDocument
from ereuse_devicehub.resources.documents.schemas import RecycleDocument as sh_document # from ereuse_devicehub.resources.documents.schemas import RecycleDocument as sh_document
class Format(enum.Enum): class Format(enum.Enum):
@ -291,24 +291,24 @@ class StampsView(View):
result=result) result=result)
class RecycleDocumentView(View): # class RecycleDocumentView(View):
""" # """
This view allow save one document as a proof of one container with some weight was send to recycling. # This view allow save one document as a proof of one container with some weight was send to recycling.
""" # """
def post(self): # def post(self):
# import pdb; pdb.set_trace() # # import pdb; pdb.set_trace()
data = request.get_data() # data = request.get_data()
schema = sh_document() # schema = sh_document()
doc = schema.loads(data) # doc = schema.loads(data)
document = RecycleDocument(**doc) # document = RecycleDocument(**doc)
db.session.add(document) # db.session.add(document)
db.session().final_flush() # db.session().final_flush()
ret = jsonify(document) # ret = jsonify(document)
ret.status_code = 201 # ret.status_code = 201
db.session.commit() # db.session.commit()
return ret # return ret
class InternalStatsView(DeviceView): class InternalStatsView(DeviceView):
@ -457,6 +457,5 @@ class DocumentDef(Resource):
wbconf_view = app.auth.requires_auth(wbconf_view) wbconf_view = app.auth.requires_auth(wbconf_view)
self.add_url_rule('/wbconf/<string:wbtype>', view_func=wbconf_view, methods=get) self.add_url_rule('/wbconf/<string:wbtype>', view_func=wbconf_view, methods=get)
recycle_doc_view = RecycleDocumentView.as_view('RecycleDocumentView', definition=self, auth=app.auth) # recycle_doc_view = RecycleDocumentView.as_view('RecycleDocumentView', definition=self, auth=app.auth)
self.add_url_rule('/recycle/', defaults={}, view_func=recycle_doc_view, methods={'POST'}) # self.add_url_rule('/recycle/', defaults={}, view_func=recycle_doc_view, methods={'POST'})

View file

@ -64,26 +64,3 @@ class DataWipeDocument(JoinedTableMixin, Document):
def __str__(self) -> str: def __str__(self) -> str:
return '{0.file_name}'.format(self) return '{0.file_name}'.format(self)
class RecycleDocument(JoinedTableMixin, Document):
"""Document than proof how any of weight go to recycling."""
weight = db.Column(db.Float(nullable=True))
weight.comment = """Weight than go to recycling"""
trade_document_id = db.Column(db.BigInteger, db.ForeignKey('trade_document.id'))
trade_document_id.comment = """This is the trade document used for send material to recyle"""
lot_id = db.Column(UUID(as_uuid=True),
db.ForeignKey('lot.id'),
nullable=False)
lot_id.comment = """This lot is the input lot if the material that will then go definitively to recycling"""
lot = db.relationship('Lot',
backref=backref('recycling_documents',
lazy=True,
cascade=CASCADE_OWN,
**_sorted_documents),
primaryjoin='RecycleDocument.lot_id == Lot.id')
def __str__(self) -> str:
return '{0.file_name}'.format(self)

View file

@ -35,21 +35,21 @@ class DataWipeDocument(Thing):
data['document_type'] = 'DataWipeDocument' data['document_type'] = 'DataWipeDocument'
class RecycleDocument(Thing): # class RecycleDocument(Thing):
__doc__ = m.RecycleDocument.__doc__ # __doc__ = m.RecycleDocument.__doc__
file_hash = SanitizedStr(data_key='hash', # file_hash = SanitizedStr(data_key='hash',
default='', # default='',
description=m.RecycleDocument.file_hash.comment, # description=m.RecycleDocument.file_hash.comment,
validate=validate.Length(max=64)) # validate=validate.Length(max=64))
weight = Float(required=False, validate=Range(0.1), description=m.RecycleDocument.weight.comment) # weight = Float(required=False, validate=Range(0.1), description=m.RecycleDocument.weight.comment)
lot = NestedOn('Lot', only_query='id', description=m.RecycleDocument.lot.__doc__) # lot = NestedOn('Lot', only_query='id', description=m.RecycleDocument.lot.__doc__)
@post_load # @post_load
def get_trade_document(self, data): # def get_trade_document(self, data):
tradedocument = TradeDocument.query.filter_by(file_hash=data['file_hash']).one() # tradedocument = TradeDocument.query.filter_by(file_hash=data['file_hash']).one()
data['trade_document_id'] = tradedocument.id # data['trade_document_id'] = tradedocument.id
data['file_name'] = tradedocument.file_name # data['file_name'] = tradedocument.file_name
data['date'] = tradedocument.date # data['date'] = tradedocument.date
data['id_document'] = tradedocument.id_document # data['id_document'] = tradedocument.id_document
data['url'] = tradedocument.url # data['url'] = tradedocument.url
data['document_type'] = 'RecycleDocument' # data['document_type'] = 'RecycleDocument'