From 13ee6d09e6e3034229b79831f27150aa9029afe8 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 19 Nov 2020 15:50:21 +0100 Subject: [PATCH] adding acctions into receives --- .../versions/e93aec8fc41f_added_assigned_action.py | 2 ++ ereuse_devicehub/resources/action/models.py | 9 ++++++++- ereuse_devicehub/resources/action/models.pyi | 8 +++----- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/ereuse_devicehub/migrations/versions/e93aec8fc41f_added_assigned_action.py b/ereuse_devicehub/migrations/versions/e93aec8fc41f_added_assigned_action.py index 9212fbcf..70778fc9 100644 --- a/ereuse_devicehub/migrations/versions/e93aec8fc41f_added_assigned_action.py +++ b/ereuse_devicehub/migrations/versions/e93aec8fc41f_added_assigned_action.py @@ -49,9 +49,11 @@ def upgrade(): 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()}' diff --git a/ereuse_devicehub/resources/action/models.py b/ereuse_devicehub/resources/action/models.py index 638f28be..5f3b9f19 100644 --- a/ereuse_devicehub/resources/action/models.py +++ b/ereuse_devicehub/resources/action/models.py @@ -1450,8 +1450,15 @@ class Receive(JoinedTableMixin, ActionWithMultipleDevices): default=lambda: g.user.individual.id) agent_to = relationship(Agent, backref=backref('actions_agent', lazy=True, **_sorted_actions), - primaryjoin=agent_to_id == Agent.id) + primaryjoin=agent_to_id == Action.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): diff --git a/ereuse_devicehub/resources/action/models.pyi b/ereuse_devicehub/resources/action/models.pyi index 6cd52d73..e95c3945 100644 --- a/ereuse_devicehub/resources/action/models.pyi +++ b/ereuse_devicehub/resources/action/models.pyi @@ -530,11 +530,9 @@ class TransferOwnershipBlockchain(Trade): class Receive(ActionWithMultipleDevices): - role = ... # type:Column - - def __init__(self, **kwargs) -> None: - super().__init__(**kwargs) - self.role = ... # type: ReceiverRole + agent_from = ... # type: relationship + agent_to = ... # type: relationship + action = ... # type: relationship class Migrate(ActionWithMultipleDevices):