From 65b11cb363d095f9c89ca396ae4c4645213c4ba3 Mon Sep 17 00:00:00 2001 From: George Daramouskas Date: Thu, 24 Jan 2019 14:58:17 +0100 Subject: [PATCH] [ADD] Adds mail_thread_track_x2many module. --- mail_thread_track_x2many/README.rst | 75 ++++ mail_thread_track_x2many/__init__.py | 3 + mail_thread_track_x2many/__openerp__.py | 15 + mail_thread_track_x2many/i18n/de.po | 34 ++ mail_thread_track_x2many/models/__init__.py | 3 + .../models/mail_thread.py | 88 ++++ .../readme/CONTRIBUTORS.rst | 2 + .../readme/DESCRIPTION.rst | 2 + .../static/description/index.html | 399 ++++++++++++++++++ .../static/src/img/icon.png | Bin 0 -> 1142 bytes mail_thread_track_x2many/tests/__init__.py | 3 + .../tests/test_mail_thread.py | 82 ++++ 12 files changed, 706 insertions(+) create mode 100644 mail_thread_track_x2many/README.rst create mode 100644 mail_thread_track_x2many/__init__.py create mode 100644 mail_thread_track_x2many/__openerp__.py create mode 100644 mail_thread_track_x2many/i18n/de.po create mode 100644 mail_thread_track_x2many/models/__init__.py create mode 100644 mail_thread_track_x2many/models/mail_thread.py create mode 100644 mail_thread_track_x2many/readme/CONTRIBUTORS.rst create mode 100644 mail_thread_track_x2many/readme/DESCRIPTION.rst create mode 100644 mail_thread_track_x2many/static/description/index.html create mode 100644 mail_thread_track_x2many/static/src/img/icon.png create mode 100644 mail_thread_track_x2many/tests/__init__.py create mode 100644 mail_thread_track_x2many/tests/test_mail_thread.py diff --git a/mail_thread_track_x2many/README.rst b/mail_thread_track_x2many/README.rst new file mode 100644 index 00000000..6b0f3da2 --- /dev/null +++ b/mail_thread_track_x2many/README.rst @@ -0,0 +1,75 @@ +=============================== +Mail Thread track x2many fields +=============================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/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%2Fcrm-lightgray.png?logo=github + :target: https://github.com/OCA/crm/tree/8.0/mail_thread_track_x2many + :alt: OCA/crm +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/crm-8-0/crm-8-0-mail_thread_track_x2many + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/111/8.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Mail thread does not do a good job tracking changes on x2many fields, this +module fixes that. + +**Table of contents** + +.. contents:: + :local: + +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 smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Therp BV + +Contributors +~~~~~~~~~~~~ + +* Holger Brunn +* George Daramouskas + +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/crm `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/mail_thread_track_x2many/__init__.py b/mail_thread_track_x2many/__init__.py new file mode 100644 index 00000000..9732283c --- /dev/null +++ b/mail_thread_track_x2many/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from . import models diff --git a/mail_thread_track_x2many/__openerp__.py b/mail_thread_track_x2many/__openerp__.py new file mode 100644 index 00000000..cb4df324 --- /dev/null +++ b/mail_thread_track_x2many/__openerp__.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# Copyright 2018 Therp BV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +{ + 'name': 'Mail Thread track x2many fields', + 'version': '8.0.1.0.0', + 'author': 'Therp BV,Odoo Community Association (OCA)', + 'license': 'AGPL-3', + 'category': 'Customer Relationship Management', + 'depends': [ + 'mail', + ], + 'installable': True, + 'application': False, +} diff --git a/mail_thread_track_x2many/i18n/de.po b/mail_thread_track_x2many/i18n/de.po new file mode 100644 index 00000000..4fff25c1 --- /dev/null +++ b/mail_thread_track_x2many/i18n/de.po @@ -0,0 +1,34 @@ +# Translation of OpenERP Server. +# This file contains the translation of the following modules: +# * mail_thread_track_x2many +# +msgid "" +msgstr "" +"Project-Id-Version: OpenERP Server 7.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2013-11-23 15:59+0000\n" +"PO-Revision-Date: 2013-11-23 15:59+0000\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_track_x2many +#: code:addons/mail_thread_track_x2many/model/mail_thread.py:79 +#, python-format +msgid "Changed %s: %s" +msgstr "Anpassung %s: %s" + +#. module: mail_thread_track_x2many +#: code:addons/mail_thread_track_x2many/model/mail_thread.py:84 +#, python-format +msgid "Deleted a line" +msgstr "Eine Zeile wurde gelöscht." + +#. module: mail_thread_track_x2many +#: code:addons/mail_thread_track_x2many/model/mail_thread.py:75 +#, python-format +msgid "Added: %s" +msgstr "Zeile hinzugefügt: %s" diff --git a/mail_thread_track_x2many/models/__init__.py b/mail_thread_track_x2many/models/__init__.py new file mode 100644 index 00000000..da69d3b6 --- /dev/null +++ b/mail_thread_track_x2many/models/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from . import mail_thread diff --git a/mail_thread_track_x2many/models/mail_thread.py b/mail_thread_track_x2many/models/mail_thread.py new file mode 100644 index 00000000..f5e18a82 --- /dev/null +++ b/mail_thread_track_x2many/models/mail_thread.py @@ -0,0 +1,88 @@ +# -*- coding: utf-8 -*- +# Copyright 2018 Therp BV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from openerp import api, models, _ + + +class MailThread(models.AbstractModel): + _inherit = 'mail.thread' + + @api.model + def _get_tracked_fields( + self, + updated_fields, + suppress_x2many=True): + result = super(MailThread, self)._get_tracked_fields( + updated_fields) + if not result: + return result + return dict(filter( + lambda (y, x): not suppress_x2many + or x['type'] not in ['one2many', 'many2many'], + result.iteritems())) + + def _format_value_dict(self, col_info, values_id, values): + relation_model = self.env[col_info['relation']] + relation_model_fields = relation_model.fields_get(values.keys()) + message = '' + for field, value in values.iteritems(): + message += '
' + if relation_model_fields[field]['type'] in [ + 'many2one', 'many2many', 'one2many']: + field_model = relation_model_fields[field]['relation'] + if isinstance(value, tuple): + value = value[0] + value = self.env[field_model].browse(value).name_get() + message += '%s → %s' % ( + relation_model_fields[field]['string'], value) + record_name = '' + record = relation_model.browse(values_id) + for (__, name) in record.name_get(): + record_name = name + return record_name, message + + @api.multi + def write(self, values): + x2many_fields = dict(filter( + lambda (y, x): x['type'] in ['one2many', 'many2many'] + and y in values, + (self._get_tracked_fields( + values.keys(), + suppress_x2many=False) or {}).iteritems())) + if x2many_fields: + message = '
    ' + for field in x2many_fields: + message += '
  • %s
      ' % x2many_fields[field].get('string', + field) + for value in values[field]: + if value[0] in [3, 4, 5, 6]: + continue + message += '
    • ' + if value[0] == 0: + message += _('Added: %s') % self._format_value_dict( + x2many_fields[field], + value[1], + value[2])[1] + elif value[0] == 1: + message += _('Changed %s: %s') % self\ + ._format_value_dict( + x2many_fields[field], + value[1], + value[2]) + elif value[0] == 2: + deleted_line_model = getattr(self, field)._name + fields = self.env[deleted_line_model]._fields.keys() + fields = self.env[deleted_line_model].browse( + value[1]).read(fields) + message += _('Deleted: %s') % self._format_value_dict({ + 'relation': deleted_line_model}, + value[1], + fields[0], + )[1] + else: + message += '%s' % str(value) + message += '
    • ' + message += '
  • ' + message += '
' + self.message_post(body=message) + return super(MailThread, self).write(values) diff --git a/mail_thread_track_x2many/readme/CONTRIBUTORS.rst b/mail_thread_track_x2many/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..2dd986b7 --- /dev/null +++ b/mail_thread_track_x2many/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Holger Brunn +* George Daramouskas diff --git a/mail_thread_track_x2many/readme/DESCRIPTION.rst b/mail_thread_track_x2many/readme/DESCRIPTION.rst new file mode 100644 index 00000000..42efcc5a --- /dev/null +++ b/mail_thread_track_x2many/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +Mail thread does not do a good job tracking changes on x2many fields, this +module fixes that. diff --git a/mail_thread_track_x2many/static/description/index.html b/mail_thread_track_x2many/static/description/index.html new file mode 100644 index 00000000..2dc447d2 --- /dev/null +++ b/mail_thread_track_x2many/static/description/index.html @@ -0,0 +1,399 @@ + + + + + + +Mail Thread track x2many fields + + + +
+

Mail Thread track x2many fields

+ + +

Beta License: AGPL-3 OCA/crm Translate me on Weblate Try me on Runbot

+

Mail thread does not do a good job tracking changes on x2many fields, this +module fixes that.

+

Table of contents

+ +
+

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 smashing it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Therp BV
  • +
+
+
+

Contributors

+ +
+
+

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/crm project on GitHub.

+

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

+
+
+
+ + diff --git a/mail_thread_track_x2many/static/src/img/icon.png b/mail_thread_track_x2many/static/src/img/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..4c7ab302908e114888446d84d3493fa726033c1f GIT binary patch literal 1142 zcmeAS@N?(olHy`uVBq!ia0vp^0U*r53?z4+XPOVBSkfJR9T^xl_H+M9WCijWi-X*q z7}lMWc?skwBzpw;GB8xBF)%c=FfjZA3N^f7U???UV0e|lz+g3lfkC`r&aOZkpuXS$ zpAc7|0+Vy!%`Sd3J@*~Rz=H@Xz@vBMNCCrhU++~OAXQKjgnPb5^?zLm6yRy4l)f7mx|d; zx?*(k%?4)UEmyi0Ecrc2=k&YFn|8nX@qd4)(saLN%zo##oL4V9SpH%8W(I{5_Kby- zneS~VhopAyb6lBS&$U5E`gKppbdV7NQIC+SE zKe2ts8LoR*Hw$jqcIEDHSU_mi4;HoUDLTgOJMIHx zO|`@|q9i4;B-JXpC>2OC7#SEE>l#?<8d`)H8e5qfSQ#5>8yHy`7 +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from mock import patch +from openerp.tests.common import SingleTransactionCase + +FIELD_DESCRIPTION = { + 'test_field_ids': { + 'type': 'one2many', + 'relation': 'mail.thread', + 'string': 'test', + }, + 'test_field2_ids': { + 'type': 'many2many', + 'relation': 'mail.thread', + 'string': 'test2', + }, +} + + +class TestMailThread(SingleTransactionCase): + + post_install = True + at_install = False + + @patch( + 'openerp.addons.mail.mail_thread.mail_thread._get_tracked_fields', + new=lambda *args, **kwargs: FIELD_DESCRIPTION + ) + @patch( + 'openerp.addons.mail.mail_thread.mail_thread.fields_get', + new=lambda *args, **kwargs: FIELD_DESCRIPTION, + ) + def test_write(self, mock_obj=None): + mail_thread_model = self.env['mail.thread'] + mail_message_model = self.env['mail.message'] + mail_thread = mail_thread_model.create({}) + mail_thread.write({ # non-existant fields, that's ok. + 'test_field_ids': [(6, 0, [10])], + 'test_field2_ids': [(6, 0, [10])]}) + mail_message = mail_message_model.search( + [], + order='id DESC', + limit=1, + ) + self.assertEquals( + mail_message.body, + '
  • test
    • test2
      ' + ) + + mail_thread.write({ + 'test_field_ids': [( + 0, + 0, + {'test_field_ids': {'field1': 'value1'}}, + )], + }) + mail_message = mail_message_model.search( + [], + order='id DESC', + limit=1, + ) + self.assertEquals( + mail_message.body, + "
      • test
        • Added: test \u2192 {'field1': 'value1'}
        • " + "
      ".decode('unicode-escape'), + ) + + mail_thread.write({ + 'test_field_ids': [ + (1, 0, {'test_field_ids': {'field1': 'value2'}})], + }) + mail_message = mail_message_model.search( + [], + order='id DESC', + limit=1, + ) + self.assertEquals( + mail_message.body, + "
      • test
        • Changed : test \u2192 {'field1': 'value2'}" + "
      ".decode('unicode-escape'), + )