One2many 字段在 Odoo13 中显示为空 entries/records
One2many field shows empty entries/records in Odoo13
我想要一个 one2many 字段,其中包括两个不同的 models/classes、hr.employee 和我的一个自定义模型 (project.roles)。但是当我想将新记录添加到 one2many 列表时安装我的插件后,它给了我编辑的选项,但是 list/field 仍然是空的,它显示了一个我还没有实现的字段 'ID'。
这里有一些图片可以向您展示我的意思:
My Many2one field after editing and adding records
My Form-View for editing the Many2one field
这是我的 python 代码:
from datetime import timedelta
from odoo import api, fields, models, tools
from odoo.exceptions import UserError, AccessError, ValidationError
class Roles_Config_List(models.Model):
_name = 'config.list'
employee_id = fields.Many2one('hr.employee', string="Employee")
choose_role = fields.Many2one('project.roles', string="Role")
class Roles_Config(models.Model):
_inherit = 'project.project'
emp_pro_id = fields.One2many(
'config.list', 'employee_id', string="try")
pro_emp_id = fields.One2many(
'config.list', 'choose_role', string="Configuration")
这是'project.roles'class的代码:
from datetime import timedelta
from odoo import api, fields, models, tools
from odoo.exceptions import UserError, AccessError, ValidationError
class Roles(models.Model):
_name = 'project.roles'
role_id = fields.Char('Role', required=1, tracking=1)
currency_id = fields.Many2one("res.currency", string="currency")
rate = fields.Monetary('Rate (€)', required=1, tracking=1)
和我的 xml :
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="project_addon_config_roles" model="ir.ui.view">
<field name="name">view.config.roles</field>
<field name="model">project.project</field>
<field name="inherit_id" ref="project.edit_project"/>
<field name="arch" type="xml">
<page name="settings" position="after">
<page name="config_roles" string="Configuration Roles">
<form>
<sheet>
<group name="config_roles_emp" string="Configuration">
<field name="pro_emp_id" string="List" nolabel="0"/>
<field name="emp_pro_id" string="Try"/>
</group>
</sheet>
</form>
</page>
</page>
</field>
</record>
</odoo>
在这两种情况下,employee_id
和 choose_role
应该等于当前项目。
The value of such a field is the recordset of all the records in comodel_name
such that the field inverse_name
is equal to the current record.
您可以在 Odoo documentation
阅读有关 One2many
字段的更多信息
我想要一个 one2many 字段,其中包括两个不同的 models/classes、hr.employee 和我的一个自定义模型 (project.roles)。但是当我想将新记录添加到 one2many 列表时安装我的插件后,它给了我编辑的选项,但是 list/field 仍然是空的,它显示了一个我还没有实现的字段 'ID'。
这里有一些图片可以向您展示我的意思:
My Many2one field after editing and adding records
My Form-View for editing the Many2one field
这是我的 python 代码:
from datetime import timedelta
from odoo import api, fields, models, tools
from odoo.exceptions import UserError, AccessError, ValidationError
class Roles_Config_List(models.Model):
_name = 'config.list'
employee_id = fields.Many2one('hr.employee', string="Employee")
choose_role = fields.Many2one('project.roles', string="Role")
class Roles_Config(models.Model):
_inherit = 'project.project'
emp_pro_id = fields.One2many(
'config.list', 'employee_id', string="try")
pro_emp_id = fields.One2many(
'config.list', 'choose_role', string="Configuration")
这是'project.roles'class的代码:
from datetime import timedelta
from odoo import api, fields, models, tools
from odoo.exceptions import UserError, AccessError, ValidationError
class Roles(models.Model):
_name = 'project.roles'
role_id = fields.Char('Role', required=1, tracking=1)
currency_id = fields.Many2one("res.currency", string="currency")
rate = fields.Monetary('Rate (€)', required=1, tracking=1)
和我的 xml :
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="project_addon_config_roles" model="ir.ui.view">
<field name="name">view.config.roles</field>
<field name="model">project.project</field>
<field name="inherit_id" ref="project.edit_project"/>
<field name="arch" type="xml">
<page name="settings" position="after">
<page name="config_roles" string="Configuration Roles">
<form>
<sheet>
<group name="config_roles_emp" string="Configuration">
<field name="pro_emp_id" string="List" nolabel="0"/>
<field name="emp_pro_id" string="Try"/>
</group>
</sheet>
</form>
</page>
</page>
</field>
</record>
</odoo>
在这两种情况下,employee_id
和 choose_role
应该等于当前项目。
The value of such a field is the recordset of all the records in
comodel_name
such that the fieldinverse_name
is equal to the current record.
您可以在 Odoo documentation
阅读有关One2many
字段的更多信息