Search code examples
javascriptpythonodooodoo-12

Odoo 12: How to use form values in @api.model methods


I am new in the forum.
I am currently working with Odoo 12 and I'm having some problems communicating Odoo Model with my Javascript Widget. Step by step...
1. I am creating a widget that shows some Google Charts and the only way I've found was to show the QWeb code in a custom view and assign the Widget to a Char field.
2. I've achieved a nice approach using rpc in my start: function using rpc and getting the data from the module.
3. THE PROBLEM:
I need to show two Date fields in the form and use that dates as an interval for my Google Charts: How can I get the date values in my @api.model
function??
The function can only read a resultset of all the table, when I try to get the result (self.init_date) set in the field, I always receive "False"
Sorry, I can't post the code today, but on Monday I will post it if nobody can give me the answer.
Thank you very much!


Solution

  • The api.model decorator gives you access to the model's methods but not to the records, so they can be called when the model has no records (See https://www.odoo.com/documentation/12.0/reference/orm.html#module-odoo.api).

    If the method you wrote is intended to always receive a record, just remove the api.model decorator.