From 4d2d40c45285d3d5fbe1c7ce3225f4aaf45483e1 Mon Sep 17 00:00:00 2001 From: steveferry Date: Mon, 1 Jun 2015 16:13:07 +0200 Subject: [PATCH 1/5] Keep partner's lastname if it has one --- partner_firstname/res_user.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/partner_firstname/res_user.py b/partner_firstname/res_user.py index 447d34661..100381dfc 100644 --- a/partner_firstname/res_user.py +++ b/partner_firstname/res_user.py @@ -35,8 +35,14 @@ class ResUsers(orm.Model): installed """ vals2 = vals.copy() + + res_partner = self.pool.get('res.partner') + partner = res_partner.browse(cr, user, vals2['partner_id'], context) + if 'name' in vals: vals2['lastname'] = vals2['name'] + elif partner.lastname: + vals2['lastname'] = partner.lastname elif 'login' in vals and 'lastname' not in vals: vals2['lastname'] = vals2['login'] return super(ResUsers, self).create(cr, user, vals2, context=context) From 9a9dcb3a64fcb01118123e0c832f4eabfc25b1fe Mon Sep 17 00:00:00 2001 From: steveferry Date: Tue, 2 Jun 2015 11:44:46 +0200 Subject: [PATCH 2/5] Add a condition --- partner_firstname/res_user.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/partner_firstname/res_user.py b/partner_firstname/res_user.py index 100381dfc..490bc16ca 100644 --- a/partner_firstname/res_user.py +++ b/partner_firstname/res_user.py @@ -41,7 +41,7 @@ class ResUsers(orm.Model): if 'name' in vals: vals2['lastname'] = vals2['name'] - elif partner.lastname: + elif partner.lastname and 'lastname' not in vals: vals2['lastname'] = partner.lastname elif 'login' in vals and 'lastname' not in vals: vals2['lastname'] = vals2['login'] From dfa858069f1e3b227b35e81e27ac42ce7ce80edc Mon Sep 17 00:00:00 2001 From: steveferry Date: Wed, 10 Jun 2015 14:43:48 +0200 Subject: [PATCH 3/5] Review Test existence of 'partner_id' --- partner_firstname/res_user.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/partner_firstname/res_user.py b/partner_firstname/res_user.py index 490bc16ca..18d2d5930 100644 --- a/partner_firstname/res_user.py +++ b/partner_firstname/res_user.py @@ -36,13 +36,14 @@ class ResUsers(orm.Model): """ vals2 = vals.copy() - res_partner = self.pool.get('res.partner') - partner = res_partner.browse(cr, user, vals2['partner_id'], context) - if 'name' in vals: vals2['lastname'] = vals2['name'] - elif partner.lastname and 'lastname' not in vals: - vals2['lastname'] = partner.lastname + elif 'lastname' not in vals and 'partner_id' in vals: + res_partner = self.pool.get('res.partner') + partner = res_partner.browse(cr, user, vals2['partner_id'], + context) + if partner.lastname: + vals2['lastname'] = partner.lastname elif 'login' in vals and 'lastname' not in vals: vals2['lastname'] = vals2['login'] return super(ResUsers, self).create(cr, user, vals2, context=context) From e8ec4bb928b7804596ac45138acebe4d35c75127 Mon Sep 17 00:00:00 2001 From: steveferry Date: Wed, 10 Jun 2015 14:46:05 +0200 Subject: [PATCH 4/5] Fix PEP8 error --- partner_firstname/res_user.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/partner_firstname/res_user.py b/partner_firstname/res_user.py index 18d2d5930..4a47241b1 100644 --- a/partner_firstname/res_user.py +++ b/partner_firstname/res_user.py @@ -40,7 +40,7 @@ class ResUsers(orm.Model): vals2['lastname'] = vals2['name'] elif 'lastname' not in vals and 'partner_id' in vals: res_partner = self.pool.get('res.partner') - partner = res_partner.browse(cr, user, vals2['partner_id'], + partner = res_partner.browse(cr, user, vals2['partner_id'], context) if partner.lastname: vals2['lastname'] = partner.lastname From 4d35891d66def1c07b1835636e606c3728d56c3a Mon Sep 17 00:00:00 2001 From: steveferry Date: Mon, 29 Jun 2015 13:32:00 +0200 Subject: [PATCH 5/5] FIX --- partner_firstname/res_user.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/partner_firstname/res_user.py b/partner_firstname/res_user.py index 4a47241b1..ec71f526b 100644 --- a/partner_firstname/res_user.py +++ b/partner_firstname/res_user.py @@ -42,8 +42,7 @@ class ResUsers(orm.Model): res_partner = self.pool.get('res.partner') partner = res_partner.browse(cr, user, vals2['partner_id'], context) - if partner.lastname: - vals2['lastname'] = partner.lastname + vals2['lastname'] = partner.lastname elif 'login' in vals and 'lastname' not in vals: vals2['lastname'] = vals2['login'] return super(ResUsers, self).create(cr, user, vals2, context=context)