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

Odoo11为已有模块新增字段失败,请求排查原因

Troubleshooting: Custom Field Not Showing Up in Odoo 11 Product Template

Hey there, let's walk through why your custom field isn't appearing in the Product Template form. Based on the code snippet you shared, here are the most common fixes to check:

  • First, make sure you defined the field in the Python model
    It's easy to forget this critical step! You need to inherit the product.template model in your custom module's Python file and add the field explicitly:

    from odoo import models, fields
    
    class ProductTemplate(models.Model):
        _inherit = 'product.template'
    
        # Replace with your actual field definition
        custom_field_name = fields.Char(string="My Custom Field")
    

    Without this, the view has no data source to pull from, so the field will never show up.

  • Fix the extra space in your inherit_id reference
    In your XML, you have a trailing space in the ref attribute: ref="product.product_template_only_form_view " — Odoo's XML IDs are case and whitespace-sensitive. Remove that space to correctly reference the parent view:

    <field name="inherit_id" ref="product.product_template_only_form_view" />
    

    A wrong reference means your view inheritance doesn't kick in at all.

  • Verify your XPath expression is complete and correct
    Your snippet cuts off at <xpath expr="//field[@n... — you need a full, valid XPath to target where you want to insert the field. For example, to add your field right after the "Sale Price" field (list_price), use:

    <xpath expr="//field[@name='list_price']" position="after">
        <field name="custom_field_name" />
    </xpath>
    

    If your XPath doesn't match any elements in the parent view, the field won't be inserted. Use your browser's dev tools (F12) to inspect the original form's structure and confirm the correct target.

  • Ensure your module is properly updated and has dependencies set
    After making changes, go to Odoo's Apps menu, find your custom module, and click Update. Also, double-check your __manifest__.py file to confirm it lists product as a dependency:

    'depends': ['product'],
    

    This ensures Odoo loads your module after the core Product module, so inheritance works as expected.

  • Check permissions for the field
    Even if the field exists, the current user might not have permission to see it. Either:

    • Add read access to the relevant groups in your module's security/ir.model.access.csv
    • Set the groups parameter in your field definition (e.g., groups="base.group_user")
    • Add readonly="0" to the field in the view if you want users to edit it
  • Check Odoo logs for errors
    If all else fails, look at Odoo's log file. It will show specific errors like XML parsing issues, missing field references, or inheritance failures — these clues will point you straight to the problem.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.22 09:44:33