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.

67 lines
2.1 KiB

  1. # Copyright 2018 Eficent Business and IT Consulting Services S.L.
  2. # Copyright 2018 Odoo, S.A.
  3. # License AGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
  4. from odoo.addons.mail.models.mail_activity import MailActivity
  5. from odoo import fields
  6. def pre_init_hook(cr):
  7. """ The objective of this hook is to default to false all values of field
  8. 'done' of mail.activity
  9. """
  10. cr.execute("""SELECT column_name
  11. FROM information_schema.columns
  12. WHERE table_name='mail_activity' AND
  13. column_name='done'""")
  14. if not cr.fetchone():
  15. cr.execute(
  16. """
  17. ALTER TABLE mail_activity ADD COLUMN done boolean;
  18. """)
  19. cr.execute(
  20. """
  21. UPDATE mail_activity
  22. SET done = False
  23. """
  24. )
  25. def post_load_hook():
  26. def new_action_feedback(self, feedback=False):
  27. if 'done' not in self._fields:
  28. return self.action_feedback_original(feedback=feedback)
  29. message = self.env['mail.message']
  30. if feedback:
  31. self.write(dict(feedback=feedback))
  32. for activity in self:
  33. record = self.env[activity.res_model].browse(activity.res_id)
  34. activity.done = True
  35. activity.active = False
  36. activity.date_done = fields.Date.today()
  37. record.message_post_with_view(
  38. 'mail.message_activity_done',
  39. values={'activity': activity},
  40. subtype_id=self.env.ref('mail.mt_activities').id,
  41. mail_activity_type_id=activity.activity_type_id.id,
  42. )
  43. message |= record.message_ids[0]
  44. return message.ids and message.ids[0] or False
  45. if not hasattr(MailActivity, 'action_feedback_original'):
  46. MailActivity.action_feedback_original = MailActivity.action_feedback
  47. MailActivity.action_feedback = new_action_feedback
  48. def uninstall_hook(cr, registry):
  49. """ The objective of this hook is to remove all activities that are done
  50. upon module uninstall
  51. """
  52. cr.execute(
  53. """
  54. DELETE FROM mail_activity
  55. WHERE done=True
  56. """
  57. )