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,15 +552,9 @@ class ConfirmDocument(ActionWithMultipleDocuments):
if not doc.actions: if not doc.actions:
continue continue
ac = doc.actions[-1] if not doc.trading == 'Need Confirmation':
txt = 'No there are documents to confirm'
if ac.t == 'ConfirmDocument' and not ac.user == g.user: raise ValidationError(txt)
# 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'
raise ValidationError(txt)
class RevokeDocument(ActionWithMultipleDocuments): class RevokeDocument(ActionWithMultipleDocuments):
@ -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,14 +580,9 @@ 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']:
txt = 'No there are documents to revoke'
if ac.t == 'ConfirmDocument' and ac.user == g.user: raise ValidationError(txt)
documents.append(doc)
if not documents:
txt = 'No there are documents to revoke'
raise ValidationError(txt)
class ConfirmRevokeDocument(ActionWithMultipleDocuments): class ConfirmRevokeDocument(ActionWithMultipleDocuments):
@ -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,17 +605,12 @@ 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 txt = 'No there are documents with revoke for confirm'
# and revoke is an action of one other user raise ValidationError(txt)
data['action'] = ac
documents.append(doc)
if not documents: data['action'] = doc.actions[-1]
txt = 'No there are documents with revoke for confirm'
raise ValidationError(txt)
class ConfirmRevoke(ActionWithMultipleDevices): class ConfirmRevoke(ActionWithMultipleDevices):

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)