[FIX] hr: force a name to employee creation
The name field is a stored related on the resource.resource record. The name on the resource is required. If no name (and no resource_id), the creation fails as trying to create a resource without name (non-null constrain) Force in the view to indicate to the user that a name is required but without adding the constrain at the database level. required=True on the fields adds a non-null constrain on the SQL column but the related values are populated *after* the INSERT so it would fail depending on the given values (e.g. a resource_id value but no name) Fixes #20126 Closes #20128
This commit is contained in:
@@ -105,6 +105,7 @@ class Employee(models.Model):
|
||||
return tools.image_resize_image_big(base64.b64encode(open(image_path, 'rb').read()))
|
||||
|
||||
# resource and user
|
||||
# required on the resource, make sure required="True" set in the view
|
||||
name = fields.Char(related='resource_id.name', store=True, oldname='name_related')
|
||||
user_id = fields.Many2one('res.users', 'User', related='resource_id.user_id')
|
||||
active = fields.Boolean('Active', related='resource_id.active', default=True, store=True)
|
||||
|
||||
@@ -49,7 +49,7 @@
|
||||
<div class="oe_title">
|
||||
<label for="name" class="oe_edit_only"/>
|
||||
<h1>
|
||||
<field name="name" placeholder="Employee's Name"/>
|
||||
<field name="name" placeholder="Employee's Name" required="True"/>
|
||||
</h1>
|
||||
</div>
|
||||
<field name="category_ids" widget="many2many_tags" options="{'color_field': 'color', 'no_create_edit': True}" placeholder="e.g. Part Time" groups="hr.group_hr_user"/>
|
||||
|
||||
Reference in New Issue
Block a user