for-loop
for-loop

Reputation: 57

One2many field shows empty entries/records in Odoo13

I want to have a one2many field which included two different models/classes, the hr.employee and my one custom model (project.roles). But after installing my addon when I want to add new records to the one2many list, it gives me the option to edit, but the list/field remains empty and it shows a field 'ID' which I havent implemented.

Here are some pictures to show you what I mean:

My Many2one field after editing and adding records

My Form-View for editing the Many2one field

This is my python code :

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")

this is the code of the '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)

and my 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>

Upvotes: 0

Views: 913

Answers (1)

Kenly
Kenly

Reputation: 26688

In both cases, employee_id and choose_role should be equal to the current project.

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.

You can read more about One2many fields at the Odoo documentation

Upvotes: 1

Related Questions