Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

partner_firstname Fix tests with stock #66

Merged
merged 1 commit into from
Dec 23, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)