fixing 3 bugs, #168

This commit is contained in:
Cayo Puigdefabregas 2021-10-04 13:35:51 +02:00
parent b02f9dfac5
commit ab74240d6c
3 changed files with 23 additions and 10 deletions

View file

@ -1664,7 +1664,10 @@ class MoveOnDocument(JoinedTableMixin, ActionWithMultipleTradeDocuments):
)
container_from = db.relationship(
'TradeDocument',
primaryjoin='MoveOnDocument.container_from_id == TradeDocument.id',
backref=backref('containers_from',
lazy=True,
cascade=CASCADE_OWN),
primaryjoin='MoveOnDocument.container_from_id == TradeDocument.id'
)
container_from_id.comment = """This is the trade document used as container in a incoming lot"""
@ -1675,6 +1678,9 @@ class MoveOnDocument(JoinedTableMixin, ActionWithMultipleTradeDocuments):
)
container_to = db.relationship(
'TradeDocument',
backref=backref('containers_to',
lazy=True,
cascade=CASCADE_OWN),
primaryjoin='MoveOnDocument.container_to_id == TradeDocument.id',
)
container_to_id.comment = """This is the trade document used as container in a outgoing lot"""

View file

@ -342,13 +342,6 @@ class Device(Thing):
if action.type == 'Revoke':
return action.id
@property
def confirm_status(self):
"""The actual state of confirmation of one Trade, or None if no Trade action
has ever been performed to this device."""
# TODO @cayop we need implement this functionality
return None
@property
def physical(self):
"""The actual physical state, None otherwise."""

View file

@ -1,3 +1,5 @@
import copy
from contextlib import suppress
from citext import CIText
from flask import g
@ -101,10 +103,10 @@ class TradeDocument(Thing):
revoke = 'Revoke'
revoke_pending = 'Revoke Pending'
confirm_revoke = 'Document Revoked'
if not self.actions:
ac = self.last_action_trading()
if not ac:
return
ac = self.actions[-1]
if ac.type == 'ConfirmRevokeDocument':
# can to do revoke_confirmed
@ -143,6 +145,18 @@ class TradeDocument(Thing):
return weight
def last_action_trading(self):
"""which is the last action trading"""
with suppress(StopIteration, ValueError):
actions = copy.copy(self.actions)
actions.sort(key=lambda x: x.created)
t_trades = ['Trade',
'Confirm',
'ConfirmRevokeDocument',
'RevokeDocument',
'ConfirmDocument']
return next(e for e in reversed(actions) if e.t in t_trades)
def _warning_actions(self, actions):
"""Show warning actions"""
return sorted(ev for ev in actions if ev.severity >= Severity.Warning)