remove receives
This commit is contained in:
parent
67d7e27cf9
commit
32a17decd7
|
@ -41,23 +41,10 @@ def upgrade():
|
||||||
op.drop_table('deallocate', schema=f'{get_inv()}')
|
op.drop_table('deallocate', schema=f'{get_inv()}')
|
||||||
|
|
||||||
# Add allocate as a column in device
|
# 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
|
# Receive action
|
||||||
op.drop_table('receive', schema=f'{get_inv()}')
|
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():
|
def downgrade():
|
||||||
op.drop_table('allocate', schema=f'{get_inv()}')
|
op.drop_table('allocate', schema=f'{get_inv()}')
|
||||||
|
|
|
@ -3,7 +3,7 @@ from typing import Callable, Iterable, Tuple
|
||||||
from teal.resource import Converters, Resource
|
from teal.resource import Converters, Resource
|
||||||
|
|
||||||
from ereuse_devicehub.resources.action import schemas
|
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
|
from ereuse_devicehub.resources.device.sync import Sync
|
||||||
|
|
||||||
|
|
||||||
|
@ -248,11 +248,6 @@ class DisposeProductDef(ActionDef):
|
||||||
SCHEMA = schemas.DisposeProduct
|
SCHEMA = schemas.DisposeProduct
|
||||||
|
|
||||||
|
|
||||||
class ReceiveDef(ActionDef):
|
|
||||||
VIEW = ReceiveView
|
|
||||||
SCHEMA = schemas.Receive
|
|
||||||
|
|
||||||
|
|
||||||
class MigrateToDef(ActionDef):
|
class MigrateToDef(ActionDef):
|
||||||
VIEW = None
|
VIEW = None
|
||||||
SCHEMA = schemas.MigrateTo
|
SCHEMA = schemas.MigrateTo
|
||||||
|
|
|
@ -1430,37 +1430,6 @@ class MakeAvailable(ActionWithMultipleDevices):
|
||||||
pass
|
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):
|
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.
|
||||||
|
|
|
@ -432,13 +432,6 @@ class TransferOwnershipBlockchain(Trade):
|
||||||
__doc__ = m.TransferOwnershipBlockchain.__doc__
|
__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):
|
class Migrate(ActionWithMultipleDevices):
|
||||||
__doc__ = m.Migrate.__doc__
|
__doc__ = m.Migrate.__doc__
|
||||||
other = URL()
|
other = URL()
|
||||||
|
|
|
@ -16,7 +16,7 @@ from teal.resource import View
|
||||||
from ereuse_devicehub.db import db
|
from ereuse_devicehub.db import db
|
||||||
from ereuse_devicehub.query import things_response
|
from ereuse_devicehub.query import things_response
|
||||||
from ereuse_devicehub.resources.action.models import (Action, RateComputer, Snapshot, VisualTest,
|
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.action.rate.v1_0 import CannotRate
|
||||||
from ereuse_devicehub.resources.enums import SnapshotSoftware, Severity
|
from ereuse_devicehub.resources.enums import SnapshotSoftware, Severity
|
||||||
from ereuse_devicehub.resources.user.exceptions import InsufficientPermission
|
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"""
|
"""Perform a InitTransfer action to change author_id of device"""
|
||||||
pass
|
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
|
|
||||||
)
|
|
||||||
|
|
|
@ -256,7 +256,7 @@ class Device(Thing):
|
||||||
from ereuse_devicehub.resources.action.models import Receive
|
from ereuse_devicehub.resources.action.models import Receive
|
||||||
with suppress(LookupError):
|
with suppress(LookupError):
|
||||||
action = self.last_action_of(Receive)
|
action = self.last_action_of(Receive)
|
||||||
return action.to
|
return action.agent_to
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def working(self):
|
def working(self):
|
||||||
|
|
|
@ -64,7 +64,8 @@ class Traking(State):
|
||||||
|
|
||||||
:cvar Receive: The device changes hands
|
:cvar Receive: The device changes hands
|
||||||
"""
|
"""
|
||||||
Receive = e.Receive
|
# Receive = e.Receive
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class Usage(State):
|
class Usage(State):
|
||||||
|
|
Reference in New Issue