This commit is contained in:
Cayo Puigdefabregas 2020-11-21 19:10:31 +01:00
parent 775cd9a215
commit 0e53919607

View file

@ -43,7 +43,7 @@ from ereuse_devicehub.resources.device.models import Component, Computer, DataSt
Device, Laptop, Server
from ereuse_devicehub.resources.enums import AppearanceRange, BatteryHealth, BiosAccessRange, \
ErasureStandards, FunctionalityRange, PhysicalErasureMethod, PriceSoftware, \
R_NEGATIVE, R_POSITIVE, RatingRange, ReceiverRole, Severity, SnapshotSoftware, \
R_NEGATIVE, R_POSITIVE, RatingRange, Severity, SnapshotSoftware, \
TestDataStorageLength
from ereuse_devicehub.resources.models import STR_SM_SIZE, Thing
from ereuse_devicehub.resources.user.models import User
@ -129,8 +129,7 @@ class Action(Thing):
agent = relationship(Agent,
backref=backref('actions_agent', lazy=True, **_sorted_actions),
primaryjoin=agent_id == Agent.id)
agent_id.comment = """The direct performer or driver of the action.
e.g. John wrote a book.
agent_id.comment = """The direct performer or driver of the action. e.g. John wrote a book.
It can differ with the user that registered the action in the
system, which can be in their behalf.
@ -324,6 +323,7 @@ class Deallocate(JoinedTableMixin, ActionWithMultipleDevices):
"""
pass
class EraseBasic(JoinedWithOneDeviceMixin, ActionWithOneDevice):
"""An erasure attempt to a ``DataStorage``. The action contains
information about success and nature of the erasure.
@ -1373,7 +1373,6 @@ class Trade(JoinedTableMixin, ActionWithMultipleDevices):
backref=backref('confirmation', lazy=True, uselist=False),
primaryjoin=confirms_id == Organize.id)
confirms_id.comment = """An organize action that this association confirms.
For example, a ``Sell`` or ``Rent``
can confirm a ``Reserve`` action.
"""
@ -1531,6 +1530,36 @@ def update_parent(target: Union[EraseBasic, Test, Install], device: Device, _, _
target.parent = device.parent
@event.listens_for(Allocate.devices, 'append')
def update_allocated(target: Allocate, device, initiatort):
"""Mark one device as allocated."""
# for device in target.devices:
actions = [a for a in device.actions]
actions.sort(key=lambda x: x.created)
actions.reverse()
allocate = None
#import pdb; pdb.set_trace()
for a in actions:
if isinstance(a, Allocate):
allocate = a
break
if isinstance(a, Deallocate):
break
if allocate:
txt = "You need deallocate before allocate this device again"
same_allocate = [
allocate.code == target.code,
allocate.start_time == target.start_time,
allocate.end_users == target.end_users
]
assert all(same_allocate), txt
import pdb; pdb.set_trace()
target.allocated = True
class InvalidRangeForPrice(ValueError):
pass