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.

39 lines
1.4 KiB

  1. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  2. import logging
  3. from odoo import fields, models
  4. _logger = logging.getLogger(__name__)
  5. class ResPartner(models.Model):
  6. """Adds last name and first name; name becomes a stored function field."""
  7. _inherit = 'res.partner'
  8. def _compute_is_favorite(self):
  9. for partner in self:
  10. partner.is_favorite = self.env.user in partner.favorite_user_ids
  11. def _inverse_is_favorite(self):
  12. favorite_partners = not_fav_partners = self.env['res.partner'].sudo()
  13. for partner in self:
  14. if self.env.user in partner.favorite_user_ids:
  15. favorite_partners |= partner
  16. else:
  17. not_fav_partners |= partner
  18. # partner User has no write access for partner.
  19. not_fav_partners.write({'favorite_user_ids': [(4, self.env.uid)]})
  20. favorite_partners.write({'favorite_user_ids': [(3, self.env.uid)]})
  21. def _get_default_favorite_user_ids(self):
  22. return [(6, 0, [self.env.uid])]
  23. favorite_user_ids = fields.Many2many(
  24. 'res.users', 'partner_favorite_user_rel', 'partner_id', 'user_id',
  25. default=_get_default_favorite_user_ids,
  26. string='Members')
  27. is_favorite = fields.Boolean(
  28. compute='_compute_is_favorite',
  29. inverse='_inverse_is_favorite',
  30. string='Show Favorite Partner',
  31. help="Display this partner with favorite filter")