gpt4 book ai didi

python-3.x - Many2many 字段使用相同的表和列,同时继承 _name 字段 Odoo13

转载 作者:行者123 更新时间:2023-12-04 11:30:57 24 4
gpt4 key购买 nike

This error is thrown up when "hr.employee" or any other model with Many2many field is inherited to my model in odoo13.


Traceback (most recent call last):


File "/opt/odoo/odoo/modules/registry.py", line 59, in __new__
return cls.registries[db_name]
File "/opt/odoo/odoo/tools/func.py", line 69, in wrapper
return func(self, *args, **kwargs)
File "/opt/odoo/odoo/tools/lru.py", line 44, in __getitem__
a = self.d[obj].me
KeyError: 'shorepoint'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/opt/odoo/odoo/modules/registry.py", line 85, in new
odoo.modules.load_modules(registry._db, force_demo, status, update_module)
File "/opt/odoo/odoo/modules/loading.py", line 423, in load_modules
registry.setup_models(cr)
File "/opt/odoo/odoo/modules/registry.py", line 247, in setup_models
model._setup_fields()
File "/opt/odoo/odoo/models.py", line 2684, in _setup_fields
field.setup_full(self)
File "/opt/odoo/odoo/fields.py", line 418, in setup_full
self._setup_regular_full(model)
File "/opt/odoo/odoo/fields.py", line 3151, in _setup_regular_full
raise TypeError(msg % (self, field))
TypeError: Many2many fields school.student.category_ids and hr.employee.category_ids use the same table and columns

这是我的代码:
from odoo import models, fields, api

class school_management(models.Model):
_name = 'school.student'
_inherit = 'hr.employee'
_description = 'Model to manage school students'

最佳答案

hr应用领域category_ids是这样定义的:

    category_ids = fields.Many2many(
'hr.employee.category', 'employee_category_rel',
'emp_id', 'category_id',
string='Tags')

他们指定了 relation 的名称和 columns所以当他继承了 hr.employee在您的自定义模型中定义相同的 category_ids用于您的模型,这就是为什么 Odoo 会混淆您使用相同的 relationcolumns定义一个 many2many relation两种不同的型号 .您所要做的就是删除此 歧义 通过为您指定一个新的关系名称 many2many field 。
class school_management(models.Model):
_name = 'school.student'
_inherit = 'hr.employee'
_description = 'student' # this will be used to log message when you create a student, so keep it simple, when you create a record message will be 'student is created'

# define new relation name and better column names
# and I think you need a new category model because this one is used for employee category, may be it's better to create hr.student.category table I don't know it's up to you
category_ids = fields.Many2many(
'hr.employee.category', 'student_category_rel',
'student_id', 'category_id',
string='Tags')

我希望这可以帮助你。

关于python-3.x - Many2many 字段使用相同的表和列,同时继承 _name 字段 Odoo13,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59981217/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com