You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

153 lines
6.2 KiB

  1. # -*- coding: utf-8 -*-
  2. #
  3. #
  4. # Authors: Nemry Jonathan
  5. # Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu)
  6. # All Rights Reserved
  7. #
  8. # WARNING: This program as such is intended to be used by professional
  9. # programmers who take the whole responsibility of assessing all potential
  10. # consequences resulting from its eventual inadequacies and bugs.
  11. # End users who are looking for a ready-to-use solution with commercial
  12. # guarantees and support are strongly advised to contact a Free Software
  13. # Service Company.
  14. #
  15. # This program is Free Software; you can redistribute it and/or
  16. # modify it under the terms of the GNU General Public License
  17. # as published by the Free Software Foundation; either version 2
  18. # of the License, or (at your option) any later version.
  19. #
  20. # This program is distributed in the hope that it will be useful,
  21. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. # GNU General Public License for more details.
  24. #
  25. # You should have received a copy of the GNU General Public License
  26. # along with this program; if not, write to the Free Software
  27. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  28. #
  29. #
  30. import openerp.tests.common as common
  31. from openerp.tools.translate import _
  32. class test_partner_firstname(common.TransactionCase):
  33. def setUp(self):
  34. super(test_partner_firstname, self).setUp()
  35. self.registry('ir.model').clear_caches()
  36. self.registry('ir.model.data').clear_caches()
  37. self.user_model = self.registry("res.users")
  38. self.partner_model = self.registry("res.partner")
  39. self.fields_partner = {
  40. 'lastname': 'lastname', 'firstname': 'firstname'}
  41. self.fields_user = {
  42. 'name': 'lastname', 'login': 'v5Ue4Tql0Pm67KX05g25A'}
  43. self.context = self.user_model.context_get(self.cr, self.uid)
  44. def test_copy_partner(self):
  45. cr, uid, context = self.cr, self.uid, self.context
  46. res_id = self.partner_model.create(
  47. cr, uid, self.fields_partner, context=context)
  48. res_id = self.partner_model.copy(
  49. cr, uid, res_id, default={}, context=context)
  50. vals = self.partner_model.read(cr, uid, [res_id], [
  51. 'name', 'lastname', 'firstname'], context=context)[0]
  52. self.assertEqual(
  53. vals['name'],
  54. _('%s (copy)') % 'lastname' + " firstname",
  55. 'Copy of the partner failed with wrong name'
  56. )
  57. self.assertEqual(
  58. vals['lastname'],
  59. _('%s (copy)') % 'lastname',
  60. 'Copy of the partner failed with wrong lastname'
  61. )
  62. self.assertEqual(vals['firstname'], 'firstname',
  63. 'Copy of the partner failed with wrong firstname')
  64. def test_copy_user(self):
  65. cr, uid, context = self.cr, self.uid, self.context
  66. # create a user
  67. res_id = self.user_model.create(
  68. cr, uid, self.fields_user, context=context)
  69. # get the related partner id and add it a firstname
  70. flds = self.user_model.read(
  71. cr, uid, [res_id], ['partner_id'], context=context)[0]
  72. self.partner_model.write(cr, uid, flds['partner_id'][
  73. 0], {'firstname': 'firstname'}, context=context)
  74. # copy the user and compare result
  75. res_id = self.user_model.copy(
  76. cr, uid, res_id, default={}, context=context)
  77. vals = self.user_model.read(
  78. cr, uid, [res_id], ['name', 'lastname', 'firstname'],
  79. context=context)[0]
  80. self.assertEqual(
  81. vals['name'],
  82. _('%s (copy)') % 'lastname' + ' firstname',
  83. 'Copy of the user failed with wrong name'
  84. )
  85. self.assertEqual(
  86. vals['lastname'], _('%s (copy)') %
  87. 'lastname', 'Copy of the user failed with wrong lastname')
  88. self.assertEqual(vals['firstname'], 'firstname',
  89. 'Copy of the user failed with wrong firstname')
  90. def test_update_user_lastname(self):
  91. cr, uid, context = self.cr, self.uid, self.context
  92. # create a user
  93. res_id = self.user_model.create(
  94. cr, uid, self.fields_user, context=context)
  95. # get the related partner id and add it a firstname
  96. flds = self.user_model.read(
  97. cr, uid, [res_id], ['partner_id'], context=context)[0]
  98. self.partner_model.write(
  99. cr, uid, flds['partner_id'][0], {'firstname': 'firstname'},
  100. context=context)
  101. self.user_model.write(
  102. cr, uid, res_id, {'name': 'change firstname'}, context=context)
  103. vals = self.user_model.read(
  104. cr, uid, [res_id], ['name', 'lastname', 'firstname'],
  105. context=context)[0]
  106. self.assertEqual(vals['name'], 'change firstname',
  107. 'Update of the user lastname failed with wrong name')
  108. self.assertEqual(
  109. vals['lastname'], 'change',
  110. 'Update of the user lastname failed with wrong lastname')
  111. self.assertEqual(
  112. vals['firstname'], 'firstname',
  113. 'Update of the user lastname failed with wrong firstname')
  114. def test_update_user_firstname(self):
  115. cr, uid, context = self.cr, self.uid, self.context
  116. # create a user
  117. res_id = self.user_model.create(
  118. cr, uid, self.fields_user, context=context)
  119. # get the related partner id and add it a firstname
  120. flds = self.user_model.read(
  121. cr, uid, [res_id], ['partner_id'], context=context)[0]
  122. self.partner_model.write(
  123. cr, uid, flds['partner_id'][0], {'firstname': 'firstname'},
  124. context=context)
  125. self.user_model.write(
  126. cr, uid, res_id, {'name': 'lastname other'}, context=context)
  127. vals = self.user_model.read(
  128. cr, uid, [res_id], ['name', 'lastname', 'firstname'],
  129. context=context)[0]
  130. self.assertEqual(
  131. vals['name'], 'lastname other',
  132. 'Update of the user firstname failed with wrong name')
  133. self.assertEqual(
  134. vals['lastname'], 'lastname other',
  135. 'Update of the user firstname failed with wrong lastname')
  136. self.assertFalse(
  137. vals['firstname'],
  138. 'Update of the user firstname failed with wrong firstname')