Skip to Content
Menu
This question has been flagged
2 Replies
2288 Views

Hi,

I recently modified the account move tree view to enable mass editing, especially to give many invoices the same invoice date.

I have just added a multi-edit="1" to the account.invoice.tree


But when I edit the invoice date in the treeview, the invoice_due_date is not updated as it have to be.

When we enter in an invoice and update the invoice date, the invoice due date is change, based on an onchange function. 

I have added some loggers in this onchange function and this one is not triggered when I edit depends fields in the tree view.


Is there any trick to trigger the onchange function from the tree-view when I update a field ?


Thanks :)

Avatar
Discard

Updated my response after testing & investigating. Hope it helps !

Author Best Answer

Unfortunately doesn't work. Tried from the treeview, doesn't see any changes, but tried in the form view, and here's no change either (there was with the onchange)

Avatar
Discard

Can you provide a minimal example to reproduce your issue ?

Author

I've taken screenshots, but no possibilities to put them here, so let's go for a full text :)

-Go into a customer invoice in draft
-Edit the tree view to show invoice_date_due field, it's the field that appears on the report
-Set the payment terms to 30 days
-Change the invoice date.
Here you can see that the invoice date due change accroding to the invoice date and payment terms. If you set invoice date to 06/28/2022, invoice date due will be automatically 07/28/2022, that's the original flow from Odoo

Now, the custom edit
-Go to Accounting > Customers > Invoices
-Edit the tree view, and set multi-edit="1" as an attribute of the tree tag
-Now select the draft invoice, and change the invoice date directly from the tree view (possible with the multi-edit)
-Enter the draft invoice, and you can see that the invoice date is the same as the tree view, but the invoice date due is not the right one : that's because the onchange that take care of this field was not triggered.

And, as you said, I tried to change onchange by depends, but with that, even the original flow doesn't work

Tested it locally and the invoice due date doesn't change when terms are set, no difference between single and mass editing.
I guess I'd need to know the version you're running, whether it's community or enterprise, the modules you installed.

Author

I'm runnig odoo 14 enterprise on odoo.sh. Made some custom code, but it doesn't change the invoicing dates.
In your tests, invoice date due never change ?

@Thomas hi again
Had some time to try it out. Looks like the onchange method does trigger as it should, but the conditions just don't make the invoice_date_due field change when the payment term is set instead.
That seems to be the, if not original, standard flow of odoo.
So back to the issue about onchange/depends not triggering from the multi_edit="1" tree view... You seem to be right, I'll ask around see why that is ¯\_(ツ)_/¯

Best Answer

Hi Thomas,

Consider using the @api.depends decorator as it is triggered by any change to that field, while the @api.onchange only triggers when a form containing the field changes that field.

Here's a related Forum thread
Here's a related SO question
Here's the related Odoo docs

EDIT: 

@api.onchange('field_A')
- Triggers: when the value of field_A changes in the view
- Conditions to meet: both fields are present in the current view

@api.depends('field_A')
- Triggers: when the value of field_A changes in the database (therefore, never if store=False)
- Conditions to meet: both fields are present in the current view AND field_A has been declared with compute=my_function

Tested those with multi_edit list views and it works :)

If you want to trigger on a field change but do not meet those conditions, you can try overriding the write method.

Avatar
Discard
Author

Hi Stanisles,

Tried what you said, with the onchange :
-In the invoices tree, there's my two fields : invoice_date, the one I want to change, and invoice_date_due, the one that have to be changed automatically with the onchange function

When I try to change the first field, I see in logs that the onchange is not called. There's only the write method.
When I change it in form view, the onchange method is correctly called.

So I tried to modified the write to call the onchange function before returning super, but it show me wrong date on the second field. There's so many calls in that onchange function, I can't rewrite it in the write method.

You said you've tested it and works for you. You've juste add multi-edit in the invoices tree (account.view_invoice_tree) ?

Thanks :)