Hello im trying to build an esignature workflow using viewflow. Im doing so by linking my process model , to an esignature model where i keep the signatures by a foreign key. However , im facing this error.
Cannot assign "8": "ESignatureModel.paymentVoucherProcess" must be a "PaymentVoucherProcess" instance.
My flows.py
class Pipeline(Flow):
process_class = PaymentVoucherProcess
start = (
flow.Start(
CreateProcessView,
fields=["payment_code","bPBankAccount"]
).Permission(
auto_create=True
).Next(this.approve)
)
approve = (
flow.View(
Signature,
fields=["eSignatureModel"]
).Permission(
auto_create=True
).Next(this.check_approve)
)
check_approve = (
flow.If(lambda activation: activation.process.eSignatureModel)
.Then(this.send)
.Else(this.end)
)
send = (
flow.Handler(
this.send_hello_world_request
).Next(this.end)
)
end = flow.End()
def send_hello_world_request(self, activation):
print(activation.process.payment_code)
Here is my models.py
class PaymentVoucherProcess(Process):
payment_code = models.CharField(max_length=250,default='sup')
bPBankAccount = models.ForeignKey('BPBankAccount', on_delete=models.CASCADE)
drop_status = models.CharField(
null=True, max_length=3, default=None,
choices=(('SCF', 'Successful'),
('ERR', 'Unsuccessful'))
)
remarks = models.TextField(null=True)
class ESignatureModel(JSignatureFieldsMixin):
name = models.ForeignKey(User , on_delete=models.CASCADE)
paymentVoucherProcess = models.ForeignKey('PaymentVoucherProcess', on_delete=models.CASCADE)
Here is my external custom view i used to insert the esignature aspect into my workflow
@flow_view
def Signature(request):
form = SignatureForm(request.POST or None)
if form.is_valid():
esig = ESignatureModel()
signature = form.cleaned_data.get('signature')
if signature:
signature_picture = draw_signature(signature)
signature_file_path = draw_signature(signature, as_file=True)
pk = request.activation.process.pk
#attempting to assign the foreign key field error occurs here
esig.paymentVoucherProcess = pk
form.save()
request.activation.done()
return redirect(get_next_task_url(request, request.activation.process))
return render(request, 'cash/pipeline/jsig.html', {
'form': form,
'activation': request.activation
})
Do let me know if you spot any of my mistaks