Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
91 Lượt xem

Hello Odoo Community,

I'm encountering a very strange issue in Odoo 17 regarding a Selection field that loses its options in the database schema under specific upgrade scenarios. I would appreciate any insights or suggestions.

My Goal & Implementation

My goal is to add a consistent workflow state field (kanban_state) to many models that already use mail.thread and mail.activity.mixin (like sale.order, purchase.order, etc.).

To avoid creating a new mixin and manually adding it to dozens of models, I chose to inherit the core mail.activity.mixin and inject my new field there. This way, any model that is "chatter-enabled" automatically gets my workflow capabilities.

Here is the code for my mixin:

code

Python

# In my custom module: my_workflow_mixin/models/mail_activity_mixin.py


from odoo import fields, models


class MailActivityMixin(models.AbstractModel):

_name = 'mail.activity.mixin'

_inherit = 'mail.activity.mixin'

_description = 'Enhance native Activity Mixin with workflow capabilities'


kanban_state = fields.Selection([

('draft', 'Draft'),

('to_approve', 'To Approve'),

('approved', 'Approved'),

('rejected', 'Rejected')

], string='Kanban State', default='draft', tracking=True, copy=False,

help="A visual state field for use in kanban views and status bars.")

The Strange Problem

The issue arises with models that inherit this mixin, for example, sale.order.

Initial State: After installing my module (my_workflow_mixin), everything works correctly. The kanban_state field appears in the sale.order model, and in the PostgreSQL database, the sale_order table has a kanban_state column with the correct enum type and its four defined options.

Problem Occurs: After a server restart and an upgrade of another module (or sometimes after just upgrading my own module again after making a small change), I find that the selection options for kanban_state have disappeared from the sale_order table in the database. When I inspect the column type in PostgreSQL, the enum is empty. This causes errors in the UI as the values no longer match a valid selection.

Temporary Fix: If I run a full database update for all modules using the command line: ./odoo-bin -u all -d my_database, the selection options reappear correctly in the database schema for the sale_order table. The enum is repopulated.

Problem Reappears: However, if I then make a change to my my_workflow_mixin module and upgrade only this module (./odoo-bin -u my_workflow_mixin -d my_database), the problem comes back! The selection options are once again wiped from the sale_order table's enum type.

My Hypothesis and Questions

It seems like the module loading order and the scope of the update (-u my_module vs. -u all) are causing the Odoo ORM to incorrectly update the PostgreSQL enum type. When only my module is updated, the ORM seems to forget that other models like sale.order depend on this modified mixin, and it fails to propagate the schema changes correctly. The -u all command forces a re-evaluation of the entire model registry in the correct dependency order, which fixes it temporarily.

Has anyone encountered this behavior before?

Is inheriting a core Odoo mixin like mail.activity.mixin to add fields considered bad practice, and could it be the root cause of these ORM inconsistencies?

Is this a potential bug in the Odoo 17 ORM regarding how it handles schema updates for inherited models?

Any help would be greatly appreciated. Thank you!


Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
4
thg 5 25
2724
2
thg 5 25
6156
1
thg 3 25
1819
4
thg 3 25
4718
3
thg 2 25
5805