Set default discount_percentage on Sales Invoice Item

Hi

I have create a single doctype for setting a default discount value. I am trying to use this value to set the discount_percentage in a Sales Invoice items child table, like so …

It works okay, setting the value. But the it seems the callback in erpnext item_code event , here,


… gets triggered after my custom code has completed execution.

Since both the codes are executing asynchronously, sometimes the above code executes later. Is there any way that this custom code can always run after the erpnext event? … Instead of both being subjected to a race condition.

rgds