Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to get value from DB in constructor?

By
Andrew
on 10/27/16, 9:09 AM 123 views

Normally I use this example of code to get record id:

@api.onchange('selector') def some(self):
        order_object = self.env['ir.ui.menu'] order_object_ids = order_object.search([('sequence', '=', 10)]) if order_object_ids:
            for obj in order_object_ids:
                 print obj.id       
But when I try to use constructor to get values, I receiving error:

AttributeError: 'ir.ui.menu' object has no attribute 'id' 

This is my constructor

def __init__(self, *args, **kwargs):
        registry = registry_get('main-db')
        r = modules.registry.RegistryManager.get('main-db')
        cr = r.cursor() with api.Environment.manage():
        env = api.Environment(cr, 1, {})
        obj = env['ir.ui.menu'].browse(161)
        print obj.id
        super(HumanResourcesBase, self).__init__(*args, **kwargs)


Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 10/27/16, 9:09 AM
Seen: 123 times
Last updated: 10/27/16, 10:13 AM