콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
1704 화면

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
2027
1
4월 24
2599
2
4월 24
2950
1
7월 25
1784
0
2월 24
1241