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.

69 lines
2.9 KiB

  1. # Copyright 2014-2017 Therp BV <https://therp.nl>
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  3. # pylint: disable=no-self-use
  4. from odoo import _, api, fields, models
  5. from odoo.exceptions import ValidationError
  6. class ResPartnerRelationType(models.Model):
  7. # pylint: disable=too-few-public-methods
  8. _inherit = 'res.partner.relation.type'
  9. tab_left_id = fields.Many2one(
  10. comodel_name='res.partner.tab',
  11. string='Tab for this relation',
  12. help="Tab in which these relations will be visible on partner.")
  13. tab_right_id = fields.Many2one(
  14. comodel_name='res.partner.tab',
  15. string='Tab for inverse relation',
  16. help="Tab in which inverse relations will be visible on partner.")
  17. @api.multi
  18. @api.constrains(
  19. 'contact_type_left',
  20. 'partner_category_left',
  21. 'tab_left_id')
  22. def _check_tab_left(self):
  23. """Conditions for left partner should be consistent with tab."""
  24. for rec in self:
  25. if not rec.tab_left_id:
  26. continue
  27. tab_contact_type = rec.tab_left_id.contact_type
  28. if tab_contact_type and tab_contact_type != rec.contact_type_left:
  29. raise ValidationError(_(
  30. "Contact type left not compatible with left tab"))
  31. tab_partner_category_id = rec.tab_left_id.partner_category_id
  32. if tab_partner_category_id and \
  33. tab_partner_category_id != rec.partner_category_left:
  34. raise ValidationError(_(
  35. "Partner category left not compatible with left tab"))
  36. @api.multi
  37. @api.constrains(
  38. 'contact_type_right',
  39. 'partner_category_right',
  40. 'tab_right_id')
  41. def _check_tab_right(self):
  42. """Conditions for right partner should be consistent with tab."""
  43. for rec in self:
  44. if not rec.tab_right_id:
  45. continue
  46. tab_contact_type = rec.tab_right_id.contact_type
  47. if tab_contact_type and tab_contact_type != rec.contact_type_right:
  48. raise ValidationError(_(
  49. "Contact type right not compatible with right tab"))
  50. tab_partner_category_id = rec.tab_right_id.partner_category_id
  51. if tab_partner_category_id and \
  52. tab_partner_category_id != rec.partner_category_right:
  53. raise ValidationError(_(
  54. "Partner category right not compatible with right tab"))
  55. @api.multi
  56. def _update_right_vals(self, vals):
  57. """Make sure that on symmetric relations, right vals follow left vals.
  58. @attention: original method only handles properties ending with _left
  59. and we need to update tab_right_id as well
  60. """
  61. vals['tab_right_id'] = vals.get('tab_left_id', self['tab_left_id'])
  62. super(ResPartnerRelationType, self)._update_right_vals(vals)