0

I am trying to adapt the Viewflow Dynamicsplit example

The objective is to split approvals of an Order based on OrderLines and to assign them to the appropriate approver. It seems that this should be possible as there seems to be a possibility described in this answer - Assign user to tasks automatically (Viewflow, Django)

The issue is that whenever I try to grab the current order pk in the DynamicSplitActivation - the queryset comes back empty. Not sure where I am going wrong. The queryset works fine if I set the pk manually, but as soon as I try to use a dynamic variable it stops working.

I have listed the flow and models etc. at the end of the post, however, I am guessing the issue is quite basic. Any help would be appreciated!

nodes.py

...

class DynamicSplitActivation(AbstractGateActivation):
    def calculate_next(self):
        self._order = self.flow_task._order_callback(self.process)

        order_id = self._order.pk
#        order_id = 28
        order_lines = models.OrderLine.objects.filter(order_id=order_id)
        project_lines = project_models.ProjectLine.objects.filter(orderline__in=order_lines)
        users = User.objects.filter(projectline__in=project_lines).distinct()

        self._approvers = users
...

class DynamicSplit(...):
...

    def __init__(self, callback):
        super(DynamicSplit, self).__init__()
        self._order_callback = callback
        self._ifnone_next_node = None

...

flows.py

...

    approval_split = (
        nodes.DynamicSplit(lambda act: act.order)
        .IfNone(this.end)
        .Next(this.split_approval_budget)
    )

models.py

...

class ProjectLine(models.Model):
    project = models.ForeignKey(Project, on_delete=models.CASCADE)
    description = models.CharField(max_length=50)
    budget_holder = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.SET_NULL, null=True, blank=True)

class Order(models.Model):
    description = models.CharField(max_length=30)

class OrderLine(models.Model):
    order = models.ForeignKey(Order, on_delete=models.CASCADE)
    project_line = models.ForeignKey(project_models.ProjectLine, on_delete=models.SET_NULL, null=True, blank=False)
    product = models.ForeignKey(catalogue_models.Product, on_delete=models.CASCADE)
    quantity = models.PositiveIntegerField()

    budgetholder_approved = models.BooleanField(null=True)

class OrderProccess(Process):
    order = models.ForeignKey(Order, blank=True, null=True, on_delete=models.CASCADE)

...
dj.bettega
  • 117
  • 1
  • 1
  • 11
  • So I am an idiot. The reason why this is not working is because at this stage in the workflow the record has not yet been saved so the query is coming back empty because it has not been created yet. – dj.bettega Dec 04 '22 at 06:00

0 Answers0