Does anyone know how to obtain the current record in a Python method which is called from JavaScript code?
Let's put an example:
I have my Python method:
@api.multi
def my_method(self):
_logger.info(self)
To call that method from my JS code, I have to do the following:
var MyModel = new Model('my.model');
MyModel.call(
'my_method', [current_id],
)
And because of this I need to get the current ID from JavaScript. So, before calling the method, I store the current ID in a JS variable this way:
var current_id = this.field_manager.datarecord.id
It works OK. But only when the record has already an ID. If the current record is currently being created, this.field_manager.datarecord.id returns null, and the method call fails.
What I would like is to know how to call that method even when the record has not an ID yet. For example, onchange decorator allows you to work in Python with records with are not stored in the database and therefore have not an ID yet.
Any ideas?