I have a standar viewflow flow process, in one of the states id want to split my proccess based on the text value that is introduced in one of the fields. I have defined my field of interest this way in models.py
estado_de_aprobacion= models.CharField(max_length=15, choices=REVIEW_CHOICES)
my choices:
REVIEW_CHOICES = (
('APROBACION_FINAL', 'Aprobar definitivamente'),
('APROBACION_NUEVO_REVISOR', 'Enviar a otro revisor'),
('DEVOLVER_EJECUTOR','Devolver al ejecutor')
)
so basically what happens is that a drop list is displayed so the user can choose one of the options, and based on that I appliy the followinf split in the flow:
split =(
#If(lambda activation: activation.process.aprobacion_final)
flow.Switch()
.Case(this.end, cond=((lambda act: act.process.estado_de_aprobacion)=='APROBACION_FINAL'))
.Case(this.revisor_check, cond=((lambda act: act.process.estado_de_aprobacion)=='APROBACION_NUEVO_REVISOR'))
.Case(this.ejecutar, cond=((lambda act: act.process.estado_de_aprobacion)=='DEVOLVER_EJECUTOR'))
)
I assume that the lamba expression returns the value contained in the specified proccess atributes but since the comparisson isn't working im thinking its wrong.
Let's unpack what is going on in the cond
value.
cond=((lambda act: act.process.estado_de_aprobacion)=='APROBACION_FINAL')
(lambda act: act.process.estado_de_aprobacion)
returns a function which extracts the relevant field from act
.
Then you are comparing this to =='APROBACION_FINAL'
, which is always going to fail because you are comparing a lambda function and a string.
So the actual value of cond
being passed to the function is False
.
I assume cond
need to be a function that returns true or false? In which case you should do the comparison in the lambda function.
cond=lambda act: act.process.estado_de_aprobacion=='APROBACION_FINAL'
The extract parentheses in the original code are unnecessary, and are in fact probably the source of the problem.