Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
266 มุมมอง

I was trying to edit a selection field on my custom module via python code.


Original Field Definition

unit_of_measurement = fields.Selection(

​string='Unit of Measurement',

   selection=[

       ('meter', 'Meter'),

       ('feet', 'Feet'),

   ],

 )


I changed it to:

unit_of_measurement = fields.Selection(

​string='Unit of Measurement of to get Size Area',

   selection=[

       ('square_meter', 'Square meters'),

       ('squre_feet', 'Square feet'),

   ],

 )


What Happened After the Update:

When you updated your custom module, Odoo did not remove the old options. Instead, it combined both the old and new selection values,

Options became:
- meter
- feet
- square_meter
- squre_feet


Can someone explain to me what could be the cause and how can I resolve it? Thank you in advance!

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Identify the Field Type

  • A Selection field in Odoo is used to allow users to choose one option from a predefined list.
  • The options are usually static (hardcoded) or dynamically computed.

What Usually Goes Wrong

Common issues with Selection fields include:

  • The new value you're trying to assign is not in the list of allowed selections.
  • If the field value in the database doesn't match any current selection, it will throw an error.
  • When the selection values change in the code but existing records still have old or invalid values, it causes inconsistencies.

Root Cause (Most Likely)

  • The value being set or edited is not present in the current list of selection options.
  • Odoo checks if the value is valid according to the defined selections.
  • If the selection list was changed recently, or if data was imported/created with outdated values, it can lead to this issue.

How to Fix or Avoid It

  • Make sure that all values used in your records are present in the current selection list.
  • If you modify the selection list, check your database for any existing values that are now invalid.
  • You might need to write a script or use the Odoo shell to clean up or update invalid records.

Good Practice

  • When changing selection options, migrate existing data accordingly.
  • Always validate values before assigning them, especially if they come from user input or external sources.

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
Odoo 10 selection field แก้ไขแล้ว
2
ก.ย. 17
12003
Selection Field, how does it work? แก้ไขแล้ว
2
เม.ย. 15
28530
1
พ.ค. 23
2397
2
มี.ค. 18
4550
0
มี.ค. 15
2941