You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将Odoo8字段转换并迁移至Odoo11?求解决方案

Converting Odoo 8 Field Definitions to Odoo 11

Hey there, migrating from Odoo 8 to 11? Let's get those field definitions updated properly. Here's the refactored code for Odoo 11, plus a breakdown of the key changes you need to know:

Updated Odoo 11 Code

from odoo import fields, models

class YourModelName(models.Model):
    _name = 'your.model.name'  # Don't forget to replace with your actual model technical name!
    _description = 'Your Model Description'  # Optional but recommended for documentation

    name = fields.Char(string='Name', size=64, required=True)
    code = fields.Char(string='Code', size=9, required=True)
    description = fields.Text(string='Description')
    active = fields.Boolean(string='Active', help="If the active field is set to False, it will allow you to hide the record without removing it.")

Key Differences from Odoo 8

  • No more _columns dictionary: Starting in Odoo 9, the ORM moved away from wrapping fields in a _columns dict. Now fields are defined directly as class attributes of your model.
  • Import path shift: The top-level package changed from openerp to odoo in Odoo 9, so you'll need to update your imports to match.
  • Explicit keyword parameters: In Odoo 8, you could pass the field label and length as positional arguments. In newer versions, using explicit keywords like string= (for labels) and size= (for char field lengths) makes your code more readable and future-proof.
  • Optional _description: Adding this attribute is a best practice in Odoo 11+ to document your model's purpose for other developers and the Odoo interface.

Quick Additional Tips

  • Keep other model attributes like _inherit or _order intact—only the field definition structure changes here.
  • For other field types (e.g., many2one, selection), follow the same pattern: move them out of _columns and define them as class attributes with updated keyword parameters if needed.

内容的提问来源于stack exchange,提问作者Sankar guru

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 06:38:47