Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
2202 Widoki

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)

Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
kwi 24
2572
1
kwi 24
3175
2
kwi 24
3580
1
lip 25
2333
0
lut 24
1653