For example, in Sales Invoice List, I want to filter only docs that “Outstanding Amount” < “Total Amount”.
I think, filter now only can compare a field with a value, i.e., Out Standing Amount > 0.
But to compare 2 fields, seem super tricky to me. Only way I can think of is to create and compute a new field, i.e., “Partly Paid” = [1, 0] and use filter on this field. Super complicated for a simple task.
We have to admit that it won’t be that clean and easy to do things in the low code way although I am ok/not ok with adding new custom_partly_paid field. As in many area, Frappe use doc.db_set() any bypass all the event hooks.
In this case, I want to hook to Sales Invoice to set value,
But the doc.db_set() in set_status() don’t trigger hook.
Frankly, it is quite annoying.
The only way I can see is to write python code in a custom app using class extension to the set_status().
Another way is to write a scheduled job to keep updating (which is CPU intensive and not real time).
May be server script doc event should have one for db_set() too, WDYT about this?
Firstly, the virtual field is not good here, becasue it can’t be used as filter or display in the list view.
Says, I have Sales Invoice 100 USD, and submitted.
Then, I make payment partially 30 USD, and submit the payment, now, the sales invoice’s set_status() as I linked to the github will be called (when submit Payment).
There, on set_status(), I want server script to trigger on sales invoice but it won’t happen because set_status() is not using save() method, but use db_set().
Ah, I see what you’re saying. Yes, since the status field is a derived value, changes aren’t triggering event hooks. If you want to catch changes to the outstanding balance of a Sales Invoice, your best bet would be to catch the thing making the change (i.e., watch for changes to GL Entry or Payment Entry docs).