From 87d3dbf41faccd5d38c50dbc46b69018acfd5a64 Mon Sep 17 00:00:00 2001 From: "Ronald Portier (Therp BV)" Date: Fri, 17 Apr 2015 16:23:48 +0200 Subject: [PATCH] [FIX] cannot create user due to required name. --- partner_firstname/partner.py | 11 ++++------- partner_firstname/res_user.py | 12 +++++++++--- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/partner_firstname/partner.py b/partner_firstname/partner.py index 938709490..52dccd201 100644 --- a/partner_firstname/partner.py +++ b/partner_firstname/partner.py @@ -115,15 +115,12 @@ class ResPartner(orm.Model): even if we use fnct_inv: otherwise we can't create entry because lastname is mandatory and module will not install if there is demo data """ - to_use = vals - if 'name' in vals: - corr_vals = vals.copy() - if vals.get('name'): - corr_vals['lastname'] = corr_vals['name'] + corr_vals = vals.copy() + if corr_vals.get('name'): + corr_vals['lastname'] = corr_vals['name'] del(corr_vals['name']) - to_use = corr_vals return super(ResPartner, self).create( - cursor, uid, to_use, context=context) + cursor, uid, corr_vals, context=context) _columns = {'name': fields.function(_compute_name_custom, string="Name", type="char", store=True, diff --git a/partner_firstname/res_user.py b/partner_firstname/res_user.py index a84f5b18c..83ec8be7c 100644 --- a/partner_firstname/res_user.py +++ b/partner_firstname/res_user.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +"""Extend res.users to be compatible with split name in res.partner.""" ############################################################################## # # Author: Nicolas Bessi. Copyright Camptocamp SA @@ -17,14 +18,19 @@ # along with this program. If not, see . # ############################################################################## -from openerp.osv import orm +from openerp import api, models from openerp.tools.translate import _ -class ResUsers(orm.Model): - +class ResUsers(models.Model): + """Extend res.users to be compatible with split name in res.partner.""" _inherit = 'res.users' + @api.onchange('firstname', 'lastname') + def change_name(self): + names = [name for name in [self.firstname, self.lastname] if name] + self.name = ' '.join(names) + def copy_data(self, cr, uid, _id, default=None, context=None): """ Avoid to replicate the firstname into the name when duplicating a user