跳至內容
選單
此問題已被標幟
1 回覆
1570 瀏覽次數

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)

頭像
捨棄
最佳答案

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

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
1
4月 24
1917
1
4月 24
2460
2
4月 24
2765
1
7月 25
1648
0
2月 24
1149