Skip to content

Commit

Permalink
Merge pull request #66 from savoirfairelinux/7.0-partner_contact-odoo…
Browse files Browse the repository at this point in the history
…-tests

partner_firstname Fix tests with stock
  • Loading branch information
guewen committed Dec 23, 2014
2 parents 7e4d6d4 + 04c13b3 commit 1dbb4ce
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
16 changes: 16 additions & 0 deletions partner_firstname/res_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@ class ResUsers(orm.Model):

_inherit = 'res.users'

def create(self, cr, user, vals, context=None):
"""To support data backward compatibility we have to keep this
overwrite 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
This fixes the unittests in stock when partner_firstname is
installed
"""
vals2 = vals.copy()
if 'name' in vals:
vals2['lastname'] = vals2['name']
elif 'login' in vals and 'lastname' not in vals:
vals2['lastname'] = vals2['login']
return super(ResUsers, self).create(cr, user, vals2, context=context)

def copy_data(self, cr, uid, _id, default=None, context=None):
"""Avoid to replicate the firstname into the name when
duplicating a user
Expand Down
13 changes: 13 additions & 0 deletions partner_firstname/tests/test_partner_firstname.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,16 @@ def test_update_user_firstname(self):
vals['firstname'],
'Update of the user firstname failed with wrong firstname'
)

def test_create_user_login_only(self):
"""Test creation of a user with only the login supplied"""
cr, uid, context = self.cr, self.uid, self.context
# create a user
res_id = self.user_model.create(
cr, uid, {'login': 'test_login_only'}, context=context
)
# get the related partner id and add it a firstname
user = self.user_model.browse(cr, uid, res_id, context=context)
self.assertEqual(user.login, user.name)
self.assertEqual(user.login, user.lastname)
self.assertEqual(user.login, user.partner_id.lastname)

0 comments on commit 1dbb4ce

Please sign in to comment.