[IMP] Added the possibility to indicate a server action to be executed

for the matching record.
pull/3071/head
Jose Zambudio Bernabeu 2024-07-23 12:02:13 +02:00 committed by Jose Zambudio
parent 1250087688
commit 383c633f60
15 changed files with 205 additions and 16 deletions

View File

@ -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

View File

@ -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",

View File

@ -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)"

View File

@ -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)"

View File

@ -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)"

View File

@ -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)"

View File

@ -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)"

View File

@ -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)"

View File

@ -12,8 +12,8 @@ msgstr ""
"PO-Revision-Date: 2024-05-29 16:35+0000\n"
"Last-Translator: Rodrigo Macedo <sottomaiormacedotec@users.noreply."
"translation.odoo-community.org>\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)"

View File

@ -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)"

View File

@ -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)"

View File

@ -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()

View File

@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
@ -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
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/server-tools/tree/16.0/fetchmail_attach_from_folder"><img alt="OCA/server-tools" src="https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/server-tools-16-0/server-tools-16-0-fetchmail_attach_from_folder"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/server-tools&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>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
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-10">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>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.</p>

View File

@ -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)

View File

@ -26,6 +26,7 @@
<field name="path" />
<field name="archive_path" />
<field name="model_id" />
<field name="action_id" />
<field name="match_algorithm" />
<field name="model_field" />
<field name="mail_field" />
@ -63,6 +64,7 @@
<group>
<field name="path" placeholder="INBOX.subfolder1" />
<field name="model_id" />
<field name="action_id" />
<field name="match_algorithm" />
</group>
<group