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.

55 lines
2.0 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2014-2017 Therp BV <http://therp.nl>
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from openerp import api, fields, models
  5. class ResPartnerRelationAll(models.AbstractModel):
  6. """Abstract model to show each relation from two sides."""
  7. _inherit = 'res.partner.relation.all'
  8. tab_id = fields.Many2one(
  9. comodel_name='res.partner.tab',
  10. string='Show relation on tab',
  11. readonly=True,
  12. )
  13. def _get_additional_view_fields(self):
  14. """Add tab_id to view fields."""
  15. return ','.join([
  16. super(ResPartnerRelationAll, self)._get_additional_view_fields(),
  17. "CASE"
  18. " WHEN NOT bas.is_inverse"
  19. " THEN lefttab.id"
  20. " ELSE righttab.id"
  21. " END as tab_id"])
  22. def _get_additional_tables(self):
  23. """Add res_partner_tab table to view."""
  24. return ' '.join([
  25. super(ResPartnerRelationAll, self)._get_additional_tables(),
  26. "LEFT OUTER JOIN res_partner_tab lefttab"
  27. " ON typ.tab_left_id = lefttab.id",
  28. "LEFT OUTER JOIN res_partner_tab righttab"
  29. " ON typ.tab_right_id = righttab.id"])
  30. @api.onchange(
  31. 'this_partner_id',
  32. 'other_partner_id',
  33. )
  34. def onchange_partner_id(self):
  35. """Add tab if needed to type_selection_id domain.
  36. This method makes sure then when a relation is added to a tab,
  37. it is with a relation type meant to be placed on that tab.
  38. """
  39. result = super(ResPartnerRelationAll, self).onchange_partner_id()
  40. if 'default_tab_id' in self.env.context:
  41. if 'domain' not in result:
  42. result['domain'] = {}
  43. if 'type_selection_id' not in result['domain']:
  44. result['domain']['type_selection_id'] = []
  45. selection_domain = result['domain']['type_selection_id']
  46. selection_domain.append(
  47. ('tab_id', '=', self.env.context['default_tab_id']))
  48. return result