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.

197 lines
6.8 KiB

10 years ago
10 years ago
  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',
  41. 'firstname': 'firstname',
  42. }
  43. self.fields_user = {
  44. 'name': 'lastname',
  45. 'login': 'v5Ue4Tql0Pm67KX05g25A',
  46. }
  47. self.context = self.user_model.context_get(self.cr, self.uid)
  48. def test_copy_partner(self):
  49. cr, uid, context = self.cr, self.uid, self.context
  50. res_id = self.partner_model.create(
  51. cr, uid, self.fields_partner, context=context
  52. )
  53. res_id = self.partner_model.copy(
  54. cr, uid, res_id, default={}, context=context
  55. )
  56. vals = self.partner_model.read(
  57. cr, uid, [res_id],
  58. ['name', 'lastname', 'firstname'], context=context
  59. )[0]
  60. self.assertEqual(
  61. vals['name'],
  62. _('%s (copy)') % 'lastname' + " firstname",
  63. 'Copy of the partner failed with wrong name'
  64. )
  65. self.assertEqual(
  66. vals['lastname'],
  67. _('%s (copy)') % 'lastname',
  68. 'Copy of the partner failed with wrong lastname'
  69. )
  70. self.assertEqual(
  71. vals['firstname'],
  72. 'firstname',
  73. 'Copy of the partner failed with wrong firstname'
  74. )
  75. def test_copy_user(self):
  76. cr, uid, context = self.cr, self.uid, self.context
  77. # create a user
  78. res_id = self.user_model.create(
  79. cr, uid, self.fields_user, context=context
  80. )
  81. # get the related partner id and add it a firstname
  82. flds = self.user_model.read(
  83. cr, uid, [res_id], ['partner_id'], context=context
  84. )[0]
  85. self.partner_model.write(
  86. cr, uid, flds['partner_id'][0], {'firstname': 'firstname'},
  87. context=context
  88. )
  89. # copy the user and compare result
  90. res_id = self.user_model.copy(
  91. cr, uid, res_id, default={}, context=context
  92. )
  93. vals = self.user_model.read(
  94. cr, uid, [res_id], ['name', 'lastname', 'firstname'],
  95. context=context
  96. )[0]
  97. self.assertEqual(
  98. vals['name'],
  99. _('%s (copy)') % 'lastname' + ' firstname',
  100. 'Copy of the user failed with wrong name'
  101. )
  102. self.assertEqual(
  103. vals['lastname'],
  104. _('%s (copy)') % 'lastname',
  105. 'Copy of the user failed with wrong lastname'
  106. )
  107. self.assertEqual(
  108. vals['firstname'],
  109. 'firstname',
  110. 'Copy of the user failed with wrong firstname'
  111. )
  112. def test_update_user_lastname(self):
  113. cr, uid, context = self.cr, self.uid, self.context
  114. # create a user
  115. res_id = self.user_model.create(
  116. cr, uid, self.fields_user, context=context
  117. )
  118. # get the related partner id and add it a firstname
  119. flds = self.user_model.read(
  120. cr, uid, [res_id], ['partner_id'], context=context
  121. )[0]
  122. self.partner_model.write(
  123. cr, uid, flds['partner_id'][0], {'firstname': 'firstname'},
  124. context=context
  125. )
  126. self.user_model.write(
  127. cr, uid, res_id, {'name': 'change firstname'}, context=context
  128. )
  129. vals = self.user_model.read(
  130. cr, uid, [res_id], ['name', 'lastname', 'firstname'],
  131. context=context
  132. )[0]
  133. self.assertEqual(
  134. vals['name'],
  135. 'change firstname',
  136. 'Update of the user lastname failed with wrong name'
  137. )
  138. self.assertEqual(
  139. vals['lastname'],
  140. 'change',
  141. 'Update of the user lastname failed with wrong lastname'
  142. )
  143. self.assertEqual(
  144. vals['firstname'],
  145. 'firstname',
  146. 'Update of the user lastname failed with wrong firstname'
  147. )
  148. def test_update_user_firstname(self):
  149. cr, uid, context = self.cr, self.uid, self.context
  150. # create a user
  151. res_id = self.user_model.create(
  152. cr, uid, self.fields_user, context=context
  153. )
  154. # get the related partner id and add it a firstname
  155. flds = self.user_model.read(
  156. cr, uid, [res_id], ['partner_id'], context=context
  157. )[0]
  158. self.partner_model.write(
  159. cr, uid, flds['partner_id'][0], {'firstname': 'firstname'},
  160. context=context
  161. )
  162. self.user_model.write(
  163. cr, uid, res_id, {'name': 'lastname other'}, context=context
  164. )
  165. vals = self.user_model.read(
  166. cr, uid, [res_id], ['name', 'lastname', 'firstname'],
  167. context=context
  168. )[0]
  169. self.assertEqual(
  170. vals['name'],
  171. 'lastname other',
  172. 'Update of the user firstname failed with wrong name'
  173. )
  174. self.assertEqual(
  175. vals['lastname'],
  176. 'lastname other',
  177. 'Update of the user firstname failed with wrong lastname'
  178. )
  179. self.assertFalse(
  180. vals['firstname'],
  181. 'Update of the user firstname failed with wrong firstname'
  182. )