Odoo Help


Developing new module: "env" is not defined

on 2/5/16, 4:49 PM 1,553 views

I am trying to do this:

moves = env['stock.move'].search([('picking_id','==',current_stock_picking)])

Inside a controller, but I am getting global variable "env" is not defined. I also tried to define it via:

    env = Env(cr, uid, context)

But then I get global variable "Env" is not defined.

What is missing? Thanks.

I include full controller code:

class Binary(http.Controller):
@http.route('/web/binary/item_labels', type='http', auth="user")
def download_item_labels(self, id, **kw):

            Model = request.registry['stock.picking']
            cr, uid, context = request.cr, request.uid, request.context
            fields = [ 'id' ]
            current_stock_picking = Model.read(cr, uid, [int(id)], fields, context)[0]['id']
            print "current_stock_picking"
            print current_stock_picking

            env = Env(cr, uid, context)
            moves = env['stock.move'].search([('picking_id','==',current_stock_picking)])
            print "moves"
            print moves


Axel Mendoza

--Axel Mendoza--
| 7 8 8
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full-time employee trying to understand what to do and how

Reach me at aekroft@gmail.com

Axel Mendoza
On 2/5/16, 6:24 PM

Make sure that you have imported the class Environment correctly. For example for your code works ok you just need to add this line at the top of the file

from openerp.api import Environment as Env

Thanks Axel,

on 2/5/16, 6:58 PM

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 2/5/16, 4:49 PM
Seen: 1553 times
Last updated: 2/5/16, 6:58 PM