clean views of trade documents

This commit is contained in:
Cayo Puigdefabregas 2021-06-29 19:13:00 +02:00
parent c8b0c56bbb
commit b7e652906e
2 changed files with 12 additions and 30 deletions

View File

@ -543,7 +543,6 @@ class ConfirmDocument(ActionWithMultipleDocuments):
if data['documents'] == OrderedSet(): if data['documents'] == OrderedSet():
return return
documents = []
for doc in data['documents']: for doc in data['documents']:
if not doc.lot.trade: if not doc.lot.trade:
return return
@ -553,13 +552,7 @@ class ConfirmDocument(ActionWithMultipleDocuments):
if not doc.actions: if not doc.actions:
continue continue
ac = doc.actions[-1] if not doc.trading == 'Need Confirmation':
if ac.t == 'ConfirmDocument' and not ac.user == g.user:
# If document is confirmed but is not for g.user, then need confirm
documents.append(doc)
if not documents:
txt = 'No there are documents to confirm' txt = 'No there are documents to confirm'
raise ValidationError(txt) raise ValidationError(txt)
@ -574,10 +567,10 @@ class RevokeDocument(ActionWithMultipleDocuments):
This is not checked in the view becouse the list of documents is inmutable This is not checked in the view becouse the list of documents is inmutable
""" """
# import pdb; pdb.set_trace()
if data['documents'] == OrderedSet(): if data['documents'] == OrderedSet():
return return
documents = []
for doc in data['documents']: for doc in data['documents']:
if not doc.lot.trade: if not doc.lot.trade:
return return
@ -587,12 +580,7 @@ class RevokeDocument(ActionWithMultipleDocuments):
if not doc.actions: if not doc.actions:
continue continue
ac = doc.actions[-1] if not doc.trading in ['Document Confirmed', 'Confirm']:
if ac.t == 'ConfirmDocument' and ac.user == g.user:
documents.append(doc)
if not documents:
txt = 'No there are documents to revoke' txt = 'No there are documents to revoke'
raise ValidationError(txt) raise ValidationError(txt)
@ -610,7 +598,6 @@ class ConfirmRevokeDocument(ActionWithMultipleDocuments):
if data['documents'] == OrderedSet(): if data['documents'] == OrderedSet():
return return
documents = []
for doc in data['documents']: for doc in data['documents']:
if not doc.lot.trade: if not doc.lot.trade:
return return
@ -618,18 +605,13 @@ class ConfirmRevokeDocument(ActionWithMultipleDocuments):
if not doc.actions: if not doc.actions:
continue continue
ac = doc.actions[-1]
if ac.t == 'RevokeDocument' and not ac.user == g.user: if not doc.trading == 'Revoke':
# If document is revoke before you can Confirm now
# and revoke is an action of one other user
data['action'] = ac
documents.append(doc)
if not documents:
txt = 'No there are documents with revoke for confirm' txt = 'No there are documents with revoke for confirm'
raise ValidationError(txt) raise ValidationError(txt)
data['action'] = doc.actions[-1]
class ConfirmRevoke(ActionWithMultipleDevices): class ConfirmRevoke(ActionWithMultipleDevices):
__doc__ = m.ConfirmRevoke.__doc__ __doc__ = m.ConfirmRevoke.__doc__

View File

@ -58,7 +58,7 @@ class TradeView():
db.session.add(confirm_devs) db.session.add(confirm_devs)
if self.trade.documents: if self.trade.documents:
confirm_docs = Confirm(user=g.user, confirm_docs = ConfirmDocument(user=g.user,
action=self.trade, action=self.trade,
documents=self.trade.documents) documents=self.trade.documents)
db.session.add(confirm_docs) db.session.add(confirm_docs)