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.

57 lines
1.7 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2019 ACSONE SA/NV
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. from odoo import api, fields, models
  5. class TestOnchangeHelperMessage(models.Model):
  6. _name = "test_onchange_helper.message"
  7. _description = "Test Onchange Helper Message"
  8. discussion = fields.Many2one(
  9. "test_onchange_helper.discussion", ondelete="cascade"
  10. )
  11. body = fields.Text()
  12. author = fields.Many2one("res.users", default=lambda self: self.env.user)
  13. name = fields.Char(string="Title", compute="_compute_name", store=True)
  14. display_name = fields.Char(
  15. string="Abstract", compute="_compute_display_name"
  16. )
  17. discussion_name = fields.Char(
  18. related="discussion.name", string="Discussion Name"
  19. )
  20. author_partner = fields.Many2one(
  21. "res.partner",
  22. compute="_compute_author_partner",
  23. search="_search_author_partner",
  24. )
  25. important = fields.Boolean()
  26. @api.one
  27. @api.depends("author.name", "discussion.name")
  28. def _compute_name(self):
  29. self.name = "[%s] %s" % (
  30. self.discussion.name or "",
  31. self.author.name or "",
  32. )
  33. @api.one
  34. @api.depends("author.name", "discussion.name", "body")
  35. def _compute_display_name(self):
  36. stuff = "[%s] %s: %s" % (
  37. self.author.name,
  38. self.discussion.name or "",
  39. self.body or "",
  40. )
  41. self.display_name = stuff[:80]
  42. @api.one
  43. @api.depends("author", "author.partner_id")
  44. def _compute_author_partner(self):
  45. self.author_partner = self.author.partner_id
  46. @api.model
  47. def _search_author_partner(self, operator, value):
  48. return [("author.partner_id", operator, value)]