Hello, I am working with Odoo 16, and I was wondering if there is a way to update the entire web page, or to reload just the form view, when a field in the form changes (in my specific case, a Many2one field called "bank").
I'm asking this because I have a "documents" One2many field, in the same form where "bank" is, that automatically updates when "bank" changes.
In the Python method, decorated with @api.onchange('bank'), there are instructions that create documents in the database based on the selected bank.
The issue is that if I change "bank", after manually adding a document, the new documents created by the function are not displayed until I save the form or reload the page.
I tried using JavaScript, writing the following snippet:
odoo.define('my_crm.reload_on_bank_change', function (require) {
"use strict";
var FormController = require('web.FormController');
FormController.include({
_onFieldChanged: function (record, changes) {
if ('bank' in changes) {
// Reload the page if the "bank" field has changed
location.reload(true);
}
},
});
});
And also Python, using @api.onchange('bank') on my method and making it return the following:
return { 'type': 'ir.actions.client', 'tag': 'reload', }
I have searched everywhere online and in the documentation, but I haven't been able to find a solution, and unfortunately, the above methods didn't work.
Thanks to anyone who will answer.