How to initiate a step back with editting functionality in viewflow

121 Views Asked by At

I'm currently trying to recreate this flow:

enter image description here

So far, my flow only goes in 1 direction, there is no option for going back a step back, let's say Person 'b' spots a mistake keyed in by person 'a', I wish to be able to allow person 'b' to send the task back to person 'a' so that they can 'edit' their entry. However, there doesn't seem to be an 'editing' function in view flow, is there a reason for this?

flows.py

class Pipeline(Flow):
    process_class = PaymentVoucherProcess
    lock_impl = lock.select_for_update_lock
    #process starts here
    start = flow.Start(
        PVStartView,
        task_title="Processing New Voucher"
    ).Permission("cash.can_start_voucher"
    ).Next(this.approve_by_preparer)
    
    #preparer will approve
    approve_by_preparer = flow.View(
        UpdateProcessView,
        form_class=PreparerApproveForm,
        task_title="Approval By Preparer"
    ).Assign(lambda act: act.process.assign_preparer
    ).Permission("cash.preparer"
    ).Next(this.documents)

    #preparer will upload supporting documents
    documents = flow.View(
        UploadView,
        task_title="Recieving Supporting Documents"
    ).Assign(lambda act: act.process.assign_preparer
    ).Permission("cash.preparer"
    ).Next(this.preparer)

    #preparer will sign
    preparer = flow.View(
        PreparerSignature,
        task_title="Signature By Preparer"
    ).Assign(lambda act: act.process.assign_preparer
    ).Permission("cash.preparer"
    ).Next(this.approve_by_verifier)

    #system check point
    check_treasury = flow.If(
        cond=lambda act: act.process.preparer,
        task_title="Processing",
    ).Then(this.approve_by_verifier).Else(this.end)

    #verifier will sign
    approve_by_verifier = flow.View(
        UpdateProcessView,
        form_class=VerifierApproveForm,
        task_title="Approval By Verifier"
    ).Assign(lambda act: act.process.assign_verifier
    ).Permission("cash.verifier"
    ).Next(this.verifier)
    #there is more but not relevant 

I understand that there are some 'undo' mixin views but I'm not sure how it is being implemented in my case and how everything is orchestrated, please help!

2

There are 2 best solutions below

0
On

Undo task flow is part of admin functionality, and not desined to be used by usual cases. If you need to edit a process data by user a, you could simple create edit task for user a

check = flow.If().Then(...).Else(this.edit_by_a)

edit_by_a = flow.View().Assign(this.start.owner).Next(this.check)
1
On

I still have no clue on how to properly do this. But here is what i did for the meantime :

flows.py

class Pipeline(Flow):
process_class = PaymentVoucherProcess
lock_impl = lock.select_for_update_lock
#process starts here
start = flow.Start(
    PVStartView,
    task_title="Processing New Voucher"
).Permission("cash.can_start_voucher"
).Next(this.approve_by_preparer)

#preparer will approve
approve_by_preparer = flow.View(
    UpdateProcessView,
    form_class=PreparerApproveForm,
    task_title="Approval By Preparer"
).Assign(lambda act: act.process.assign_preparer
).Permission("cash.preparer"
).Next(this.check_preparer)

#system check point
check_preparer = flow.If(
    cond=lambda act: act.process.preparer,
    task_title="Processing",
).Then(this.documents).Else(this.roll_back)

roll_back = flow.Handler(this.roll_back_call).Next(this.approve_by_preparer)

#preparer will upload supporting documents
documents = flow.View(
    UploadView,
    task_title="Recieving Supporting Documents"
).Assign(lambda act: act.process.assign_preparer
).Permission("cash.preparer"
).Next(this.preparer)

#preparer will sign
preparer = flow.View(
    PreparerSignature,
    task_title="Signature By Preparer"
).Assign(lambda act: act.process.assign_preparer
).Permission("cash.preparer"
).Next(this.approve_by_verifier)

#verifier will sign
approve_by_verifier = flow.View(
    UpdateProcessView,
    form_class=VerifierApproveForm,
    task_title="Approval By Verifier"
).Assign(lambda act: act.process.assign_verifier
).Permission("cash.verifier"
).Next(this.check_verifier)

#system check point
check_verifier = flow.If(
    cond=lambda act: act.process.verifier,
    task_title="Processing"
).Then(this.verifier).Else(this.roll_back)
#bunch of code here and inbetween


end = flow.End()

def roll_back_call(self, activation):
    esig = ESignatures.objects.filter(paymentVoucherProcess = activation.process).filter(voided = False)
    docu = Attachment.objects.filter(paymentVoucherProcess = activation.process).filter(voided = False)
    if len(esig) > 0 :
        for sig in esig:
            sig.voided = True
            sig.save()
    if len(docu) > 0 :
        for doc in docu:
            doc.voided = True
            doc.save()
    activation.process.preparer = False
    activation.process.verifier = False
    activation.process.treasury = False
    activation.process.director = False

Basically what is happening in this Roll back handler is that when the program figures out that Person 'B' disapproves , it will run the roll_back code which searches for the process and 'refreshes' it , marking all foreign relations to void and removing all prior approvals. It is really super unorthodox and hacky , but for the meantime it works , please let me know you guys comments and do share with me your answers.

I still havent figured out how exactly one can 'edit' or 'cancel' or 'reassign' his tasks , the documentations don't have much and im really surprised people don't face such issues as there is a severe lack of content out there . Anyways i hope to see some constructive feed back!