تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
4 الردود
13206 أدوات العرض

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

الصورة الرمزية
إهمال
الكاتب

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

أفضل إجابة

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,

الصورة الرمزية
إهمال
أفضل إجابة

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.

الصورة الرمزية
إهمال
الكاتب أفضل إجابة

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

الصورة الرمزية
إهمال