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.

54 lines
2.1 KiB

  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # This file is part of partner_academic_title,
  5. # an Odoo module.
  6. #
  7. # Copyright (c) 2015 ACSONE SA/NV (<http://acsone.eu>)
  8. #
  9. # partner_academic_title is free software:
  10. # you can redistribute it and/or modify it under the terms of the GNU
  11. # Affero General Public License as published by the Free Software
  12. # Foundation,either version 3 of the License, or (at your option) any
  13. # later version.
  14. #
  15. # partner_academic_title is distributed
  16. # in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
  17. # even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  18. # PURPOSE. See the GNU Affero General Public License for more details.
  19. #
  20. # You should have received a copy of the GNU Affero General Public License
  21. # along with partner_academic_title.
  22. # If not, see <http://www.gnu.org/licenses/>.
  23. #
  24. ##############################################################################
  25. from openerp import models, fields, api
  26. class ResPartner(models.Model):
  27. _inherit = 'res.partner'
  28. def _get_separator(self):
  29. return ', '
  30. @api.depends('academic_title_ids', 'academic_title_ids.sequence')
  31. @api.one
  32. def _get_academic_title_display(self):
  33. display_title = ""
  34. separator = self._get_separator()
  35. title_ids = self.academic_title_ids.sorted(lambda r: r.sequence)
  36. for title in title_ids:
  37. if display_title:
  38. display_title = "%s%s%s" % (display_title, separator,
  39. title.name)
  40. else:
  41. display_title = "%s" % (title.name)
  42. self.academic_title_display = display_title
  43. academic_title_ids = fields.Many2many(
  44. comodel_name='partner.academic.title',
  45. relation='partner_academic_title_ref', column1='partner_id',
  46. column2='academic_title_id', string='Academic Titles')
  47. academic_title_display = fields.Char(compute='_get_academic_title_display',
  48. string='Academic Titles', store=True)