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

[odoo:9] : 'getting Attribute Error: Environment' when calling method from thread,why?

By
Prince Caspion
on 7/15/16, 1:30 AM 363 views

Hello All,

What is the missing thing?

I got  AttributeError: environments error, while using thread.

Here is the sample code of my method

class test_class(models.TransientModel):

def main_method
#Code of method

    @api.one
    def test_thread(self):
 
        thread_var = threading.Thread(target=self.main_method)
        thread_var.start()
        

The method which is called from thread that the method of Transient Model

Regards,

Prince.

0
Dilip Dabhi
On 7/15/16, 3:42 AM

It is working well at my side, please will you try as below

***********************************************

import threading

class test_wizard(models.TransientModel):

_name = 'test.wizard'

def main_method(self):

#Code of method

print "done"

return True

@api.one

def test_thread(self):

thread_var = threading.Thread(target=self.main_method)

thread_var.start()

class test_module(models.Model):

_name = 'test.module'

@api.multi

def test(self):

mod_obj = self.pool.get('ir.model.data')

res_id = mod_obj.get_object_reference(self._cr, self._uid, 'test_module', 'view_test_wizard_form')

return {

'name':_("Test Wizard"),

'type': 'ir.actions.act_window',

'res_model': 'test.wizard',

'view_mode': 'form',

'view_type': 'form',

'view_id': res_id[1],

# 'res_id': res_id[1],

'nodestroy': True,

'target': 'new',

# 'domain': '[]',

# 'context': dict(context, active_ids=ids)

}

************************

<record id="view_test_wizard_form" model="ir.ui.view">

    <field name="name">test.wizard</field>

        <field name="model">test.wizard</field>

        <field name="arch" type="xml">

            <form string="Test wizard">

                <button name="test_thread" type="object" class="oe_highlight" string="Test"/>

            </form>

    </field>

</record>

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: 7/15/16, 1:30 AM
Seen: 363 times
Last updated: 7/15/16, 3:42 AM