This question has been flagged
2 Replies
14988 Views

I´m writing a custom module that had models that inherits from res.users to create custom users with some new filds.
I´m using delegation inheritance type to have another table for the fields of my custom users.
The schema is similar to: res.partner-->res.users-->custom_users.
I named the custom users "progenitor_tutor". I can access fields of res.users and res.partners like email or login from my custom view, but the problem is that when I´m trying to create a new custom user from the custom user view, a pop up appears and says:

And the res.partner, res.users, and progenitor_tutor (the custom user) datas are not created.
This is the code of my custom view and the custom model:

------------------------

<?xml version="1.0" encoding="UTF-8"?>
<odoo>

<!--Tree View of progenitor_tutor-->
<recordmodel="ir.ui.view"id="progenitor_tutor_tree_view">
<fieldname="name">progenitor_tutor.tree.view</field>
<fieldname="model">aula10.progenitor_tutor</field>
<fieldname="arch"type="xml">
<treestring="progenitor_tutor">
<fieldname="name"/>
<fieldname="login"/>
</tree>
</field>
</record>

<!--Form View of progenitor_tutor-->
<recordmodel="ir.ui.view"id="progenitor_tutor_form_view">
<fieldname="name">progenitor_tutor.form.view</field>
<fieldname="model">aula10.progenitor_tutor</field>
<fieldname="arch"type="xml">
<form>
  <sheet>
<fieldname="id"invisible="1"/>
<divclass="oe_button_box"name="button_box">
<buttonname="toggle_active"type="object"class="oe_stat_button"icon="fa-check">
<fieldname="active"widget="boolean_button"options='{"terminology": "active"}'/>
</button>
</div>
<fieldname="image"widget='image'class="oe_avatar"options='{"preview_image": "image_medium"}'/>
<divclass="oe_title">
<labelfor="name"class="oe_edit_only"/>
<h1><fieldname="name"required="1"/></h1>
<fieldname="email"invisible="1"/>
<labelfor="login"class="oe_edit_only"string="Email Address"/>
<h2><fieldname="login"/></h2>
<group>
<fieldname="partner_id"readonly="1"required="0"groups="base.group_no_one"
attrs="{'invisible': [('id', '=', False)]}"/>
</group>
</div>
<notebookcolspan="4">
<pagename="access_rights"string="Access Rights">
<groupstring="Multi Companies"attrs="{'invisible': [('companies_count', '&lt;=', 1)]}">
<fieldstring="Allowed Companies"name="company_ids"widget="many2many_tags"/>
<fieldstring="Current Company"name="company_id"context="{'user_preference': 0}"/>
<fieldstring="Companies count"name="companies_count"invisible="1"/>
</group>
<fieldname="groups_id"/>
</page>
<pagestring="Preferences">
<group>
<groupstring="Localization"name="preferences">
<fieldname="lang"/>
<fieldname="tz"widget="timezone_mismatch"options="{'tz_offset_field': 'tz_offset'}"/>
<fieldname="tz_offset"invisible="1"/>
</group>
<groupstring="Menus Customization"groups="base.group_no_one">
<fieldname="action_id"/>
</group>
</group>
<groupstring="Messaging and Social"name="messaging">
<fieldname="signature"/>
</group>
</page>
</notebook>
</sheet>
</form>
</field>
</record>

<!--Action of progenitor_tutor-->
<recordmodel="ir.actions.act_window"id="progenitor_tutor_action">
<fieldname="name">Padres/Tutores</field>
<fieldname="res_model">aula10.progenitor_tutor</field>
<fieldname="view_type">form</field>
<fieldname="view_mode">tree,form</field>
</record>

<!--Menu-->
<menuitemname="Padres/Tutores"id="progenitor_tutor"action="progenitor_tutor_action"/>

</odoo>

---------------------------

from odoo import models, fields, api
#from odoo.exceptions import ValidationError
class progenitor_tutor(models.Model):
_name = 'aula10.progenitor_tutor'
_inherits = {'res.users': 'usuario_id'}
usuario_id = fields.Many2one('res.users', required=True, ondelete='restrict', auto_join=True, string='Usuario relacionado', help='Partner-related data of the user')
name = fields.Char('Nombre',required=True)
Avatar
Discard

format your code

Best Answer

The problem is that you are adding a field "name" in your new model. When you save the record, the name you type in the form is the one in 'aula10.progenitor_tutor' and not the one in res.partner, wich is required.
In the python file, remove:

name = fields.Char('Nombre',required=True)
Then you will use the one in res.partner, as res.users does.

Avatar
Discard