From f7b276b544865654638111dbed3ee9d26f05646e Mon Sep 17 00:00:00 2001 From: nobuQuartile Date: Thu, 15 Jan 2026 09:28:46 +0000 Subject: [PATCH] [ADD] mail_last_message_date --- mail_last_message_date/README.rst | 108 ++++ mail_last_message_date/__init__.py | 1 + mail_last_message_date/__manifest__.py | 14 + mail_last_message_date/models/__init__.py | 2 + .../models/mail_last_message_date_mixin.py | 21 + mail_last_message_date/models/mail_message.py | 26 + mail_last_message_date/readme/CONFIGURE.rst | 18 + .../readme/CONTRIBUTORS.rst | 4 + mail_last_message_date/readme/DESCRIPTION.rst | 4 + .../static/description/index.html | 462 ++++++++++++++++++ mail_last_message_date/tests/__init__.py | 4 + .../test_mail_last_message_date_mixin.py | 44 ++ mail_last_message_date/tests/test_models.py | 16 + .../odoo/addons/mail_last_message_date | 1 + setup/mail_last_message_date/setup.py | 6 + 15 files changed, 731 insertions(+) create mode 100644 mail_last_message_date/README.rst create mode 100644 mail_last_message_date/__init__.py create mode 100644 mail_last_message_date/__manifest__.py create mode 100644 mail_last_message_date/models/__init__.py create mode 100644 mail_last_message_date/models/mail_last_message_date_mixin.py create mode 100644 mail_last_message_date/models/mail_message.py create mode 100644 mail_last_message_date/readme/CONFIGURE.rst create mode 100644 mail_last_message_date/readme/CONTRIBUTORS.rst create mode 100644 mail_last_message_date/readme/DESCRIPTION.rst create mode 100644 mail_last_message_date/static/description/index.html create mode 100644 mail_last_message_date/tests/__init__.py create mode 100644 mail_last_message_date/tests/test_mail_last_message_date_mixin.py create mode 100644 mail_last_message_date/tests/test_models.py create mode 120000 setup/mail_last_message_date/odoo/addons/mail_last_message_date create mode 100644 setup/mail_last_message_date/setup.py diff --git a/mail_last_message_date/README.rst b/mail_last_message_date/README.rst new file mode 100644 index 0000000000..9b2c053229 --- /dev/null +++ b/mail_last_message_date/README.rst @@ -0,0 +1,108 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +====================== +Mail Last Message Date +====================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:ad8725fa1a949f43179cece42bbab34828e98918bbddb1d0049bbdbc67b10614 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github + :target: https://github.com/OCA/social/tree/15.0/mail_last_message_date + :alt: OCA/social +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/social-15-0/social-15-0-mail_last_message_date + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/social&target_branch=15.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module does not provide functionality on its own; another module must inherit +``mail.last.message.date.mixin`` on the target model. This module adds a last chatter +update datetime (``last_message_date``) through the mixin. Models inherit the mixin +explicitly, and can optionally restrict updates to specific message_type in code. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +#. Inherit ``mail.last.message.date.mixin`` on the models to track + (alongside ``mail.thread`` if the model does not already inherit it). +#. (Optional) override ``_get_tracked_message_types()`` on the model to return a list of + ``message_types``. If no ``message_types`` are returned, any message updates + ``last_message_date``. +#. Example: + + .. code-block:: python + + from odoo import models + + class PurchaseOrder(models.Model): + _inherit = ["purchase.order", "mail.last.message.date.mixin"] + + def _get_tracked_message_types(self): + message_types = super()._get_tracked_message_types() + message_types.append("email") + return message_types + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Quartile + +Contributors +~~~~~~~~~~~~ + +* `Quartile `__: + + * Toshikimi Shigenobu + * Yoshi Tashiro + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/social `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/mail_last_message_date/__init__.py b/mail_last_message_date/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/mail_last_message_date/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/mail_last_message_date/__manifest__.py b/mail_last_message_date/__manifest__.py new file mode 100644 index 0000000000..808b2b2236 --- /dev/null +++ b/mail_last_message_date/__manifest__.py @@ -0,0 +1,14 @@ +# Copyright 2026 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + "name": "Mail Last Message Date", + "version": "15.0.1.0.0", + "category": "Mail", + "summary": "Track last message date on models using the mixin", + "author": "Quartile, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/social", + "license": "AGPL-3", + "depends": ["mail"], + "installable": True, +} diff --git a/mail_last_message_date/models/__init__.py b/mail_last_message_date/models/__init__.py new file mode 100644 index 0000000000..c320f4d755 --- /dev/null +++ b/mail_last_message_date/models/__init__.py @@ -0,0 +1,2 @@ +from . import mail_message +from . import mail_last_message_date_mixin diff --git a/mail_last_message_date/models/mail_last_message_date_mixin.py b/mail_last_message_date/models/mail_last_message_date_mixin.py new file mode 100644 index 0000000000..2e936b97fb --- /dev/null +++ b/mail_last_message_date/models/mail_last_message_date_mixin.py @@ -0,0 +1,21 @@ +# Copyright 2026 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import fields, models + + +class MailLastMessageDateMixin(models.AbstractModel): + _name = "mail.last.message.date.mixin" + + last_message_date = fields.Datetime( + help="Datetime when a message was posted on the record.", + ) + + def _get_tracked_message_types(self): + return [] + + def _should_track_message(self, message): + message_types = self._get_tracked_message_types() + if not message_types: + return True + return message.message_type in message_types diff --git a/mail_last_message_date/models/mail_message.py b/mail_last_message_date/models/mail_message.py new file mode 100644 index 0000000000..0b6f2348ab --- /dev/null +++ b/mail_last_message_date/models/mail_message.py @@ -0,0 +1,26 @@ +# Copyright 2026 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import api, models + + +class MailMessage(models.Model): + _inherit = "mail.message" + + def _update_last_message_date(self): + for message in self: + if not (message.model and message.res_id): + continue + record = self.env[message.model].browse(message.res_id) + if ( + "last_message_date" not in record._fields + or not record._should_track_message(message) + ): + continue + record.sudo().write({"last_message_date": message.date}) + + @api.model_create_multi + def create(self, vals_list): + messages = super().create(vals_list) + messages._update_last_message_date() + return messages diff --git a/mail_last_message_date/readme/CONFIGURE.rst b/mail_last_message_date/readme/CONFIGURE.rst new file mode 100644 index 0000000000..5d5f0bb0fc --- /dev/null +++ b/mail_last_message_date/readme/CONFIGURE.rst @@ -0,0 +1,18 @@ +#. Inherit ``mail.last.message.date.mixin`` on the models to track + (alongside ``mail.thread`` if the model does not already inherit it). +#. (Optional) override ``_get_tracked_message_types()`` on the model to return a list of + ``message_types``. If no ``message_types`` are returned, any message updates + ``last_message_date``. +#. Example: + + .. code-block:: python + + from odoo import models + + class PurchaseOrder(models.Model): + _inherit = ["purchase.order", "mail.last.message.date.mixin"] + + def _get_tracked_message_types(self): + message_types = super()._get_tracked_message_types() + message_types.append("email") + return message_types diff --git a/mail_last_message_date/readme/CONTRIBUTORS.rst b/mail_last_message_date/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..52192eefec --- /dev/null +++ b/mail_last_message_date/readme/CONTRIBUTORS.rst @@ -0,0 +1,4 @@ +* `Quartile `__: + + * Toshikimi Shigenobu + * Yoshi Tashiro diff --git a/mail_last_message_date/readme/DESCRIPTION.rst b/mail_last_message_date/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..3bcb244565 --- /dev/null +++ b/mail_last_message_date/readme/DESCRIPTION.rst @@ -0,0 +1,4 @@ +This module does not provide functionality on its own; another module must inherit +``mail.last.message.date.mixin`` on the target model. This module adds a last chatter +update datetime (``last_message_date``) through the mixin. Models inherit the mixin +explicitly, and can optionally restrict updates to specific message_type in code. diff --git a/mail_last_message_date/static/description/index.html b/mail_last_message_date/static/description/index.html new file mode 100644 index 0000000000..47f4900c26 --- /dev/null +++ b/mail_last_message_date/static/description/index.html @@ -0,0 +1,462 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + +
+

Mail Last Message Date

+ +

Beta License: AGPL-3 OCA/social Translate me on Weblate Try me on Runboat

+

This module does not provide functionality on its own; another module must inherit +mail.last.message.date.mixin on the target model. This module adds a last chatter +update datetime (last_message_date) through the mixin. Models inherit the mixin +explicitly, and can optionally restrict updates to specific message_type in code.

+

Table of contents

+ +
+

Configuration

+
    +
  1. Inherit mail.last.message.date.mixin on the models to track +(alongside mail.thread if the model does not already inherit it).

    +
  2. +
  3. (Optional) override _get_tracked_message_types() on the model to return a list of +message_types. If no message_types are returned, any message updates +last_message_date.

    +
  4. +
  5. Example:

    +
    +from odoo import models
    +
    +class PurchaseOrder(models.Model):
    +    _inherit = ["purchase.order", "mail.last.message.date.mixin"]
    +
    +    def _get_tracked_message_types(self):
    +        message_types = super()._get_tracked_message_types()
    +        message_types.append("email")
    +        return message_types
    +
    +
  6. +
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Quartile
  • +
+
+
+

Contributors

+
    +
  • Quartile:
      +
    • Toshikimi Shigenobu
    • +
    • Yoshi Tashiro
    • +
    +
  • +
+
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/social project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+
+ + diff --git a/mail_last_message_date/tests/__init__.py b/mail_last_message_date/tests/__init__.py new file mode 100644 index 0000000000..4f69039aef --- /dev/null +++ b/mail_last_message_date/tests/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2026 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import test_mail_last_message_date_mixin diff --git a/mail_last_message_date/tests/test_mail_last_message_date_mixin.py b/mail_last_message_date/tests/test_mail_last_message_date_mixin.py new file mode 100644 index 0000000000..ce27a78b3f --- /dev/null +++ b/mail_last_message_date/tests/test_mail_last_message_date_mixin.py @@ -0,0 +1,44 @@ +# Copyright 2026 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo_test_helper import FakeModelLoader + +from odoo.tests import common + + +class TestMailLastMessageDate(common.TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.loader = FakeModelLoader(cls.env, cls.__module__) + cls.loader.backup_registry() + from .test_models import TestMailLastMessage + + cls.loader.update_registry((TestMailLastMessage,)) + cls.record = cls.env[TestMailLastMessage._name].create({"name": "Test Record"}) + + @classmethod + def tearDownClass(cls): + cls.loader.restore_registry() + return super().tearDownClass() + + def _create_message(self, message_type="email"): + return self.env["mail.message"].create( + { + "message_type": message_type, + "model": self.record._name, + "res_id": self.record.id, + "body": "Test message", + } + ) + + def test_update_on_tracked_message_type(self): + self.record.write({"last_message_date": False}) + message = self._create_message() + self.assertEqual(self.record.last_message_date, message.date) + + def test_no_update_on_untracked_message_type(self): + self.record.write({"last_message_date": False}) + self._create_message(message_type="comment") + self.record.invalidate_cache(["last_message_date"]) + self.assertFalse(self.record.last_message_date) diff --git a/mail_last_message_date/tests/test_models.py b/mail_last_message_date/tests/test_models.py new file mode 100644 index 0000000000..1b658e5de6 --- /dev/null +++ b/mail_last_message_date/tests/test_models.py @@ -0,0 +1,16 @@ +# Copyright 2026 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import fields, models + + +class TestMailLastMessage(models.Model): + _name = "test.mail.last.message.date" + _inherit = ["mail.thread", "mail.last.message.date.mixin"] + + name = fields.Char() + + def _get_tracked_message_types(self): + message_types = super()._get_tracked_message_types() + message_types.append("email") + return message_types diff --git a/setup/mail_last_message_date/odoo/addons/mail_last_message_date b/setup/mail_last_message_date/odoo/addons/mail_last_message_date new file mode 120000 index 0000000000..38671f3457 --- /dev/null +++ b/setup/mail_last_message_date/odoo/addons/mail_last_message_date @@ -0,0 +1 @@ +../../../../mail_last_message_date \ No newline at end of file diff --git a/setup/mail_last_message_date/setup.py b/setup/mail_last_message_date/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/mail_last_message_date/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)