diff --git a/ereuse_devicehub/migrations/versions/e93aec8fc41f_added_assigned_action.py b/ereuse_devicehub/migrations/versions/e93aec8fc41f_added_assigned_action.py index 70778fc9..88c61fbf 100644 --- a/ereuse_devicehub/migrations/versions/e93aec8fc41f_added_assigned_action.py +++ b/ereuse_devicehub/migrations/versions/e93aec8fc41f_added_assigned_action.py @@ -41,23 +41,10 @@ def upgrade(): op.drop_table('deallocate', schema=f'{get_inv()}') # Add allocate as a column in device - op.add_column('device', sa.Column('allocate', sa.Boolean(), nullable=True), schema=f'{get_inv()}') + op.add_column('device', sa.Column('allocated', sa.Boolean(), nullable=True), schema=f'{get_inv()}') # Receive action op.drop_table('receive', schema=f'{get_inv()}') - op.create_table('receive', - sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False), - sa.Column('agent_from_id', postgresql.UUID(as_uuid=True), nullable=False), - sa.Column('agent_to_id', postgresql.UUID(as_uuid=True), nullable=False), - sa.Column('action_id', postgresql.UUID(as_uuid=True), nullable=True), - - sa.ForeignKeyConstraint(['agent_from_id'], [f'{get_inv()}.agent.id'], ), - sa.ForeignKeyConstraint(['agent_to_id'], [f'{get_inv()}.agent.id'], ), - sa.ForeignKeyConstraint(['action_id'], [f'{get_inv()}.action.id'], ), - sa.ForeignKeyConstraint(['id'], [f'{get_inv()}.action.id'], ), - sa.PrimaryKeyConstraint('id'), - schema=f'{get_inv()}' - ) def downgrade(): op.drop_table('allocate', schema=f'{get_inv()}') diff --git a/ereuse_devicehub/resources/action/__init__.py b/ereuse_devicehub/resources/action/__init__.py index 6bbd3937..01b32ac4 100644 --- a/ereuse_devicehub/resources/action/__init__.py +++ b/ereuse_devicehub/resources/action/__init__.py @@ -3,7 +3,7 @@ from typing import Callable, Iterable, Tuple from teal.resource import Converters, Resource from ereuse_devicehub.resources.action import schemas -from ereuse_devicehub.resources.action.views import ActionView, ReceiveView +from ereuse_devicehub.resources.action.views import ActionView from ereuse_devicehub.resources.device.sync import Sync @@ -248,11 +248,6 @@ class DisposeProductDef(ActionDef): SCHEMA = schemas.DisposeProduct -class ReceiveDef(ActionDef): - VIEW = ReceiveView - SCHEMA = schemas.Receive - - class MigrateToDef(ActionDef): VIEW = None SCHEMA = schemas.MigrateTo diff --git a/ereuse_devicehub/resources/action/models.py b/ereuse_devicehub/resources/action/models.py index 7d8cfb27..7f64cd7e 100644 --- a/ereuse_devicehub/resources/action/models.py +++ b/ereuse_devicehub/resources/action/models.py @@ -1430,37 +1430,6 @@ class MakeAvailable(ActionWithMultipleDevices): pass -class Receive(JoinedTableMixin, ActionWithMultipleDevices): - """The act of physically taking delivery of a device. - - The Agent confirm than the device changes hands and have a new possessor - :attr:`ereuse_devicehub.resources.device.models.Device.physical_possessor`. - """ - agent_from_id = Column(UUID(as_uuid=True), - ForeignKey(Agent.id), - nullable=False, - default=lambda: g.user.individual.id) - agent_from = relationship(Agent, - backref=backref('receive_agent_from', lazy=True, **_sorted_actions), - primaryjoin=agent_from_id == Agent.id) - agent_from_id.comment = """ This device go from this agent """ - agent_to_id = Column(UUID(as_uuid=True), - ForeignKey(Agent.id), - nullable=False, - default=lambda: g.user.individual.id) - agent_to = relationship(Agent, - backref=backref('receive_agent_to', lazy=True, **_sorted_actions), - primaryjoin=agent_to_id == Agent.id) - agent_to_id.comment = """ This device go to this agent """ - action_id = Column(UUID(as_uuid=True), - ForeignKey(Action.id), - nullable=True) - action = relationship(Action, - backref=backref('actions_id', lazy=True, **_sorted_actions), - primaryjoin=action_id == Action.id) - action_id.comment = """ This Receive confirm this action """ - - class Migrate(JoinedTableMixin, ActionWithMultipleDevices): """Moves the devices to a new database/inventory. Devices cannot be modified anymore at the previous database. diff --git a/ereuse_devicehub/resources/action/schemas.py b/ereuse_devicehub/resources/action/schemas.py index 397cf8b2..8534b8f7 100644 --- a/ereuse_devicehub/resources/action/schemas.py +++ b/ereuse_devicehub/resources/action/schemas.py @@ -432,13 +432,6 @@ class TransferOwnershipBlockchain(Trade): __doc__ = m.TransferOwnershipBlockchain.__doc__ -class Receive(ActionWithMultipleDevices): - __doc__ = m.Receive.__doc__ - agent_from = NestedOn(s_agent.Agent, only_query='id', required=False, comment=m.Receive.agent_from_id.comment) - agent_to = NestedOn(s_agent.Agent, only_query='id', required=False, comment=m.Receive.agent_to_id.comment) - action = NestedOn(s_action.Action, only_query='id', required=False, comment=m.Receive.action_id.comment) - - class Migrate(ActionWithMultipleDevices): __doc__ = m.Migrate.__doc__ other = URL() diff --git a/ereuse_devicehub/resources/action/views.py b/ereuse_devicehub/resources/action/views.py index 84c92b0f..1e0908cb 100644 --- a/ereuse_devicehub/resources/action/views.py +++ b/ereuse_devicehub/resources/action/views.py @@ -16,7 +16,7 @@ from teal.resource import View from ereuse_devicehub.db import db from ereuse_devicehub.query import things_response from ereuse_devicehub.resources.action.models import (Action, RateComputer, Snapshot, VisualTest, - InitTransfer, Receive) + InitTransfer) from ereuse_devicehub.resources.action.rate.v1_0 import CannotRate from ereuse_devicehub.resources.enums import SnapshotSoftware, Severity from ereuse_devicehub.resources.user.exceptions import InsufficientPermission @@ -171,26 +171,3 @@ class ActionView(View): """Perform a InitTransfer action to change author_id of device""" pass -class ReceiveView(View): - - def post(self): - # return jsonify('Ok') - """ Create one receive """ - res_json = request.get_json() - receive = Receive(**res_json) - db.session.add(receive) - db.session().final_flush() - ret = self.schema.jsonify(receive) - ret.status_code = 201 - db.session.commit() - return ret - - def find(self, args: dict): - receives = Receive.query.filter_by(author=g.user) \ - .order_by(Receive.created.desc()) \ - .paginate(per_page=200) - return things_response( - self.schema.dump(receives.items, many=True, nested=0), - receives.page, receives.per_page, receives.total, - receives.prev_num, receives.next_num - ) diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index 21688eed..399bab92 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -256,7 +256,7 @@ class Device(Thing): from ereuse_devicehub.resources.action.models import Receive with suppress(LookupError): action = self.last_action_of(Receive) - return action.to + return action.agent_to @property def working(self): diff --git a/ereuse_devicehub/resources/device/states.py b/ereuse_devicehub/resources/device/states.py index 8a916419..a67a410d 100644 --- a/ereuse_devicehub/resources/device/states.py +++ b/ereuse_devicehub/resources/device/states.py @@ -64,7 +64,8 @@ class Traking(State): :cvar Receive: The device changes hands """ - Receive = e.Receive + # Receive = e.Receive + pass class Usage(State):