Skip to Content
Menu
This question has been flagged
2 Replies
2580 Views

When I select 2 values in my one2many fields, i get this error. How can i correct it?


 


This is my code

class Level(models.Model):
_name = 'gc.level'

name = fields.Char(string='Degree', required=True)
note = fields.Integer(string="Note", required=True)
description = fields.Text(string="Description")
critere_id = fields.Many2one('gc.criteria', string="Criteria")



class Criteria(models.Model):
_name = 'gc.criteria'

name = fields.Char(string='Critère', required=True)
levels_ids = fields.One2many('gc.level', 'critere_id', string="Degree")
Avatar
Discard
Best Answer

Hi,

Please try following code,
Models → .py file

from odoo import models, fields


class Level(models.Model):
_name = 'gc.level'
name = fields.Char(string='Degree', required=True)
note = fields.Integer(string="Note", required=True)
description = fields.Text(string="Description")
critere_id = fields.Many2one('gc.criteria', string="Criteria")


class Criteria(models.Model):
_name = 'gc.criteria'
name = fields.Char(string='Critère')
levels_ids = fields.One2many('gc.level', 'critere_id', string="Degree")

Views → .xml file

<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record id="view_gc_criteria_form" model="ir.ui.view">
<field name="name">gc.criteria.form</field>
<field name="model">gc.criteria</field>
<field name="arch" type="xml">
<form>
<sheet>
<field name="name"/>
<div>
<group>
<field name="levels_ids">
<field name="name"/>
<field name="note"/>
<field name="description"/>
<field name="critere_id" invisible="1"/>
</field>
</group>
</div>
</sheet>
</form>
</field>
</record>
<record id="gc_criteria_tree_view" model="ir.ui.view">
<field name="name">gc.criteria.tree</field>
<field name="model">gc.criteria</field>
<field eval="8" name="priority"/>
<field name="arch" type="xml">
<tree string="Test Email">
<field name="name" string="Reference"/>
<field name="levels_ids"/>
</tree>
</field>
</record>
<record id="action_gc_criteria_form" model="ir.actions.act_window">
<field name="name">Gc Criteria</field>
<field name="res_model">gc.criteria</field>
<field name="view_mode">tree,kanban,form</field>
</record>
<menuitem action="action_gc_criteria_form" name="Gc Criteria"
id="menu_action_gc_criteria" string="Gc Criteria" parent="parent_module.menu_id" sequence="4"/>
</data>
</odoo>

Security → .csv file

id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_gc_criteria,test_email.gc_criteria,model_gc_criteria,base.group_user,1,1,1,1
access_gc_level,test_email.gc_level,model_gc_level,base.group_user,1,1,1,1

Regards

Avatar
Discard
Best Answer

Based on  above error example,

record = gc.level(24, 25)  //gc.level object multiple records. if you cannot access directly object.name

print(record.name ) // Cannot get value in that case Singleton Error throw.

Solution to fix:

record = gc.level(24, 25)

for rec in record:

    print("Name", rec.name)

Check you code if any validation applied, for multiple records value access use for loop to avoid singleton error.

Avatar
Discard
Related Posts Replies Views Activity
1
Sep 23
2030
1
Sep 21
22766
1
Jan 23
1562
1
Jun 22
4147
1
Jun 22
1887