From 383c633f608fdfaf1df3cda1b655eef8ed02c72f Mon Sep 17 00:00:00 2001 From: Jose Zambudio Bernabeu Date: Tue, 23 Jul 2024 12:02:13 +0200 Subject: [PATCH] [IMP] Added the possibility to indicate a server action to be executed for the matching record. --- fetchmail_attach_from_folder/README.rst | 2 +- fetchmail_attach_from_folder/__manifest__.py | 2 +- fetchmail_attach_from_folder/i18n/de.po | 12 ++++ fetchmail_attach_from_folder/i18n/es.po | 12 ++++ .../i18n/fetchmail_attach_from_folder.pot | 12 ++++ fetchmail_attach_from_folder/i18n/fr.po | 12 ++++ fetchmail_attach_from_folder/i18n/fr_CA.po | 12 ++++ fetchmail_attach_from_folder/i18n/it.po | 12 ++++ fetchmail_attach_from_folder/i18n/pt_BR.po | 16 +++++- fetchmail_attach_from_folder/i18n/ru.po | 18 +++++- fetchmail_attach_from_folder/i18n/sl.po | 16 +++++- .../models/fetchmail_server_folder.py | 24 ++++++++ .../static/description/index.html | 14 +++-- .../tests/test_match_algorithms.py | 55 ++++++++++++++++++- .../views/fetchmail_server.xml | 2 + 15 files changed, 205 insertions(+), 16 deletions(-) diff --git a/fetchmail_attach_from_folder/README.rst b/fetchmail_attach_from_folder/README.rst index 4df7f2415..2a61cdf35 100644 --- a/fetchmail_attach_from_folder/README.rst +++ b/fetchmail_attach_from_folder/README.rst @@ -7,7 +7,7 @@ Email gateway - folders !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !! source digest: sha256:c6afe0f3176202f575e0bfd827acadf557acced4a2dccdb2a55dafc0337abc87 + !! source digest: sha256:c3af3dec7c2b9f46c88cd4355883c08deb3d7c03e21735f2f1b5ca4131aa7e69 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png diff --git a/fetchmail_attach_from_folder/__manifest__.py b/fetchmail_attach_from_folder/__manifest__.py index 4313306f0..2fbb4ca32 100644 --- a/fetchmail_attach_from_folder/__manifest__.py +++ b/fetchmail_attach_from_folder/__manifest__.py @@ -3,7 +3,7 @@ { "name": "Email gateway - folders", "summary": "Attach mails in an IMAP folder to existing objects", - "version": "16.0.1.1.0", + "version": "16.0.1.3.0", "author": "Therp BV,Odoo Community Association (OCA)", "maintainers": ["NL66278"], "website": "https://github.com/OCA/server-tools", diff --git a/fetchmail_attach_from_folder/i18n/de.po b/fetchmail_attach_from_folder/i18n/de.po index ad5030c3e..422af7e49 100644 --- a/fetchmail_attach_from_folder/i18n/de.po +++ b/fetchmail_attach_from_folder/i18n/de.po @@ -18,6 +18,11 @@ msgstr "" "Content-Transfer-Encoding: \n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" +#. module: fetchmail_attach_from_folder +#: model:ir.model.fields,field_description:fetchmail_attach_from_folder.field_fetchmail_server_folder__action_id +msgid "Action" +msgstr "" + #. module: fetchmail_attach_from_folder #: model:ir.model.fields,field_description:fetchmail_attach_from_folder.field_fetchmail_server_folder__active msgid "Active" @@ -386,6 +391,13 @@ msgstr "" msgid "Only folders, not inbox" msgstr "" +#. module: fetchmail_attach_from_folder +#: model:ir.model.fields,help:fetchmail_attach_from_folder.field_fetchmail_server_folder__action_id +msgid "" +"Optional custom server action to trigger for each incoming mail, on the " +"record that was created or updated by this mail" +msgstr "" + #. module: fetchmail_attach_from_folder #: model:ir.model.fields,field_description:fetchmail_attach_from_folder.field_fetchmail_server_folder__model_order msgid "Order (model)" diff --git a/fetchmail_attach_from_folder/i18n/es.po b/fetchmail_attach_from_folder/i18n/es.po index 9dbdf49c8..bf37dcbb8 100644 --- a/fetchmail_attach_from_folder/i18n/es.po +++ b/fetchmail_attach_from_folder/i18n/es.po @@ -18,6 +18,11 @@ msgstr "" "Content-Transfer-Encoding: \n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" +#. module: fetchmail_attach_from_folder +#: model:ir.model.fields,field_description:fetchmail_attach_from_folder.field_fetchmail_server_folder__action_id +msgid "Action" +msgstr "" + #. module: fetchmail_attach_from_folder #: model:ir.model.fields,field_description:fetchmail_attach_from_folder.field_fetchmail_server_folder__active msgid "Active" @@ -386,6 +391,13 @@ msgstr "" msgid "Only folders, not inbox" msgstr "" +#. module: fetchmail_attach_from_folder +#: model:ir.model.fields,help:fetchmail_attach_from_folder.field_fetchmail_server_folder__action_id +msgid "" +"Optional custom server action to trigger for each incoming mail, on the " +"record that was created or updated by this mail" +msgstr "" + #. module: fetchmail_attach_from_folder #: model:ir.model.fields,field_description:fetchmail_attach_from_folder.field_fetchmail_server_folder__model_order msgid "Order (model)" diff --git a/fetchmail_attach_from_folder/i18n/fetchmail_attach_from_folder.pot b/fetchmail_attach_from_folder/i18n/fetchmail_attach_from_folder.pot index fd5cfc23f..07c6838ec 100644 --- a/fetchmail_attach_from_folder/i18n/fetchmail_attach_from_folder.pot +++ b/fetchmail_attach_from_folder/i18n/fetchmail_attach_from_folder.pot @@ -13,6 +13,11 @@ msgstr "" "Content-Transfer-Encoding: \n" "Plural-Forms: \n" +#. module: fetchmail_attach_from_folder +#: model:ir.model.fields,field_description:fetchmail_attach_from_folder.field_fetchmail_server_folder__action_id +msgid "Action" +msgstr "" + #. module: fetchmail_attach_from_folder #: model:ir.model.fields,field_description:fetchmail_attach_from_folder.field_fetchmail_server_folder__active msgid "Active" @@ -380,6 +385,13 @@ msgstr "" msgid "Only folders, not inbox" msgstr "" +#. module: fetchmail_attach_from_folder +#: model:ir.model.fields,help:fetchmail_attach_from_folder.field_fetchmail_server_folder__action_id +msgid "" +"Optional custom server action to trigger for each incoming mail, on the " +"record that was created or updated by this mail" +msgstr "" + #. module: fetchmail_attach_from_folder #: model:ir.model.fields,field_description:fetchmail_attach_from_folder.field_fetchmail_server_folder__model_order msgid "Order (model)" diff --git a/fetchmail_attach_from_folder/i18n/fr.po b/fetchmail_attach_from_folder/i18n/fr.po index 037275f0d..068eb2d2e 100644 --- a/fetchmail_attach_from_folder/i18n/fr.po +++ b/fetchmail_attach_from_folder/i18n/fr.po @@ -18,6 +18,11 @@ msgstr "" "Content-Transfer-Encoding: \n" "Plural-Forms: nplurals=2; plural=(n > 1);\n" +#. module: fetchmail_attach_from_folder +#: model:ir.model.fields,field_description:fetchmail_attach_from_folder.field_fetchmail_server_folder__action_id +msgid "Action" +msgstr "" + #. module: fetchmail_attach_from_folder #: model:ir.model.fields,field_description:fetchmail_attach_from_folder.field_fetchmail_server_folder__active msgid "Active" @@ -386,6 +391,13 @@ msgstr "" msgid "Only folders, not inbox" msgstr "" +#. module: fetchmail_attach_from_folder +#: model:ir.model.fields,help:fetchmail_attach_from_folder.field_fetchmail_server_folder__action_id +msgid "" +"Optional custom server action to trigger for each incoming mail, on the " +"record that was created or updated by this mail" +msgstr "" + #. module: fetchmail_attach_from_folder #: model:ir.model.fields,field_description:fetchmail_attach_from_folder.field_fetchmail_server_folder__model_order msgid "Order (model)" diff --git a/fetchmail_attach_from_folder/i18n/fr_CA.po b/fetchmail_attach_from_folder/i18n/fr_CA.po index 1a38baca3..cb90909c7 100644 --- a/fetchmail_attach_from_folder/i18n/fr_CA.po +++ b/fetchmail_attach_from_folder/i18n/fr_CA.po @@ -18,6 +18,11 @@ msgstr "" "Content-Transfer-Encoding: \n" "Plural-Forms: nplurals=2; plural=(n > 1);\n" +#. module: fetchmail_attach_from_folder +#: model:ir.model.fields,field_description:fetchmail_attach_from_folder.field_fetchmail_server_folder__action_id +msgid "Action" +msgstr "" + #. module: fetchmail_attach_from_folder #: model:ir.model.fields,field_description:fetchmail_attach_from_folder.field_fetchmail_server_folder__active msgid "Active" @@ -385,6 +390,13 @@ msgstr "" msgid "Only folders, not inbox" msgstr "" +#. module: fetchmail_attach_from_folder +#: model:ir.model.fields,help:fetchmail_attach_from_folder.field_fetchmail_server_folder__action_id +msgid "" +"Optional custom server action to trigger for each incoming mail, on the " +"record that was created or updated by this mail" +msgstr "" + #. module: fetchmail_attach_from_folder #: model:ir.model.fields,field_description:fetchmail_attach_from_folder.field_fetchmail_server_folder__model_order msgid "Order (model)" diff --git a/fetchmail_attach_from_folder/i18n/it.po b/fetchmail_attach_from_folder/i18n/it.po index 7a0ac51df..0040ddded 100644 --- a/fetchmail_attach_from_folder/i18n/it.po +++ b/fetchmail_attach_from_folder/i18n/it.po @@ -19,6 +19,11 @@ msgstr "" "Plural-Forms: nplurals=2; plural=n != 1;\n" "X-Generator: Weblate 4.17\n" +#. module: fetchmail_attach_from_folder +#: model:ir.model.fields,field_description:fetchmail_attach_from_folder.field_fetchmail_server_folder__action_id +msgid "Action" +msgstr "" + #. module: fetchmail_attach_from_folder #: model:ir.model.fields,field_description:fetchmail_attach_from_folder.field_fetchmail_server_folder__active msgid "Active" @@ -386,6 +391,13 @@ msgstr "" msgid "Only folders, not inbox" msgstr "" +#. module: fetchmail_attach_from_folder +#: model:ir.model.fields,help:fetchmail_attach_from_folder.field_fetchmail_server_folder__action_id +msgid "" +"Optional custom server action to trigger for each incoming mail, on the " +"record that was created or updated by this mail" +msgstr "" + #. module: fetchmail_attach_from_folder #: model:ir.model.fields,field_description:fetchmail_attach_from_folder.field_fetchmail_server_folder__model_order msgid "Order (model)" diff --git a/fetchmail_attach_from_folder/i18n/pt_BR.po b/fetchmail_attach_from_folder/i18n/pt_BR.po index 0ed68e388..421c24180 100644 --- a/fetchmail_attach_from_folder/i18n/pt_BR.po +++ b/fetchmail_attach_from_folder/i18n/pt_BR.po @@ -12,8 +12,8 @@ msgstr "" "PO-Revision-Date: 2024-05-29 16:35+0000\n" "Last-Translator: Rodrigo Macedo \n" -"Language-Team: Portuguese (Brazil) (http://www.transifex.com/oca/" -"OCA-server-tools-8-0/language/pt_BR/)\n" +"Language-Team: Portuguese (Brazil) (http://www.transifex.com/oca/OCA-server-" +"tools-8-0/language/pt_BR/)\n" "Language: pt_BR\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" @@ -21,6 +21,11 @@ msgstr "" "Plural-Forms: nplurals=2; plural=n > 1;\n" "X-Generator: Weblate 4.17\n" +#. module: fetchmail_attach_from_folder +#: model:ir.model.fields,field_description:fetchmail_attach_from_folder.field_fetchmail_server_folder__action_id +msgid "Action" +msgstr "" + #. module: fetchmail_attach_from_folder #: model:ir.model.fields,field_description:fetchmail_attach_from_folder.field_fetchmail_server_folder__active msgid "Active" @@ -393,6 +398,13 @@ msgstr "" msgid "Only folders, not inbox" msgstr "" +#. module: fetchmail_attach_from_folder +#: model:ir.model.fields,help:fetchmail_attach_from_folder.field_fetchmail_server_folder__action_id +msgid "" +"Optional custom server action to trigger for each incoming mail, on the " +"record that was created or updated by this mail" +msgstr "" + #. module: fetchmail_attach_from_folder #: model:ir.model.fields,field_description:fetchmail_attach_from_folder.field_fetchmail_server_folder__model_order msgid "Order (model)" diff --git a/fetchmail_attach_from_folder/i18n/ru.po b/fetchmail_attach_from_folder/i18n/ru.po index 63ae65c9e..de228435c 100644 --- a/fetchmail_attach_from_folder/i18n/ru.po +++ b/fetchmail_attach_from_folder/i18n/ru.po @@ -16,9 +16,14 @@ msgstr "" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: \n" -"Plural-Forms: nplurals=4; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" -"%10<=4 && (n%100<12 || n%100>14) ? 1 : n%10==0 || (n%10>=5 && n%10<=9) || (n" -"%100>=11 && n%100<=14)? 2 : 3);\n" +"Plural-Forms: nplurals=4; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && " +"n%10<=4 && (n%100<12 || n%100>14) ? 1 : n%10==0 || (n%10>=5 && n%10<=9) || " +"(n%100>=11 && n%100<=14)? 2 : 3);\n" + +#. module: fetchmail_attach_from_folder +#: model:ir.model.fields,field_description:fetchmail_attach_from_folder.field_fetchmail_server_folder__action_id +msgid "Action" +msgstr "" #. module: fetchmail_attach_from_folder #: model:ir.model.fields,field_description:fetchmail_attach_from_folder.field_fetchmail_server_folder__active @@ -387,6 +392,13 @@ msgstr "" msgid "Only folders, not inbox" msgstr "" +#. module: fetchmail_attach_from_folder +#: model:ir.model.fields,help:fetchmail_attach_from_folder.field_fetchmail_server_folder__action_id +msgid "" +"Optional custom server action to trigger for each incoming mail, on the " +"record that was created or updated by this mail" +msgstr "" + #. module: fetchmail_attach_from_folder #: model:ir.model.fields,field_description:fetchmail_attach_from_folder.field_fetchmail_server_folder__model_order msgid "Order (model)" diff --git a/fetchmail_attach_from_folder/i18n/sl.po b/fetchmail_attach_from_folder/i18n/sl.po index 40b89bfca..380f62469 100644 --- a/fetchmail_attach_from_folder/i18n/sl.po +++ b/fetchmail_attach_from_folder/i18n/sl.po @@ -17,8 +17,13 @@ msgstr "" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: \n" -"Plural-Forms: nplurals=4; plural=(n%100==1 ? 0 : n%100==2 ? 1 : n%100==3 || n" -"%100==4 ? 2 : 3);\n" +"Plural-Forms: nplurals=4; plural=(n%100==1 ? 0 : n%100==2 ? 1 : n%100==3 || " +"n%100==4 ? 2 : 3);\n" + +#. module: fetchmail_attach_from_folder +#: model:ir.model.fields,field_description:fetchmail_attach_from_folder.field_fetchmail_server_folder__action_id +msgid "Action" +msgstr "" #. module: fetchmail_attach_from_folder #: model:ir.model.fields,field_description:fetchmail_attach_from_folder.field_fetchmail_server_folder__active @@ -394,6 +399,13 @@ msgstr "" msgid "Only folders, not inbox" msgstr "" +#. module: fetchmail_attach_from_folder +#: model:ir.model.fields,help:fetchmail_attach_from_folder.field_fetchmail_server_folder__action_id +msgid "" +"Optional custom server action to trigger for each incoming mail, on the " +"record that was created or updated by this mail" +msgstr "" + #. module: fetchmail_attach_from_folder #: model:ir.model.fields,field_description:fetchmail_attach_from_folder.field_fetchmail_server_folder__model_order msgid "Order (model)" diff --git a/fetchmail_attach_from_folder/models/fetchmail_server_folder.py b/fetchmail_attach_from_folder/models/fetchmail_server_folder.py index 6f6e64d04..3e351fb36 100644 --- a/fetchmail_attach_from_folder/models/fetchmail_server_folder.py +++ b/fetchmail_attach_from_folder/models/fetchmail_server_folder.py @@ -91,6 +91,12 @@ class FetchmailServerFolder(models.Model): help="The state messages fetched from this folder should be assigned in Odoo", ) active = fields.Boolean(default=True) + action_id = fields.Many2one( + comodel_name="ir.actions.server", + name="Server action", + help="Optional custom server action to trigger for each incoming " + "mail, on the record that was created or updated by this mail", + ) def button_confirm_folder(self): self.write({"state": "draft"}) @@ -227,11 +233,29 @@ class FetchmailServerFolder(models.Model): thread_id = match.id self.attach_mail(match, message_dict) matched = True if thread_id else False + if matched: + self.run_server_action(thread_id) self.update_msg(connection, msgid, matched=matched) if self.archive_path: self._archive_msg(connection, msgid) return thread_id # Can be None if no match found. + def run_server_action(self, matched_object_ids): + action = self.action_id + if not action: + return + records = self.env[self.model_id.model].browse(matched_object_ids) + for record in records: + if not record.exists(): + continue + action.with_context( + **{ + "active_id": record.id, + "active_ids": record.ids, + "active_model": self.model_id.model, + } + ).run() + def fetch_msg(self, connection, msgid): """Select a single message from a folder.""" self.ensure_one() diff --git a/fetchmail_attach_from_folder/static/description/index.html b/fetchmail_attach_from_folder/static/description/index.html index 3c1707bd5..7fcdda0ac 100644 --- a/fetchmail_attach_from_folder/static/description/index.html +++ b/fetchmail_attach_from_folder/static/description/index.html @@ -1,4 +1,3 @@ - @@ -9,10 +8,11 @@ /* :Author: David Goodger (goodger@python.org) -:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $ +:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $ :Copyright: This stylesheet has been placed in the public domain. Default cascading style sheet for the HTML output of Docutils. +Despite the name, some widely supported CSS2 features are used. See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to customize this style sheet. @@ -275,7 +275,7 @@ pre.literal-block, pre.doctest-block, pre.math, pre.code { margin-left: 2em ; margin-right: 2em } -pre.code .ln { color: grey; } /* line numbers */ +pre.code .ln { color: gray; } /* line numbers */ pre.code, code { background-color: #eeeeee } pre.code .comment, code .comment { color: #5C6576 } pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold } @@ -301,7 +301,7 @@ span.option { span.pre { white-space: pre } -span.problematic { +span.problematic, pre.problematic { color: red } span.section-subtitle { @@ -367,7 +367,7 @@ ul.auto-toc { !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!! source digest: sha256:c6afe0f3176202f575e0bfd827acadf557acced4a2dccdb2a55dafc0337abc87 +!! source digest: sha256:c3af3dec7c2b9f46c88cd4355883c08deb3d7c03e21735f2f1b5ca4131aa7e69 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

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

Adds the possibility to attach emails from a certain IMAP folder to @@ -469,7 +469,9 @@ If you spotted it first, help us to smash it by providing a detailed and welcome

Maintainers

This module is maintained by the OCA.

-Odoo Community Association + +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.

diff --git a/fetchmail_attach_from_folder/tests/test_match_algorithms.py b/fetchmail_attach_from_folder/tests/test_match_algorithms.py index 04018f42b..bdd406c37 100644 --- a/fetchmail_attach_from_folder/tests/test_match_algorithms.py +++ b/fetchmail_attach_from_folder/tests/test_match_algorithms.py @@ -56,7 +56,14 @@ class TestMatchAlgorithms(TransactionCase): cls.partner_model = cls.env["res.partner"] cls.test_partner = cls.partner_model.with_context(tracking_disable=True).create( - {"name": "Reynaert de Vos", "email": TEST_EMAIL, "is_company": False} + { + "name": "Reynaert de Vos", + "email": TEST_EMAIL, + "is_company": False, + "category_id": [ + (6, 0, []), + ], + } ) cls.server_model = cls.env["fetchmail.server"] cls.folder_model = cls.env["fetchmail.server.folder"] @@ -81,6 +88,40 @@ class TestMatchAlgorithms(TransactionCase): "mail_field": "from", } ) + cls.partner_ir_model = cls.env["ir.model"].search( + [ + ("model", "=", cls.partner_model._name), + ], + limit=1, + ) + cls.partner_category = cls.env.ref("base.res_partner_category_12") + cls.server_action = cls.env["ir.actions.server"].create( + { + "name": "Action Set Active Partner", + "model_id": cls.partner_ir_model.id, + "state": "object_write", + "code": False, + "fields_lines": [ + ( + 0, + 0, + { + "col1": cls.env["ir.model.fields"] + .search( + [ + ("name", "=", "category_id"), + ("model_id", "=", cls.partner_ir_model.id), + ], + limit=1, + ) + .id, + "evaluation_type": "equation", + "value": str([cls.partner_category.id]), + }, + ), + ], + } + ) def test_email_exact(self): """A message to ronald@acme.com should be linked to partner with that email.""" @@ -122,3 +163,15 @@ class TestMatchAlgorithms(TransactionCase): folder.match_algorithm = "email_domain" connection = MockConnection() folder.retrieve_imap_folder(connection) + + def test_non_action(self): + connection = MockConnection() + self.folder.action_id = False + self.folder.apply_matching(connection, "1") + self.assertFalse(self.test_partner.category_id) + + def test_action(self): + connection = MockConnection() + self.folder.action_id = self.server_action + self.folder.apply_matching(connection, "1") + self.assertEqual(self.partner_category, self.test_partner.category_id) diff --git a/fetchmail_attach_from_folder/views/fetchmail_server.xml b/fetchmail_attach_from_folder/views/fetchmail_server.xml index 4748da163..cd2baf067 100644 --- a/fetchmail_attach_from_folder/views/fetchmail_server.xml +++ b/fetchmail_attach_from_folder/views/fetchmail_server.xml @@ -26,6 +26,7 @@ + @@ -63,6 +64,7 @@ +