mirror of https://github.com/OCA/social.git
commit
384c05de21
|
@ -0,0 +1,75 @@
|
||||||
|
=======================
|
||||||
|
Partner Mail Forwarding
|
||||||
|
=======================
|
||||||
|
|
||||||
|
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
!! This file is generated by oca-gen-addon-readme !!
|
||||||
|
!! changes will be overwritten. !!
|
||||||
|
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
|
||||||
|
.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png
|
||||||
|
:target: https://odoo-community.org/page/development-status
|
||||||
|
:alt: Production/Stable
|
||||||
|
.. |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/13.0/mail_debrand
|
||||||
|
:alt: OCA/social
|
||||||
|
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
|
||||||
|
:target: https://translation.odoo-community.org/projects/social-13-0/social-13-0-mail_debrand
|
||||||
|
: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/13.0
|
||||||
|
:alt: Try me on Runbot
|
||||||
|
|
||||||
|
|badge1| |badge2| |badge3| |badge4| |badge5|
|
||||||
|
|
||||||
|
This module allows to select a related partner (called "Forwarding Partner") in each partner in order to send all the notifications
|
||||||
|
to the Forwarding Partner.
|
||||||
|
|
||||||
|
|
||||||
|
**Table of contents**
|
||||||
|
|
||||||
|
.. contents::
|
||||||
|
:local:
|
||||||
|
|
||||||
|
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_debrand%0Aversion:%2013.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
|
||||||
|
~~~~~~~
|
||||||
|
|
||||||
|
* AdHoc SA
|
||||||
|
|
||||||
|
Contributors
|
||||||
|
~~~~~~~~~~~~
|
||||||
|
|
||||||
|
* Nicolás Mac Rouillon <nmr@adhoc.com.ar>
|
||||||
|
|
||||||
|
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/13.0/mail_backup_user>`_ project on GitHub.
|
||||||
|
|
||||||
|
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
|
|
@ -0,0 +1 @@
|
||||||
|
from . import models
|
|
@ -0,0 +1,17 @@
|
||||||
|
# Copyright 2022 AdHoc SA - Pablo Paez
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
||||||
|
{
|
||||||
|
"name": "Partner Mail Forwarding",
|
||||||
|
"summary": "Forwarding notifications for partners",
|
||||||
|
"version": "13.0.1.0.0",
|
||||||
|
"category": "Social Network",
|
||||||
|
"website": "https://github.com/OCA/social",
|
||||||
|
"author": "ADHOC SA, Odoo Community Association (OCA)",
|
||||||
|
"license": "AGPL-3",
|
||||||
|
"installable": True,
|
||||||
|
"depends": ["mail"],
|
||||||
|
"data": ["views/res_user_views.xml", "views/res_partner_views.xml"],
|
||||||
|
"development_status": "Production/Stable",
|
||||||
|
"maintainers": [],
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
from . import res_partner
|
||||||
|
from . import res_user
|
||||||
|
from . import mail_thread
|
|
@ -0,0 +1,43 @@
|
||||||
|
from odoo import models
|
||||||
|
|
||||||
|
|
||||||
|
class MailThread(models.AbstractModel):
|
||||||
|
_inherit = "mail.thread"
|
||||||
|
|
||||||
|
def _notify_compute_recipients(self, message, msg_vals):
|
||||||
|
""" Inherit this method to add in the list of partners to be notify
|
||||||
|
the forwarding_partner_id of any partners in the list """
|
||||||
|
recipient_data = super()._notify_compute_recipients(message, msg_vals)
|
||||||
|
if not recipient_data.get("partners", False):
|
||||||
|
return recipient_data
|
||||||
|
partner_dict = {x.get("id"): x for x in recipient_data.get("partners")}
|
||||||
|
forwarded_partner_ids = []
|
||||||
|
# for each partner being notified we check if it has a
|
||||||
|
# forwarding_partner_id configured that is not being notified yet
|
||||||
|
for partner in (
|
||||||
|
self.env["res.partner"]
|
||||||
|
.sudo()
|
||||||
|
.with_context(prefetch_fields=False)
|
||||||
|
.browse(partner_dict.keys())
|
||||||
|
):
|
||||||
|
if (
|
||||||
|
partner.forwarding_partner_id
|
||||||
|
and partner.forwarding_partner_id.id not in partner_dict.keys()
|
||||||
|
and partner.forwarding_partner_id.id not in forwarded_partner_ids
|
||||||
|
):
|
||||||
|
forwarded_partner_ids.append(partner.forwarding_partner_id.id)
|
||||||
|
data = partner_dict[partner.id].copy()
|
||||||
|
notif = (
|
||||||
|
partner.forwarding_partner_id.user_ids
|
||||||
|
and partner.forwarding_partner_id.user_ids[0].notification_type
|
||||||
|
or "email"
|
||||||
|
)
|
||||||
|
data.update(
|
||||||
|
{
|
||||||
|
"id": partner.forwarding_partner_id.id,
|
||||||
|
"share": partner.partner_share,
|
||||||
|
"notif": notif,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
recipient_data["partners"].append(data)
|
||||||
|
return recipient_data
|
|
@ -0,0 +1,12 @@
|
||||||
|
from odoo import fields, models
|
||||||
|
|
||||||
|
|
||||||
|
class ResPartner(models.Model):
|
||||||
|
_inherit = "res.partner"
|
||||||
|
|
||||||
|
forwarding_partner_id = fields.Many2one(
|
||||||
|
"res.partner",
|
||||||
|
string="Forwarding Partner",
|
||||||
|
help="Messages will be forwarded only for partners that are followers but no "
|
||||||
|
"partners being notify because they belong to channel that is following the thread",
|
||||||
|
)
|
|
@ -0,0 +1,16 @@
|
||||||
|
from odoo import fields, models
|
||||||
|
|
||||||
|
|
||||||
|
class ResUsers(models.Model):
|
||||||
|
_inherit = "res.users"
|
||||||
|
|
||||||
|
forwarding_partner_id = fields.Many2one(
|
||||||
|
related="partner_id.forwarding_partner_id", readonly=False
|
||||||
|
)
|
||||||
|
|
||||||
|
def __init__(self, pool, cr):
|
||||||
|
super().__init__(pool, cr)
|
||||||
|
self.SELF_WRITEABLE_FIELDS = list(self.SELF_WRITEABLE_FIELDS)
|
||||||
|
self.SELF_WRITEABLE_FIELDS.append("forwarding_partner_id")
|
||||||
|
self.SELF_READABLE_FIELDS = list(self.SELF_READABLE_FIELDS)
|
||||||
|
self.SELF_READABLE_FIELDS.append("forwarding_partner_id")
|
|
@ -0,0 +1 @@
|
||||||
|
* Nicolás Mac Rouillon <nmr@adhoc.com.ar>
|
|
@ -0,0 +1 @@
|
||||||
|
This module allows to select a related user (called "Forwarding partner") in each partner in order to send all the notifications to the Forwarding partner.
|
|
@ -0,0 +1,4 @@
|
||||||
|
13.0.1.0.0 (2022-01-03)
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
* [NEW] Module in v13.
|
|
@ -0,0 +1,5 @@
|
||||||
|
To use this module, you need to:
|
||||||
|
|
||||||
|
* Install it.
|
||||||
|
* Set a Forwarding partner in your partner.
|
||||||
|
* Your Forwarding partner also will be notify of your notifications
|
|
@ -0,0 +1 @@
|
||||||
|
from . import test_mail_forwarding
|
|
@ -0,0 +1 @@
|
||||||
|
from . import fake_order
|
|
@ -0,0 +1,13 @@
|
||||||
|
# Copyright 2021 Camptocamp (http://www.camptocamp.com).
|
||||||
|
# @author Iván Todorovich <ivan.todorovich@gmail.com>
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
|
from odoo import fields, models
|
||||||
|
|
||||||
|
|
||||||
|
class FakeOrder(models.Model):
|
||||||
|
_name = "fake.order"
|
||||||
|
_inherit = "mail.thread"
|
||||||
|
_description = "Fake sale.order like model"
|
||||||
|
|
||||||
|
partner_id = fields.Many2one("res.partner", required=True)
|
|
@ -0,0 +1,46 @@
|
||||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
|
from odoo_test_helper import FakeModelLoader
|
||||||
|
|
||||||
|
from odoo import _
|
||||||
|
from odoo.tests.common import SavepointCase, tagged
|
||||||
|
|
||||||
|
|
||||||
|
@tagged("post_install", "-at_install")
|
||||||
|
class TestMailForwarding(SavepointCase):
|
||||||
|
@classmethod
|
||||||
|
def setUpClass(cls):
|
||||||
|
super().setUpClass()
|
||||||
|
# Setup env
|
||||||
|
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
|
||||||
|
# Load fake order model
|
||||||
|
cls.loader = FakeModelLoader(cls.env, cls.__module__)
|
||||||
|
cls.loader.backup_registry()
|
||||||
|
from .models.fake_order import FakeOrder
|
||||||
|
|
||||||
|
cls.loader.update_registry((FakeOrder,))
|
||||||
|
cls.fake_order_model = cls.env["ir.model"].search(
|
||||||
|
[("model", "=", "fake.order")]
|
||||||
|
)
|
||||||
|
# Partner To forward
|
||||||
|
cls.partner_1 = cls.env.ref("base.user_demo").partner_id
|
||||||
|
cls.partner_2 = cls.env.ref("base.user_admin").partner_id
|
||||||
|
|
||||||
|
# Configurate in the user setting the user to be forwarding
|
||||||
|
cls.partner_2.forwarding_partner_id = cls.partner_1
|
||||||
|
# Empty fake.order
|
||||||
|
cls.order = cls.env["fake.order"].create({"partner_id": cls.partner_2.id})
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def tearDownClass(cls):
|
||||||
|
cls.loader.restore_registry()
|
||||||
|
return super().tearDownClass()
|
||||||
|
|
||||||
|
def test_message_post_forwarding(self):
|
||||||
|
"""Test forwarding when send a message for the user"""
|
||||||
|
self.order.message_post(
|
||||||
|
body=_("Test"),
|
||||||
|
message_type="comment",
|
||||||
|
subtype="mail.mt_comment",
|
||||||
|
partner_ids=[self.partner_2.id],
|
||||||
|
)
|
|
@ -0,0 +1,16 @@
|
||||||
|
<!-- Copyright 2022 AdHoc SA
|
||||||
|
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -->
|
||||||
|
<odoo>
|
||||||
|
|
||||||
|
<record id="view_partner_form" model="ir.ui.view">
|
||||||
|
<field name="name">res.partner.form.forwarding</field>
|
||||||
|
<field name="model">res.partner</field>
|
||||||
|
<field name="inherit_id" ref="base.view_partner_form" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<field name="website" position="before">
|
||||||
|
<field name="forwarding_partner_id" />
|
||||||
|
</field>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
</odoo>
|
|
@ -0,0 +1,28 @@
|
||||||
|
<!-- Copyright 2022 AdHoc SA
|
||||||
|
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -->
|
||||||
|
<odoo>
|
||||||
|
|
||||||
|
<record id="view_users_form_mail" model="ir.ui.view">
|
||||||
|
<field name="name">res.users.form.user.forwarding</field>
|
||||||
|
<field name="model">res.users</field>
|
||||||
|
<field name="inherit_id" ref="base.view_users_form" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<xpath expr="//field[@name='login']//.." position="after">
|
||||||
|
<label for="forwarding_partner_id" />
|
||||||
|
<field name="forwarding_partner_id" />
|
||||||
|
</xpath>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<record id="view_users_form_mail_preferences" model="ir.ui.view">
|
||||||
|
<field name="name">res.users.form.user.forwarding.preferences</field>
|
||||||
|
<field name="model">res.users</field>
|
||||||
|
<field name="inherit_id" ref="base.view_users_form_simple_modif" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<field name="email" position="after">
|
||||||
|
<field name="forwarding_partner_id" readonly="0" />
|
||||||
|
</field>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
</odoo>
|
|
@ -0,0 +1 @@
|
||||||
|
../../../../mail_partner_forwarding
|
|
@ -0,0 +1,6 @@
|
||||||
|
import setuptools
|
||||||
|
|
||||||
|
setuptools.setup(
|
||||||
|
setup_requires=['setuptools-odoo'],
|
||||||
|
odoo_addon=True,
|
||||||
|
)
|
Loading…
Reference in New Issue