Odoo模块服务器更新报错:res.company不存在e_invoice系列字段
问题
本地环境模块运行正常,但服务器端更新模块时出现报错。通过继承res.company模型添加了以下字段:
class InheritAccountMove(models.Model): _inherit = 'res.company' tax_office = fields.Many2one('tax.office', string='Tax Office') building_no = fields.Char(string='Building Number') district_name = fields.Char(string='District/Town') e_invoice_username = fields.Char(string="E-Invoice API Username") e_invoice_password = fields.Char(string="E-Invoice API Password") e_invoice_catalog = fields.Char(string="E-Invoice API Catalog") e_invoice_isyeri = fields.Char(string="E-Invoice API Isyeri") e_invoice_wsdl = fields.Char(string="E-Invoice API wsdl")
对应的视图XML如下:
<record id="view_company_form_inherit" model="ir.ui.view"> <field name="name">company.form</field> <field name="model">res.company</field> <field name="inherit_id" ref="base.view_company_form"/> <field name="arch" type="xml"> <xpath expr="//field[@name='vat']" position="after"> <field name="tax_office"/> <field name="building_no"/> <field name="district_name"/> <field name="e_invoice_username"/> <field name="e_invoice_password"/> <field name="e_invoice_catalog"/> <field name="e_invoice_isyeri"/> <field name="e_invoice_wsdl"/> </xpath> </field> </record>
报错信息:
THERE IS NO FIELD "e_invoice_username" inside of res.company.
其中tax_office、building_no和district_name是一周前添加的,此前运行正常;新增以e_invoice开头的字段后触发报错。已尝试卸载并重新上传模块,但问题仍未解决。
解决方法
- 检查Python文件加载配置:确保定义新增字段的Python文件已被正确导入到模块的
__init__.py中。比如字段文件在models/res_company.py,需在模块根目录__init__.py添加from . import models,同时models/__init__.py添加from . import res_company,避免服务器端未加载该文件。 - 强制刷新模型定义:在服务器端执行带
--force参数的模块升级命令,强制Odoo刷新模型结构:
也可通过Odoo Shell手动触发模型更新:./odoo-bin -d 你的数据库名 -u 你的模块名 --forceself.env['res.company']._fields.clear() self.env['res.company']._auto_init() - 验证文件完整性:对比本地与服务器端的模块文件,确认新增字段的Python文件已完整上传,无遗漏或损坏。
- 排查字段命名冲突:临时修改一个
e_invoice开头的字段名(如改为e_inv_username),测试是否仍报错,排除字段名与系统保留关键字或其他模块字段重名的可能。 - 查看服务器日志:检查Odoo服务器日志,获取更详细的错误信息(如Python文件语法错误、依赖缺失等),定位问题根源。
内容的提问来源于stack exchange,提问作者Selman
相关产品推荐
相关产品推荐

