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.

56 lines
2.1 KiB

  1. # Copyright 2014-2018 Therp BV <https://therp.nl>.
  2. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
  3. from odoo import api, fields, models
  4. class ResPartnerRelationAll(models.AbstractModel):
  5. """Abstract model to show each relation from two sides."""
  6. _inherit = 'res.partner.relation.all'
  7. tab_id = fields.Many2one(
  8. comodel_name='res.partner.tab',
  9. string='Show relation on tab',
  10. readonly=True,
  11. )
  12. def _get_additional_view_fields(self):
  13. """Add tab_id to view fields."""
  14. # pylint: disable=no-member
  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. # pylint: disable=no-member
  25. return ' '.join([
  26. super(ResPartnerRelationAll, self)._get_additional_tables(),
  27. "LEFT OUTER JOIN res_partner_tab lefttab"
  28. " ON typ.tab_left_id = lefttab.id",
  29. "LEFT OUTER JOIN res_partner_tab righttab"
  30. " ON typ.tab_right_id = righttab.id"])
  31. @api.onchange(
  32. 'this_partner_id',
  33. 'other_partner_id',
  34. )
  35. def onchange_partner_id(self):
  36. """Add tab if needed to type_selection_id domain.
  37. This method makes sure that when a relation is added to a tab,
  38. it is with a relation type meant to be placed on that tab.
  39. """
  40. # pylint: disable=no-member
  41. result = super(ResPartnerRelationAll, self).onchange_partner_id()
  42. if 'default_tab_id' in self.env.context:
  43. result['domain'] = result['domain'] if 'domain' in result else {}
  44. result['domain']['type_selection_id'] = \
  45. result['domain']['type_selection_id'] \
  46. if 'type_selection_id' in result['domain'] else {}
  47. result['domain']['type_selection_id'].append(
  48. ('tab_id', '=', self.env.context['default_tab_id']))
  49. return result