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.

70 lines
2.7 KiB

10 years ago
10 years ago
11 years ago
11 years ago
  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # Author: Nicolas Bessi. Copyright Camptocamp SA
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU Affero General Public License as
  8. # published by the Free Software Foundation, either version 3 of the
  9. # License, or (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU Affero General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU Affero General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. ##############################################################################
  20. from openerp.osv import orm
  21. from openerp.tools.translate import _
  22. class ResUsers(orm.Model):
  23. _inherit = 'res.users'
  24. def create(self, cr, user, vals, context=None):
  25. """To support data backward compatibility we have to keep this
  26. overwrite even if we use fnct_inv: otherwise we can't create
  27. entry because lastname is mandatory and module will not install
  28. if there is demo data
  29. This fixes the unittests in stock when partner_firstname is
  30. installed
  31. """
  32. vals2 = vals.copy()
  33. if 'name' in vals:
  34. vals2['lastname'] = vals2['name']
  35. elif 'lastname' not in vals and 'partner_id' in vals:
  36. res_partner = self.pool.get('res.partner')
  37. partner = res_partner.browse(cr, user, vals2['partner_id'],
  38. context)
  39. vals2['lastname'] = partner.lastname
  40. elif 'login' in vals and 'lastname' not in vals:
  41. vals2['lastname'] = vals2['login']
  42. return super(ResUsers, self).create(cr, user, vals2, context=context)
  43. def copy_data(self, cr, uid, _id, default=None, context=None):
  44. """Avoid to replicate the firstname into the name when
  45. duplicating a user
  46. """
  47. default = default or {}
  48. if not default.get('lastname'):
  49. default = default.copy()
  50. default['lastname'] = (
  51. _('%s (copy)') % self.read(
  52. cr,
  53. uid,
  54. [_id],
  55. ['lastname'],
  56. context=context
  57. )[0]['lastname']
  58. )
  59. if default.get('name'):
  60. del(default['name'])
  61. return super(ResUsers, self).copy_data(
  62. cr, uid, _id, default, context=context
  63. )