Browse Source

[CHG] Some Refactoring Of The Code

pull/2/head
Jonathan Nemry 11 years ago
parent
commit
6205e32cf1
  1. 6
      partner_firstname/partner.py
  2. 34
      partner_firstname/tests/test_partner_firstname.py

6
partner_firstname/partner.py

@ -53,9 +53,9 @@ class ResPartner(Model):
# * if only lastname change in the new name: lastname is updated accordingly, firstname remains untouched
"""
vals = {'lastname': field_value, 'firstname': False}
dict = self.read(cursor, uid, [partner_id], ['firstname', 'is_company'], context=context)[0]
if not dict['is_company']:
to_check = ' %s' % dict['firstname']
fields = self.read(cursor, uid, [partner_id], ['firstname', 'is_company'], context=context)[0]
if not fields['is_company']:
to_check = ' %s' % fields['firstname']
if field_value.endswith(to_check):
vals['lastname'] = field_value[:-len(to_check)]
del(vals['firstname'])

34
partner_firstname/tests/test_partner_firstname.py

@ -29,8 +29,6 @@
##############################################################################
import openerp.tests.common as common
ADMIN_USER_ID = common.ADMIN_USER_ID
class test_partner_firstname(common.TransactionCase):
@ -41,12 +39,12 @@ class test_partner_firstname(common.TransactionCase):
self.user_model = self.registry("res.users")
self.partner_model = self.registry("res.partner")
self.dict_partner = {'lastname': 'lastname', 'firstname': 'firstname'}
self.dict_user = {'name': 'lastname', 'login': 'v5Ue4Tql0Pm67KX05g25A'}
self.fields_partner = {'lastname': 'lastname', 'firstname': 'firstname'}
self.fields_user = {'name': 'lastname', 'login': 'v5Ue4Tql0Pm67KX05g25A'}
def test_copy_partner(self):
cr, uid = self.cr, ADMIN_USER_ID
res_id = self.partner_model.create(cr, uid, self.dict_partner, context={})
cr, uid = self.cr, self.uid
res_id = self.partner_model.create(cr, uid, self.fields_partner, context={})
res_id = self.partner_model.copy(cr, uid, res_id, default={}, context={})
vals = self.partner_model.read(cr, uid, [res_id], ['name', 'lastname', 'firstname'], context={})[0]
self.assertEqual(vals['name'] == "lastname (copy) firstname" and
@ -54,12 +52,12 @@ class test_partner_firstname(common.TransactionCase):
vals['firstname'] == 'firstname', True, 'Copy of the partner failed with wrong values')
def test_copy_user(self):
cr, uid = self.cr, ADMIN_USER_ID
cr, uid = self.cr, self.uid
# create a user
res_id = self.user_model.create(cr, uid, self.dict_user, context={})
res_id = self.user_model.create(cr, uid, self.fields_user, context={})
# get the related partner id and add it a firstname
dict = self.user_model.read(cr, uid, [res_id], ['partner_id'], context={})[0]
self.partner_model.write(cr, uid, dict['partner_id'][0], {'firstname':'firstname'}, context={})
fields = self.user_model.read(cr, uid, [res_id], ['partner_id'], context={})[0]
self.partner_model.write(cr, uid, fields['partner_id'][0], {'firstname':'firstname'}, context={})
# copy the user and compare result
res_id = self.user_model.copy(cr, uid, res_id, default={}, context={})
vals = self.user_model.read(cr, uid, [res_id], ['name', 'lastname', 'firstname'], context={})[0]
@ -68,12 +66,12 @@ class test_partner_firstname(common.TransactionCase):
vals['firstname'] == 'firstname', True, 'Copy of the user failed with wrong values')
def test_update_user_lastname(self):
cr, uid = self.cr, ADMIN_USER_ID
cr, uid = self.cr, self.uid
# create a user
res_id = self.user_model.create(cr, uid, self.dict_user, context={})
res_id = self.user_model.create(cr, uid, self.fields_user, context={})
# get the related partner id and add it a firstname
dict = self.user_model.read(cr, uid, [res_id], ['partner_id'], context={})[0]
self.partner_model.write(cr, uid, dict['partner_id'][0], {'firstname':'firstname'}, context={})
fields = self.user_model.read(cr, uid, [res_id], ['partner_id'], context={})[0]
self.partner_model.write(cr, uid, fields['partner_id'][0], {'firstname':'firstname'}, context={})
self.user_model.write(cr, uid, res_id, {'name': 'change firstname'}, context={})
vals = self.user_model.read(cr, uid, [res_id], ['name', 'lastname', 'firstname'], context={})[0]
self.assertEqual(vals['name'] == "change firstname" and
@ -81,12 +79,12 @@ class test_partner_firstname(common.TransactionCase):
vals['firstname'] == 'firstname', True, 'Update of the user lastname failed with wrong values')
def test_update_user_firstname(self):
cr, uid = self.cr, ADMIN_USER_ID
cr, uid = self.cr, self.uid
# create a user
res_id = self.user_model.create(cr, uid, self.dict_user, context={})
res_id = self.user_model.create(cr, uid, self.fields_user, context={})
# get the related partner id and add it a firstname
dict = self.user_model.read(cr, uid, [res_id], ['partner_id'], context={})[0]
self.partner_model.write(cr, uid, dict['partner_id'][0], {'firstname':'firstname'}, context={})
fields = self.user_model.read(cr, uid, [res_id], ['partner_id'], context={})[0]
self.partner_model.write(cr, uid, fields['partner_id'][0], {'firstname':'firstname'}, context={})
self.user_model.write(cr, uid, res_id, {'name': 'lastname other'}, context={})
vals = self.user_model.read(cr, uid, [res_id], ['name', 'lastname', 'firstname'], context={})[0]
self.assertEqual(vals['name'] == "lastname other" and

Loading…
Cancel
Save