Reputation: 5495
I am trying to define a method @api.model
:
@api.model
def test(param1, param2):
print model.env['product.template'].search([("company_id", "=", param1), ("warehouse_id", "=", param2), ])
Question is, official documentation states that you can use model.env
but when I try to do it I get:
NameError: global name 'model' is not defined
which is the right import
to use to get model
available?
Upvotes: 0
Views: 559
Reputation: 2633
What is meant by model
is that you need a model object (empty recordset) to be able to access env
. In the new API, self
will be a recordset, so you can access the environment via self.env
:
@api.model
def test(self, param1, param2):
print self.env['product.template'].search([("company_id", "=", param1), ("warehouse_id", "=", param2), ])
Note that the method should be defined on a model class (in your snippet, the test
method signature is missing self
parameter).
On a related note, the link you have provided is not from the official documentation and is outdated - it was written in the period of initial migration from the old API to the new API between OpenERP 7.0 and Odoo 8.0, so it is not the best source. I would suggest to refer to the offical documentation available on Odoo.com.
Upvotes: 2