Se rendre au contenu
Menu
Cette question a été signalée
3 Réponses
227 Vues

hello dear community 

want to ask u i created a field selection and i put values but i want to give to the user the permission so he can add values and select one of them is it possible and if it yes can please someone explain how 

Avatar
Ignorer

Hello jihane,

Can you tell me is the user is internal user type or portal and also where you want the user to select the field on odoo basic erp view or on website?

Meilleure réponse

Replace fields.Selection with a Many2one field pointing to a new model.

Here’s how:

🔧 Step 1: Create a new model to store the options

python

CopyEdit

from odoo import models, fields class CustomOption(models.Model): _name = 'your.model.option' _description = 'Selectable Options' name = fields.Char(string="Option", required=True)

✏️ Step 2: Replace your Selection field with a Many2one field

In your main model:

python

CopyEdit

from odoo import models, fields class YourModel(models.Model): _name = 'your.model' option_id = fields.Many2one('your.model.option', string="Option")

🧑‍💻 Step 3: Enable adding new options from the dropdown

In the form view XML:

xml

CopyEdit

<field name="option_id" options="{'no_create': False}" context="{'default_name': 'New Option'}"/>

This allows the user to:

  • Select an existing option
  • Create a new one directly from the dropdown

✅ Done!

Now users can add and choose options freely, just like a dynamic selection list.

Let me know if you want to restrict who can add options with access rights!

Avatar
Ignorer
Meilleure réponse

Hello Jihane

Users cant add a value to the selection field as its modified only using python code
However you can implement the same thing by Creating a new model and instead of using a selection field you can use a Many2one field and then give users access to this new model so they can add values

Hope this helps

Avatar
Ignorer
Meilleure réponse

Hi,

Step 1: Create a New Model for Selection Options


Create .py file


from odoo import models, fields


class CustomSelectionOption(models.Model):

    _name = 'custom.selection.option'

    _description = 'Editable Selection Options'

    _order = 'name asc'  # Sort alphabetically


    name = fields.Char('Option Value', required=True)

    active = fields.Boolean('Active', default=True)


Step 2: Add Many2one Field to Your Main Model


Create .py file


class YourModel(models.Model):

    _inherit = 'your.model'  # e.g., sale.order, product.template


    custom_selection = fields.Many2one(

        'custom.selection.option',

        string='Custom Selection',

        help="Select or create new options"

    )


Step 3: Set Up Security Permissions


Create security/ir.model.access.csv:


id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink

access_custom_selection,custom.selection.access,model_custom_selection_option,base.group_user,1,1,1,0


Hope it helps

Avatar
Ignorer