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.

78 lines
3.0 KiB

11 years ago
11 years ago
11 years ago
11 years ago
  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # Author: Yannick Vaucher
  5. # Copyright 2013 Camptocamp SA
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as
  9. # published by the Free Software Foundation, either version 3 of the
  10. # License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. ##############################################################################
  21. from openerp.osv import orm, fields
  22. class ResPartner(orm.Model):
  23. _inherit = 'res.partner'
  24. def _display_name_compute(self, cr, uid, ids, name, args, context=None):
  25. return dict(self.name_get(cr, uid, ids, context=context))
  26. def name_get(self, cr, uid, ids, context=None):
  27. """ By pass of name_get to use directly firstname and lastname
  28. as we cannot ensure name as already been computed when calling this
  29. method for display_name"""
  30. if context is None:
  31. context = {}
  32. if isinstance(ids, (int, long)):
  33. ids = [ids]
  34. res = []
  35. for record in self.browse(cr, uid, ids, context=context):
  36. names = (record.lastname, record.firstname)
  37. name = u" ".join([s for s in names if s])
  38. if record.parent_id and not record.is_company:
  39. name = "%s, %s" % (record.parent_id.name, name)
  40. if context.get('show_address'):
  41. name = name + "\n" + self._display_address(
  42. cr, uid, record, without_company=True, context=context
  43. )
  44. name = name.replace('\n\n', '\n')
  45. name = name.replace('\n\n', '\n')
  46. if context.get('show_email') and record.email:
  47. name = "%s <%s>" % (name, record.email)
  48. res.append((record.id, name))
  49. return res
  50. _display_name_store_triggers = {
  51. 'res.partner': (
  52. lambda self, cr, uid, ids, context=None:
  53. self.search(cr, uid, [
  54. ('id', 'child_of', ids)
  55. ]),
  56. ['parent_id', 'is_company', 'name', 'firstname', 'lastname'],
  57. 10
  58. )
  59. }
  60. # indirection to avoid passing a copy of the overridable method when
  61. # declaring the function field
  62. _display_name = lambda self, *a, **kw: self._display_name_compute(*a, **kw)
  63. _columns = {
  64. # extra field to allow ORDER BY to match visible names
  65. 'display_name': fields.function(
  66. _display_name,
  67. type='char',
  68. string='Name',
  69. store=_display_name_store_triggers
  70. ),
  71. }