Odooers论坛

欢迎!

该社区面向专业人士和我们产品和服务的爱好者。
分享和讨论最好的内容和新的营销理念,建立您的专业形象,一起成为更好的营销人员。


0

How to change the contact company_type base field?

2 注释
形象
丢弃
形象
odoo
-

Hello Nikhil Nakrani

How do i get acces to the odoo Xml? do i need full admin rights?

Thanks and Best Regards


形象
odoo
-

Guys, as Ray Carnes already explained is really not recommended to chage this logic (note: is possible indeed, is just not recommended). 

If you do it you need to think that you may face several issue, not only to implementing it, but also at mantaining cause many other modules rely on this logic.

Personally I don't like the way it has been implemented, as extending this it's usually a common request. But it is what it is...

4 答案
0
形象
odoo
最佳答案

We don't recommend doing this.

1. This cannot be done without modifying the Odoo source code via your own module which inherits and overrides the Odoo module where this is defined. This is only something a developer can do.

2. This is a very fundamental part of Odoo and many other parts of the system rely on only having two options in this field. To implement another option would require a very advanced understanding of how the Odoo framework uses this field and a comprehensive search of the codebase to also modify every other place this field is referenced.

You should find another way to implement what you need - like using your own field or using tags.

形象
丢弃
0
形象
odoo
最佳答案

thanks but

  company_type = fields.Selection(string='Company Type',

         selection=[('person', 'Individual'), ('company', 'Company'),('external', 'Foreign')],

         compute='_compute_company_type', inverse='_write_company_type')

After adding the new value, if I select it it returns me to person

I think it's because of the method

_compute_company_type


Do you know how to prevent that from happening? I'm with odoo15

形象
丢弃
0
形象
odoo
最佳答案

this is my workaround for this, I added  new a field is_organisme :

    company_type = fields.Selection(string='Company Type',
        selection=[('person', 'Individual'), ('company', 'Company'),('organisme', 'Organisme')],default='company',
        compute='_compute_company_type', inverse='_write_company_type')
    is_organisme = fields.Boolean(string='Organisme', default=False,
        help="Check if the contact is an Organism, otherwise it is a company or a persone")

    @api.depends('is_company')

    def _compute_company_type(self):

        for partner in self:

            if partner.is_organisme and not partner.is_company:

                partner.company_type = 'organisme'

            elif partner.is_company and not partner.is_organisme:

                partner.company_type = 'company'

            else:

                partner.company_type = 'person'

    def _write_company_type(self):

        for partner in self:

            if self.company_type == 'company':

                self.is_company = True

                self.is_organisme = False

            if self.company_type == 'person':

                self.is_company = False

                self.is_organisme = False

            if self.company_type == 'organisme':

                self.is_company = False

                self.is_organisme = True

    @api.onchange('company_type')

    def onchange_company_type(self):

  if self.company_type == 'company':

            self.is_company = True

            self.is_organisme = False

        if self.company_type == 'person':

            self.is_company = False

            self.is_organisme = False

        if self.company_type == 'organisme':

            self.is_company = False

            self.is_organisme = True

      

形象
丢弃
0
形象
odoo
最佳答案

Hi Severin Caplazi,

  1. First in your odoo addons find this field.

   2. create your custom_module in odoo and inside model.

   3. inherit res.partner model like this way,

  4. Then add below you modify field like this way.

here i add one (key, value) new as (test, Testing) you can add multiple here.

 5. Add this file in your init.py 

Thanks.

1 备注
形象
丢弃
形象
odoo
-

Hello Nikhil Nakrani

How do i get acces to the odoo Xml? do i need full admin rights?

Thanks and Best Regards