From 6286dc4809e7c7f6b212d18436588c4b54164bbc Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Fri, 13 Oct 2017 11:31:57 +0200 Subject: [PATCH] [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 --- addons/hr/models/hr.py | 1 + addons/hr/views/hr_views.xml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/hr/models/hr.py b/addons/hr/models/hr.py index 7901261f001..974b4c9acf6 100644 --- a/addons/hr/models/hr.py +++ b/addons/hr/models/hr.py @@ -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) diff --git a/addons/hr/views/hr_views.xml b/addons/hr/views/hr_views.xml index aae1a300f3d..be426aba38f 100644 --- a/addons/hr/views/hr_views.xml +++ b/addons/hr/views/hr_views.xml @@ -49,7 +49,7 @@