Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[18.0][MIG] mail_thread_create_nolog: Migration to 18.0 #1481

Open
wants to merge 9 commits into
base: 18.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 109 additions & 0 deletions mail_thread_create_nolog/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
=============================
Mail Thread - Fake create log
=============================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:71f52b516471ce5279c11bdd348d6c046414076011790291cb6e5c71a12edfa1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
:target: https://odoo-community.org/page/development-status
:alt: Alpha
.. |badge2| image:: https://img.shields.io/badge/licence-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/18.0/mail_thread_create_nolog
:alt: OCA/social
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/social-18-0/social-18-0-mail_thread_create_nolog
: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=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module will block the creation in the database of 'Record created'
messages on data models inheriting from mail.thread, but will instead
generate this message on the fly when Odoo displays the messages of a
record.

This allows to reduce the size of the mail_message table.

.. IMPORTANT::
This is an alpha version, the data model and design can change at any time without warning.
Only for development or testing purpose, do not use in production.
`More details on development status <https://odoo-community.org/page/development-status>`_

**Table of contents**

.. contents::
:local:

Known issues / Roadmap
======================

- Ability to configure the create_nolog context key by data model

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/social/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 <https://github.com/OCA/social/issues/new?body=module:%20mail_thread_create_nolog%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Credits
=======

Authors
-------

* Camptocamp

Contributors
------------

- `Camptocamp <https://www.camptocamp.com>`__:

- Sébastien Alix

- Chau Le chaulb@trobz.com

Other credits
-------------

The migration of this module from 14.0 to 18.0 was financially supported
by Camptocamp.

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.

.. |maintainer-sebalix| image:: https://github.com/sebalix.png?size=40px
:target: https://github.com/sebalix
:alt: sebalix

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-sebalix|

This module is part of the `OCA/social <https://github.com/OCA/social/tree/18.0/mail_thread_create_nolog>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions mail_thread_create_nolog/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from . import controllers
15 changes: 15 additions & 0 deletions mail_thread_create_nolog/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2023 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
{
"name": "Mail Thread - Fake create log",
"summary": "Display a fake (non-stored) create log in the chatter.",
"version": "18.0.1.0.0",
"category": "Mail",
"website": "https://github.com/OCA/social",
"author": "Camptocamp, Odoo Community Association (OCA)",
"maintainers": ["sebalix"],
"development_status": "Alpha",
"license": "AGPL-3",
"installable": True,
"depends": ["mail"],
}
1 change: 1 addition & 0 deletions mail_thread_create_nolog/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import thread
37 changes: 37 additions & 0 deletions mail_thread_create_nolog/controllers/thread.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from odoo import http
from odoo.http import request

from odoo.addons.mail.controllers import thread as mail_thread


class ThreadController(mail_thread.ThreadController):
@http.route("/mail/thread/messages", methods=["POST"], type="json", auth="user")
def mail_thread_messages(
self,
thread_model,
thread_id,
search_term=None,
before=None,
after=None,
around=None,
limit=30,
):
result = super().mail_thread_messages(

Check warning on line 19 in mail_thread_create_nolog/controllers/thread.py

View check run for this annotation

Codecov / codecov/patch

mail_thread_create_nolog/controllers/thread.py#L19

Added line #L19 was not covered by tests
thread_model, thread_id, search_term, before, after, around, limit
)

result["data"].setdefault("mail.message", [])

Check warning on line 23 in mail_thread_create_nolog/controllers/thread.py

View check run for this annotation

Codecov / codecov/patch

mail_thread_create_nolog/controllers/thread.py#L23

Added line #L23 was not covered by tests

domain = [

Check warning on line 25 in mail_thread_create_nolog/controllers/thread.py

View check run for this annotation

Codecov / codecov/patch

mail_thread_create_nolog/controllers/thread.py#L25

Added line #L25 was not covered by tests
("res_id", "=", int(thread_id)),
("model", "=", thread_model),
("message_type", "!=", "user_notification"),
]

message = request.env["mail.message"]._generate_messsage(domain)

Check warning on line 31 in mail_thread_create_nolog/controllers/thread.py

View check run for this annotation

Codecov / codecov/patch

mail_thread_create_nolog/controllers/thread.py#L31

Added line #L31 was not covered by tests

if message:
result["data"]["mail.message"].append(message)
result["messages"].append(message["id"])

Check warning on line 35 in mail_thread_create_nolog/controllers/thread.py

View check run for this annotation

Codecov / codecov/patch

mail_thread_create_nolog/controllers/thread.py#L34-L35

Added lines #L34 - L35 were not covered by tests

return result

Check warning on line 37 in mail_thread_create_nolog/controllers/thread.py

View check run for this annotation

Codecov / codecov/patch

mail_thread_create_nolog/controllers/thread.py#L37

Added line #L37 was not covered by tests
45 changes: 45 additions & 0 deletions mail_thread_create_nolog/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * mail_thread_create_nolog
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 14.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2024-01-28 17:33+0000\n"
"Last-Translator: Ivorra78 <informatica@totmaterial.es>\n"
"Language-Team: none\n"
"Language: es\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 4.17\n"

#. module: mail_thread_create_nolog
#: model:ir.model.fields,field_description:mail_thread_create_nolog.field_mail_message__display_name
#: model:ir.model.fields,field_description:mail_thread_create_nolog.field_mail_thread__display_name
msgid "Display Name"
msgstr "Mostrar Nombre"

#. module: mail_thread_create_nolog
#: model:ir.model,name:mail_thread_create_nolog.model_mail_thread
msgid "Email Thread"
msgstr "Hilo de Correo Electrónico"

#. module: mail_thread_create_nolog
#: model:ir.model.fields,field_description:mail_thread_create_nolog.field_mail_message__id
#: model:ir.model.fields,field_description:mail_thread_create_nolog.field_mail_thread__id
msgid "ID"
msgstr "ID"

#. module: mail_thread_create_nolog
#: model:ir.model.fields,field_description:mail_thread_create_nolog.field_mail_message____last_update
#: model:ir.model.fields,field_description:mail_thread_create_nolog.field_mail_thread____last_update
msgid "Last Modified on"
msgstr "Última Modificación el"

#. module: mail_thread_create_nolog
#: model:ir.model,name:mail_thread_create_nolog.model_mail_message
msgid "Message"
msgstr "Mensaje"
42 changes: 42 additions & 0 deletions mail_thread_create_nolog/i18n/mail_thread_create_nolog.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * mail_thread_create_nolog
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 14.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: mail_thread_create_nolog
#: model:ir.model.fields,field_description:mail_thread_create_nolog.field_mail_message__display_name
#: model:ir.model.fields,field_description:mail_thread_create_nolog.field_mail_thread__display_name
msgid "Display Name"
msgstr ""

#. module: mail_thread_create_nolog
#: model:ir.model,name:mail_thread_create_nolog.model_mail_thread
msgid "Email Thread"
msgstr ""

#. module: mail_thread_create_nolog
#: model:ir.model.fields,field_description:mail_thread_create_nolog.field_mail_message__id
#: model:ir.model.fields,field_description:mail_thread_create_nolog.field_mail_thread__id
msgid "ID"
msgstr ""

#. module: mail_thread_create_nolog
#: model:ir.model.fields,field_description:mail_thread_create_nolog.field_mail_message____last_update
#: model:ir.model.fields,field_description:mail_thread_create_nolog.field_mail_thread____last_update
msgid "Last Modified on"
msgstr ""

#. module: mail_thread_create_nolog
#: model:ir.model,name:mail_thread_create_nolog.model_mail_message
msgid "Message"
msgstr ""
2 changes: 2 additions & 0 deletions mail_thread_create_nolog/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import mail_thread
from . import mail_message
82 changes: 82 additions & 0 deletions mail_thread_create_nolog/models/mail_message.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Copyright 2023 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)

from odoo import api, models


class MailMessage(models.AbstractModel):
_inherit = "mail.message"

def _get_message_fields(self):
return [
"body",
"date",
"message_type",
"model",
"res_id",
]

@api.model
def _generate_messsage(self, domain):
# Generate a creation message only if messages are fetched for a record.
# In that case there is no specific record implied, so no need to generate the
# the message.
record = self._messages_for_record(domain)
author = record.create_uid.partner_id

if record and record._log_access:
creation_message = record._creation_message()
create_message_record = self.new(
{
"body": creation_message,
"date": record.create_date,
"model": record._name,
"res_id": record.id,
"message_type": "notification",
}
)

data = create_message_record._read_format(
self._get_message_fields(), load=False
)[0]

data.update(
{
# An ID is required by the thread client-side
# so we generate one that doesn't really exist
# but based on the current thread so it'll always be
# unique (used by the thread_cache client model).
"id": self._get_create_message_id(domain),
# Author is not preserved above when creating the fake-record
"author": {
"id": author.id,
"name": author.name,
"type": "partner",
},
}
)

return data

return None

def _get_create_message_id(self, domain):
# Odoo JS client needs an ID to manage its cache (thread_cache).
# Return the negative version of the greatest message ID
# of the current record so it's always unique.
return -self.search(domain, limit=1, order="id DESC").id

@api.model
def _messages_for_record(self, domain):
"""Return the record from the domain used in `message_fetch`."""
model = res_id = None
for part in domain:
if len(part) == 3 and part[0] == "model" and part[1] == "=":
model = part[2]
if len(part) == 3 and part[0] == "res_id" and part[1] == "=":
res_id = part[2]
if model and res_id:
break
if model and res_id:
return self.env[model].browse(res_id).exists()
return self.browse()
18 changes: 18 additions & 0 deletions mail_thread_create_nolog/models/mail_thread.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2023 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)

from odoo import api, models


class MailThread(models.AbstractModel):
_inherit = "mail.thread"

@api.model_create_multi
def create(self, vals_list):
# Overridden to not create 'Record created' messages that increase
# the size of 'mail_message' table for little value.
# Instead a message will be generated on the fly when the Odoo client
# will retrieve the list of messages for a given record.
return super(MailThread, self.with_context(mail_create_nolog=True)).create(
vals_list
)
3 changes: 3 additions & 0 deletions mail_thread_create_nolog/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
3 changes: 3 additions & 0 deletions mail_thread_create_nolog/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- [Camptocamp](https://www.camptocamp.com):
- Sébastien Alix
- Chau Le <chaulb@trobz.com>
1 change: 1 addition & 0 deletions mail_thread_create_nolog/readme/CREDITS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The migration of this module from 14.0 to 18.0 was financially supported by Camptocamp.
6 changes: 6 additions & 0 deletions mail_thread_create_nolog/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
This module will block the creation in the database of 'Record created'
messages on data models inheriting from mail.thread, but will instead
generate this message on the fly when Odoo displays the messages of a
record.

This allows to reduce the size of the mail_message table.
1 change: 1 addition & 0 deletions mail_thread_create_nolog/readme/ROADMAP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Ability to configure the create_nolog context key by data model
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading