Skip to Content
Menu
This question has been flagged
4 Replies
12363 Views

Hi,

I want to use this inside a class model.TransientModel and this works fine with Odoo 8, but in 11 does not, it says that a arg is missing.

Can anyone help me to solve this ?

def _default_company(self):
     """Return user company our first found"""
     user = self.pool.get('res.users').browse(self._cr, self._uid, self._uid)
     if user.company_id:
        return user.company_id.id
    return self.pool.get('res.company').search([('parent_id', '=', False)])[0]

company_id = fields.Many2one(comodel_name="res.company", string="Companhia", required=True, default=_default_company, )


Thanks in advance,

Paulo

Avatar
Discard
Author

Can you explain in more detail what you mean with access to themeDisplay ?

I have a form definition that will use a many2one field called company_id, for the user to select from a combobox the name of the company if his using multi-company configuration.

in the python side I have class that is associated with this form, defined as models.TransientModel, since it's a temporary table.

So in this class I'm defining the field company_id, that is a Many2one field, they way I wrote before.

This addon was made for odoo 8, and fully working, so in this process of adaptation, I'm finding some issues as expected, and this one in particular, i bypassed it until now this way:

def _default_company(self):

"""Return user company id"""

company = self.company_id

return company

Thanks

Best Answer

Hello Paulo,

You can write as following to set default company_id: 

company_id = fields.Many2one('res.company', string='Company',  required=True,
default=lambda self: self.env['res.company']._company_default_get('account.invoice'))

Thanks,

Avatar
Discard
Best Answer

If you don't have access to themeDisplay, you might want to give a few more details on where you actually need access to this information.

Avatar
Discard
Author Best Answer

Can you explain in more detail what you mean with access to themeDisplay ?

I have a form definition that will use a many2one field called company_id, for the user to select from a combobox the name of the company if his using multi-company configuration.

in the python side I have class that is associated with this form, defined as models.TransientModel, since it's a temporary table.

So in this class I'm defining the field company_id, that is a Many2one field, they way I wrote before.

This addon was made for odoo 8, and fully working, so in this process of adaptation, I'm finding some issues as expected, and this one in particular, i bypassed it until now this way:

def _default_company(self):
"""Return user company id"""
company = self.company_id
return company

Thanks

Avatar
Discard