As title say, I have model and I'm currently logged in database (so I don't think I should use external api) and I want to get data from a model, but I'm actually outside the scope of model class.
I know in some situations like post_init method we can access to environment and models like this:
def post_init(cr, registry):But here DB cursor is automatically passed to post_init method.
from odoo import api, SUPERUSER_ID
env = api.Environment(cr, SUPERUSER_ID, {})
env['ir.config_parameter'].init(force=True)
I think i could access model data with no problem if I have access to db cursor somehow, so maybe the question might be how do I access to db cursor ?
But I want to make it even more generic by asking: what is the best way to access data of a target model when you are logged in database, but not inheriting from model classes?
I'm also trying another way, with request.env but if I try something like this:
from odoo.http import request
r = request.env['model.name'].search([])
I am not getting any value, plus I get RuntimeError: object unbound in the log.
The only way I was able to make this work, was to setup a web controller with a specific route, but how can I make this work without setup a web controller, just a request.env?
I use Odoo15, btw.
If you are not using web controller [ request.env['model.name'].search([]) ] or inheriting a model class [ self.env['model.name'].search([]) ] of Odoo, Try directly accessing from db with query. Table inside the query will be model_name [ from model.name ].
While using query, be careful and make sure its secure.