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

I want to add new selection but every time I tried to change this message pop up Properties of base fields cannot be altered in this manner! Please modify them through Python code, preferably through a custom add-on!' unfortunately i have no idea how to use Python.


best regards 


Avatar
Discard
Author

Hello Nikhil Nakrani

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

Thanks and Best Regards


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...

Best Answer

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.

Avatar
Discard
Best Answer

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

Avatar
Discard
Best Answer

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

      

Avatar
Discard
Best Answer

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.

Avatar
Discard
Author

Hello Nikhil Nakrani

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

Thanks and Best Regards

Related Posts Replies Views Activity
2
Oct 23
3614
0
Jun 22
23
3
Sep 24
1087
0
Nov 23
989
2
Feb 23
1805