İçereği Atla
Menü
Bu soru işaretlendi
4 Cevaplar
13205 Görünümler

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
Vazgeç
Üretici

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

En İyi Yanıt

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
Vazgeç
En İyi Yanıt

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
Vazgeç
Üretici En İyi Yanıt

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
Vazgeç