adding action moveOn inside of tradeDocuments
This commit is contained in:
parent
1e86515391
commit
b7396b4f23
|
@ -2,7 +2,7 @@ import copy
|
|||
from datetime import datetime, timedelta
|
||||
from dateutil.tz import tzutc
|
||||
from flask import current_app as app, g
|
||||
from marshmallow import Schema as MarshmallowSchema, ValidationError, fields as f, validates_schema, pre_load
|
||||
from marshmallow import Schema as MarshmallowSchema, ValidationError, fields as f, validates_schema, pre_load, post_load
|
||||
from marshmallow.fields import Boolean, DateTime, Decimal, Float, Integer, Nested, String, \
|
||||
TimeDelta, UUID
|
||||
from marshmallow.validate import Length, OneOf, Range
|
||||
|
@ -856,7 +856,16 @@ class MoveOnDocument(Action):
|
|||
if len(docs) > 1:
|
||||
txt = 'This document it is associated in more than one lot'
|
||||
raise ValidationError(txt)
|
||||
|
||||
if len(docs) < 1:
|
||||
txt = 'This document not exist'
|
||||
raise ValidationError(txt)
|
||||
data['container_to'] = docs[0].id
|
||||
|
||||
@post_load
|
||||
def adding_documents(self, data):
|
||||
"""Adding action in the 2 TradeDocuments"""
|
||||
docs = OrderedSet()
|
||||
docs.add(data['container_to'])
|
||||
docs.add(data['container_from'])
|
||||
data['documents'] = docs
|
||||
|
|
|
@ -101,9 +101,8 @@ class TradeDocument(Thing):
|
|||
revoke = 'Revoke'
|
||||
revoke_pending = 'Revoke Pending'
|
||||
confirm_revoke = 'Document Revoked'
|
||||
|
||||
if not self.actions:
|
||||
return
|
||||
return
|
||||
|
||||
ac = self.actions[-1]
|
||||
|
||||
|
@ -111,7 +110,7 @@ class TradeDocument(Thing):
|
|||
# can to do revoke_confirmed
|
||||
return confirm_revoke
|
||||
|
||||
if ac.type == 'RevokeDocument':
|
||||
if ac.type == 'RevokeDocument':
|
||||
if ac.user == g.user:
|
||||
# can todo revoke_pending
|
||||
return revoke_pending
|
||||
|
@ -131,9 +130,14 @@ class TradeDocument(Thing):
|
|||
# can to do revoke
|
||||
return double_confirm
|
||||
|
||||
def _warning_actions(self, actions):
|
||||
return sorted(ev for ev in actions if ev.severity >= Severity.Warning)
|
||||
@property
|
||||
def total_weight(self):
|
||||
"""Return all weight than this container have."""
|
||||
return sum([x.weight for x in self.actions if x.type == 'MoveOnDocument']) + self.weight
|
||||
|
||||
def _warning_actions(self, actions):
|
||||
"""Show warning actions"""
|
||||
return sorted(ev for ev in actions if ev.severity >= Severity.Warning)
|
||||
|
||||
def __lt__(self, other):
|
||||
return self.id < other.id
|
||||
|
|
|
@ -2478,11 +2478,13 @@ def test_moveOnDocument(user: UserClient, user2: UserClient):
|
|||
|
||||
user.post(res=models.Action, data=request_trade)
|
||||
|
||||
description = 'This is a good description'
|
||||
request_moveOn = {
|
||||
'type': 'MoveOnDocument',
|
||||
'weight': 15,
|
||||
'container_from': tradedocument_from['id'],
|
||||
'container_to': id_hash
|
||||
'container_to': id_hash,
|
||||
'description': description
|
||||
}
|
||||
doc, _ = user.post(res=models.Action, data=request_moveOn)
|
||||
|
||||
|
@ -2490,5 +2492,11 @@ def test_moveOnDocument(user: UserClient, user2: UserClient):
|
|||
assert doc['container_from']['id'] == tradedocument_from['id']
|
||||
assert doc['container_to']['id'] == tradedocument_to['id']
|
||||
|
||||
mvs= models.MoveOnDocument.query.filter().first()
|
||||
trade_from = TradeDocument.query.filter_by(id=tradedocument_from['id']).one()
|
||||
trade_to = TradeDocument.query.filter_by(id=tradedocument_to['id']).one()
|
||||
assert trade_from in mvs.documents
|
||||
assert trade_to in mvs.documents
|
||||
assert description == mvs.description
|
||||
tradedocument_to, _ = user.post(res=TradeDocument, data=request_post2)
|
||||
user.post(res=models.Action, data=request_moveOn, status=422)
|
||||
|
|
Reference in New Issue