Merge PR #930 into 15.0

Signed-off-by pedrobaeza
pull/1190/head
OCA-git-bot 2023-07-20 06:02:38 +00:00
commit 73a98496c1
9 changed files with 275 additions and 0 deletions

View File

@ -0,0 +1,79 @@
==========================================
Mail Activity Fetchmail with Team Activity
==========================================
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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/15.0/mail_activity_fetchmail
: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_activity_fetchmail
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/205/15.0
:alt: Try me on Runbot
|badge1| |badge2| |badge3| |badge4| |badge5|
**Table of contents**
.. contents::
:local:
Usage
=====
Uses mail.activity.team to configure automatic activities when mails arrive for the specified models.
The configuration to add RMA and PO models (Settings --> Technical --> Activity Teams menu).
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 smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/social/issues/new?body=module:%20mail_activity_fetchmail%0Aversion:%2015.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
~~~~~~~
* initOS GmbH
Contributors
~~~~~~~~~~~~
* isufi kapasi (isufi.kapasi@initos.com)
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 <https://github.com/OCA/social/tree/15.0/mail_activity_fetchmail>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

View File

@ -0,0 +1,4 @@
# © 2022 initOS GmbH
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import models

View File

@ -0,0 +1,22 @@
# © 2022 initOS GmbH
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Mail Activity on Fetchmail with Team Activity",
"version": "15.0.1.0.0",
"development_status": "Alpha",
"category": "Hidden",
"author": "initOS GmbH, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/social",
"license": "AGPL-3",
"summary": """
* Uses mail.activity.team to configure automatic activities when mails
arrive for the specified models.
* The configuration to add RMA and PO models
(Settings --> Technical --> Activity Teams menu)
""",
"depends": [
"mail_activity_team",
],
"installable": True,
}

View File

@ -0,0 +1,4 @@
# © 2022 initOS GmbH
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import mail_thread

View File

@ -0,0 +1,59 @@
# © 2022 initOS GmbH
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, models
class MailThread(models.AbstractModel):
_inherit = "mail.thread"
@api.model
def message_route(
self, message, message_dict, model=None, thread_id=None, custom_values=None
):
# Called by fetchmail module on mail.threads with received emails
routes = super().message_route(
message,
message_dict,
model=model,
thread_id=thread_id,
custom_values=custom_values,
)
for route in routes:
# routes: list of routes [(model, thread_id, custom_values, user_id, alias)]
model, thread_id = route[0], route[1]
mdl = self.env[model]
# Model needs mail.activity.mixin
if not all(hasattr(mdl, x) for x in ("activity_ids", "activity_schedule")):
continue
# Skip if there is no team
domain = [("res_model_ids.model", "=", model)]
team = self.env["mail.activity.team"].search(domain, limit=1)
user = team.user_id or team.member_ids
if not thread_id or not team or not user:
continue
thread = mdl.browse(thread_id)
# Only schedule if there is no email open email activity
activity_type = self.env.ref("mail.mail_activity_data_email")
domain = [
("res_model", "=", thread._name),
("res_id", "=", thread.id),
("automated", "=", True),
("activity_type_id", "=", activity_type.id),
]
if thread.activity_ids.search(domain):
continue
# Schedule the new email activity
thread.activity_schedule(
"mail.mail_activity_data_email",
user_id=user[0].id,
team_id=team.id,
automated=True,
)
return routes

View File

@ -0,0 +1,4 @@
# © 2022 initOS GmbH
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import test_activity

View File

@ -0,0 +1,96 @@
# © 2022 initOS GmbH
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import logging
import uuid
from odoo.fields import Command
from odoo.tests import TransactionCase
_logger = logging.getLogger(__name__)
class TestActivity(TransactionCase):
def generate_reply(self, message):
return (
# "Date: Thu, 22 Sep 2022 12:23:20 +0000",
"From: ext.partner@example.org\r\n"
"To: odoo.test@local\r\n"
f"Message-ID: {uuid.uuid4()}\r\n"
f"In-Reply-To: {message['message_id']}\r\n"
"Subject: Test Email Reply\r\n\r\n"
)
def test_no_team(self):
thread = self.env.user.partner_id
msg = thread.message_notify(
partner_ids=self.env.user.partner_id.ids,
body="Testing",
)
messages = thread.message_ids
activities = thread.activity_ids
reply = self.generate_reply(msg)
thread_id = thread.message_process(thread._name, reply)
self.assertTrue(len(messages) < len(thread.message_ids))
self.assertEqual(activities, thread.activity_ids)
self.assertEqual(thread_id, thread.id)
def test_with_team(self):
thread = self.env.user.partner_id
model = self.env.ref("base.model_res_partner")
self.env["mail.activity.team"].create(
{
"name": "Testing Team",
"res_model_ids": [Command.set(model.ids)],
"user_id": self.env.user.id,
}
)
msg = thread.message_notify(
partner_ids=self.env.user.partner_id.ids,
body="Testing",
)
messages = thread.message_ids
activities = thread.activity_ids
reply = self.generate_reply(msg)
thread_id = thread.message_process(thread._name, reply)
self.assertTrue(len(messages) < len(thread.message_ids))
self.assertEqual(thread_id, thread.id)
activity = thread.activity_ids - activities
self.assertTrue(activity)
self.assertEqual(
activity.activity_type_id,
self.env.ref("mail.mail_activity_data_email"),
)
# Schedule it only once
activities = thread.activity_ids
reply = self.generate_reply(msg)
thread.message_process(thread._name, reply)
self.assertEqual(activities, thread.activity_ids)
def test_with_team_no_activity_mixin(self):
thread = self.env["calendar.event"].create({"name": "Testing"})
model = self.env.ref("calendar.model_calendar_event")
self.env["mail.activity.team"].create(
{
"name": "Testing Team",
"res_model_ids": [Command.set(model.ids)],
"user_id": self.env.user.id,
}
)
msg = thread.message_notify(
partner_ids=self.env.user.partner_id.ids,
body="Testing",
)
activities = thread.activity_ids
reply = self.generate_reply(msg)
thread_id = thread.message_process(thread._name, reply)
self.assertEqual(activities, thread.activity_ids)
self.assertEqual(thread_id, thread.id)

View File

@ -0,0 +1 @@
../../../../fetchmail_mail_activity_team_activity

View File

@ -0,0 +1,6 @@
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)