adding receives
This commit is contained in:
parent
11d766d2a4
commit
cf3d44a5e3
|
@ -27,6 +27,7 @@ def get_inv():
|
||||||
return INV
|
return INV
|
||||||
|
|
||||||
def upgrade():
|
def upgrade():
|
||||||
|
# Allocate action
|
||||||
op.drop_table('allocate', schema=f'{get_inv()}')
|
op.drop_table('allocate', schema=f'{get_inv()}')
|
||||||
op.create_table('allocate',
|
op.create_table('allocate',
|
||||||
sa.Column('code', citext.CIText(), nullable=True, comment=' This is a internal code for mainteing the secrets of the personal datas of the new holder '),
|
sa.Column('code', citext.CIText(), nullable=True, comment=' This is a internal code for mainteing the secrets of the personal datas of the new holder '),
|
||||||
|
@ -39,7 +40,22 @@ 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
|
||||||
op.add_column('device', sa.Column('allocate', sa.Boolean(), nullable=True), schema=f'{get_inv()}')
|
op.add_column('device', sa.Column('allocate', 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.ForeignKeyConstraint(['agent_from_id'], [f'{get_inv()}.agent.id'], ),
|
||||||
|
sa.ForeignKeyConstraint(['agent_to_id'], [f'{get_inv()}.agent.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()}')
|
||||||
|
|
|
@ -1433,21 +1433,25 @@ class MakeAvailable(ActionWithMultipleDevices):
|
||||||
class Receive(JoinedTableMixin, ActionWithMultipleDevices):
|
class Receive(JoinedTableMixin, ActionWithMultipleDevices):
|
||||||
"""The act of physically taking delivery of a device.
|
"""The act of physically taking delivery of a device.
|
||||||
|
|
||||||
The receiver confirms that the devices have arrived, and thus,
|
The Agent confirm than the device changes hands and have a new possessor
|
||||||
they are the
|
|
||||||
:attr:`ereuse_devicehub.resources.device.models.Device.physical_possessor`.
|
:attr:`ereuse_devicehub.resources.device.models.Device.physical_possessor`.
|
||||||
|
|
||||||
This differs from :class:`.Trade` in that trading changes the
|
|
||||||
political possession. As an example, a transporter can *receive*
|
|
||||||
a device but it is not it's owner. After the delivery, the
|
|
||||||
transporter performs another *receive* to the final owner.
|
|
||||||
|
|
||||||
The receiver can optionally take a
|
|
||||||
:class:`ereuse_devicehub.resources.enums.ReceiverRole`.
|
|
||||||
"""
|
"""
|
||||||
role = Column(DBEnum(ReceiverRole),
|
agent_from_id = Column(UUID(as_uuid=True),
|
||||||
|
ForeignKey(Agent.id),
|
||||||
nullable=False,
|
nullable=False,
|
||||||
default=ReceiverRole.Intermediary)
|
default=lambda: g.user.individual.id)
|
||||||
|
agent_from = relationship(Agent,
|
||||||
|
backref=backref('actions_agent', 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('actions_agent', lazy=True, **_sorted_actions),
|
||||||
|
primaryjoin=agent_to_id == Agent.id)
|
||||||
|
agent_to_id.comment = """ This device go to this agent """
|
||||||
|
|
||||||
|
|
||||||
class Migrate(JoinedTableMixin, ActionWithMultipleDevices):
|
class Migrate(JoinedTableMixin, ActionWithMultipleDevices):
|
||||||
|
|
|
@ -221,6 +221,22 @@ class Device(Thing):
|
||||||
action = self.last_action_of(*states.Physical.actions())
|
action = self.last_action_of(*states.Physical.actions())
|
||||||
return states.Physical(action.__class__)
|
return states.Physical(action.__class__)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def traking(self):
|
||||||
|
"""The actual traking state, None otherwise."""
|
||||||
|
from ereuse_devicehub.resources.device import states
|
||||||
|
with suppress(LookupError, ValueError):
|
||||||
|
action = self.last_action_of(*states.Traking.actions())
|
||||||
|
return states.Traking(action.__class__)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def usage(self):
|
||||||
|
"""The actual usage state, None otherwise."""
|
||||||
|
from ereuse_devicehub.resources.device import states
|
||||||
|
with suppress(LookupError, ValueError):
|
||||||
|
action = self.last_action_of(*states.Usage.actions())
|
||||||
|
return states.Usage(action.__class__)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def physical_possessor(self):
|
def physical_possessor(self):
|
||||||
"""The actual physical possessor or None.
|
"""The actual physical possessor or None.
|
||||||
|
@ -240,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.agent
|
return action.to
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def working(self):
|
def working(self):
|
||||||
|
|
|
@ -51,11 +51,27 @@ class Physical(State):
|
||||||
:cvar Preparing: The device is going to be or being prepared.
|
:cvar Preparing: The device is going to be or being prepared.
|
||||||
:cvar Prepared: The device has been prepared.
|
:cvar Prepared: The device has been prepared.
|
||||||
:cvar Ready: The device is in working conditions.
|
:cvar Ready: The device is in working conditions.
|
||||||
:cvar InUse: The device is being reported to be in active use.
|
|
||||||
"""
|
"""
|
||||||
ToBeRepaired = e.ToRepair
|
ToBeRepaired = e.ToRepair
|
||||||
Repaired = e.Repair
|
Repaired = e.Repair
|
||||||
Preparing = e.ToPrepare
|
Preparing = e.ToPrepare
|
||||||
Prepared = e.Prepare
|
Prepared = e.Prepare
|
||||||
Ready = e.Ready
|
Ready = e.Ready
|
||||||
|
|
||||||
|
|
||||||
|
class Traking(State):
|
||||||
|
"""Traking states.
|
||||||
|
|
||||||
|
:cvar Receive: The device changes hands
|
||||||
|
"""
|
||||||
|
Receive = e.Receive
|
||||||
|
|
||||||
|
|
||||||
|
class Usage(State):
|
||||||
|
"""Usage states.
|
||||||
|
|
||||||
|
:cvar Allocate: The device is allocate in other Agent (organization, person ...)
|
||||||
|
:cvar InUse: The device is being reported to be in active use.
|
||||||
|
"""
|
||||||
|
Allocate = e.Allocate
|
||||||
InUse = e.Live
|
InUse = e.Live
|
||||||
|
|
Reference in New Issue