如何将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
_columnsdictionary: Starting in Odoo 9, the ORM moved away from wrapping fields in a_columnsdict. Now fields are defined directly as class attributes of your model. - Import path shift: The top-level package changed from
openerptoodooin 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) andsize=(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
_inheritor_orderintact—only the field definition structure changes here. - For other field types (e.g.,
many2one,selection), follow the same pattern: move them out of_columnsand define them as class attributes with updated keyword parameters if needed.
内容的提问来源于stack exchange,提问作者Sankar guru
相关产品推荐
相关产品推荐

