Odoo继承product.product模型时触发500错误,服务器崩溃
Fixing "TypeError: Model 'product.product' does not exist in registry" When Inheriting product.product in Odoo
Hey, let's break down what's going wrong here and fix it quickly.
The core issue in your code is that you're mixing up Odoo's model inheritance syntax. When you want to extend an existing model (like product.product from the product/website_sale modules), you don't need to set the _name attribute—only _inherit is required.
Here's why your code caused the 500 error:
- By setting
_name = 'product.product'alongside_inherit = 'product.product', you're telling Odoo to redefine theproduct.productmodel from scratch, instead of inheriting and extending the existing one. - Odoo loads modules in a specific order, and your custom module is trying to redefine the model before the original
productmodule has registered it in the system registry. That's why you get the "Model does not exist" error.
The Corrected Code
Replace your models.py with this:
# -*- coding: utf-8 -*- from odoo import models, fields, api class ImgToGifProductExtension(models.Model): _inherit = 'product.product' # Add your custom fields, methods, or overrides here # Example: # custom_description = fields.Text(string="Custom GIF Description")
Additional Checks to Ensure Everything Works
- Module Dependencies: Make sure your custom module depends on the
productmodule (sinceproduct.productoriginates there) andwebsite_saleif you need its features. Update your__manifest__.pyfile:'depends': ['product', 'website_sale'], - Class Naming: The class name can be anything descriptive (I used
ImgToGifProductExtensionhere)—it doesn't have to match the original model name. - Restart & Upgrade: After fixing the code, restart your Odoo server and upgrade your custom module through the Odoo interface.
That should resolve the server crash and let you extend the product.product model as intended.
内容的提问来源于stack exchange,提问作者Mike2233
相关产品推荐
相关产品推荐

