Se rendre au contenu
Menu
Cette question a été signalée
1 Répondre
1552 Vues

I am working with odoo 16.


I want to force my selection fields to be with one of the value that i have already populated it with. 

I have tried to do it as another article was showing as 

self.my_selection_fields = 'MyValueAlreadyInMyField"


but when i do that i get the following error :

UncaughtPromiseError > OwlError
Promesse non interceptée > An error occured in the owl lifecycle (see this Error's "cause" property)
OwlError: An error occured in the owl lifecycle (see this Error's "cause" property)
    OwlError@http://localhost:8069/web/assets/1516-9251e20/web.assets_common.min.js:1240:1
    handleError@http://localhost:8069/web/assets/1516-9251e20/web.assets_common.min.js:1472:101
    handleError@http://localhost:8069/web/assets/1516-9251e20/web.assets_common.min.js:2099:29
    _render@http://localhost:8069/web/assets/1516-9251e20/web.assets_common.min.js:1497:19
    render@http://localhost:8069/web/assets/1516-9251e20/web.assets_common.min.js:1495:6
    initiateRender@http://localhost:8069/web/assets/1516-9251e20/web.assets_common.min.js:1563:47

Caused by: TypeError: this.options.find(...) is undefined
    get string@http://localhost:8069/web/assets/1517-50327a3/web.assets_backend.min.js:3670:161
    template@http://localhost:8069/web/assets/1516-9251e20/web.assets_common.min.js line 2057 > Function:15:18
    _render@http://localhost:8069/web/assets/1516-9251e20/web.assets_common.min.js:1496:96
    render@http://localhost:8069/web/assets/1516-9251e20/web.assets_common.min.js:1495:6
    initiateRender@http://localhost:8069/web/assets/1516-9251e20/web.assets_common.min.js:1563:47

(The anwsers is 7 years old so maybe something has changed https://www.odoo.com/fr_FR/forum/aide-1/change-the-value-of-a-fields-selection-102419)

Avatar
Ignorer
Meilleure réponse

Hi,

You must ensure that the value you're assigning to the field is exactly one of the values that have been predefined in the field definition. Below is an example of how you can define and use a selection field correctly.In models define the field:from odoo import models, fields


class MyModel(models.Model):

    _name = 'my.model'


    my_selection_field = fields.Selection([

        ('value1', 'Value 1'),

        ('value2', 'Value 2'),

        ('value3', 'Value 3'),

    ], string='My Selection Field', default='value1')


When you assign a value to the selection field, make sure that the value is one of the keys specified in the selection options:


    def some_method(self):

        self.my_selection_field = 'value2' 

This value must match one of the keys in the selection options.


Hope it helps

Avatar
Ignorer
Publications associées Réponses Vues Activité
1
avr. 24
1903
1
avr. 24
2443
2
avr. 24
2747
1
juil. 25
1636
0
févr. 24
1139