Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 115 additions & 0 deletions mail_activity_partner/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
=====================
Mail Activity Partner
=====================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:b8f1e18fc30525be3711f60f6ba298b30090661d6884ad6bee0809ccc47a7342
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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%2Fmail-lightgray.png?logo=github
:target: https://github.com/OCA/mail/tree/18.0/mail_activity_partner
:alt: OCA/mail
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/mail-18-0/mail-18-0-mail_activity_partner
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/mail&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module adds a partner and commercial partner field to activities

**Table of contents**

.. contents::
:local:

Usage
=====

For developers
--------------

By default, this module links activities to the ``partner_id`` field of
the record. If your model uses a different field to hold the related
partner (e.g. ``address_id``, ``contact_id``), you must override
``_get_partner_field_name`` to return that field name, otherwise
activity partner synchronization will have no effect on your model.

**When to override:**

- Your model inherits ``mail.activity.mixin`` but does not have a
``partner_id`` field.
- Your model has a partner relationship stored under a field with a name
other than ``partner_id``.

**Example:**

.. code:: python

class MyModel(models.Model):
_name = "my.model"
_inherit = ["mail.activity.mixin", "mail.thread"]

address_id = fields.Many2one("res.partner")

@api.model
def _get_partner_field_name(self):
return "address_id"

With this override, every time ``address_id`` is set or changed on a
record, all linked activities will automatically have their
``partner_id`` updated to match.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/mail/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/mail/issues/new?body=module:%20mail_activity_partner%0Aversion:%2018.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
-------

* ForgeFlow

Contributors
------------

- Adrià Gil Sorribes (adria.gil@forgeflow.com)
- Joan Mateu Jordi (joan.mateu@forgeflow.com)
- Yann Papouin (ypa@decgroupe.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/mail <https://github.com/OCA/mail/tree/18.0/mail_activity_partner>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
3 changes: 3 additions & 0 deletions mail_activity_partner/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import models
15 changes: 15 additions & 0 deletions mail_activity_partner/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2018 ForgeFlow S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Mail Activity Partner",
"summary": "Add Partner to Activities",
"version": "18.0.1.0.0",
"development_status": "Beta",
"category": "Social Network",
"website": "https://github.com/OCA/mail",
"author": "ForgeFlow, Odoo Community Association (OCA)",
"license": "AGPL-3",
"installable": True,
"data": ["views/mail_activity_views.xml"],
"depends": ["mail"],
}
32 changes: 32 additions & 0 deletions mail_activity_partner/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * mail_activity_partner
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2025-07-14 11:59+0000\n"
"Last-Translator: kikopeiro <francisco.peiro@factorlibre.com>\n"
"Language-Team: none\n"
"Language: es\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 5.10.4\n"

#. module: mail_activity_partner
#: model:ir.model,name:mail_activity_partner.model_mail_activity
msgid "Activity"
msgstr "Actividad"

#. module: mail_activity_partner
#: model:ir.model.fields,field_description:mail_activity_partner.field_mail_activity__commercial_partner_id
msgid "Commercial Entity"
msgstr "Entidad Comercial"

#. module: mail_activity_partner
#: model:ir.model.fields,field_description:mail_activity_partner.field_mail_activity__partner_id
msgid "Partner"
msgstr "Contacto"
32 changes: 32 additions & 0 deletions mail_activity_partner/i18n/it.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * mail_activity_partner
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2023-12-01 10:12+0000\n"
"Last-Translator: mymage <stefano.consolaro@mymage.it>\n"
"Language-Team: none\n"
"Language: it\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 4.17\n"

#. module: mail_activity_partner
#: model:ir.model,name:mail_activity_partner.model_mail_activity
msgid "Activity"
msgstr "Attività"

#. module: mail_activity_partner
#: model:ir.model.fields,field_description:mail_activity_partner.field_mail_activity__commercial_partner_id
msgid "Commercial Entity"
msgstr "Entità commerciale"

#. module: mail_activity_partner
#: model:ir.model.fields,field_description:mail_activity_partner.field_mail_activity__partner_id
msgid "Partner"
msgstr "Partner"
29 changes: 29 additions & 0 deletions mail_activity_partner/i18n/mail_activity_partner.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * mail_activity_partner
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \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_activity_partner
#: model:ir.model,name:mail_activity_partner.model_mail_activity
msgid "Activity"
msgstr ""

#. module: mail_activity_partner
#: model:ir.model.fields,field_description:mail_activity_partner.field_mail_activity__commercial_partner_id
msgid "Commercial Entity"
msgstr ""

#. module: mail_activity_partner
#: model:ir.model.fields,field_description:mail_activity_partner.field_mail_activity__partner_id
msgid "Partner"
msgstr ""
4 changes: 4 additions & 0 deletions mail_activity_partner/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import mail_activity
from . import mail_activity_mixin
43 changes: 43 additions & 0 deletions mail_activity_partner/models/mail_activity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright 2018 ForgeFlow S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models


class MailActivity(models.Model):
_inherit = "mail.activity"

partner_id = fields.Many2one(
comodel_name="res.partner",
index=True,
compute="_compute_res_partner_id",
store=True,
)

commercial_partner_id = fields.Many2one(
related="partner_id.commercial_partner_id",
string="Commercial Entity",
store=True,
related_sudo=True,
readonly=True,
)

@api.depends("res_model", "res_id")
def _compute_res_partner_id(self):
for activity in self:
res_model = activity.res_model
res_id = activity.res_id
activity.partner_id = False
if res_model:
if res_model == "res.partner":
activity.partner_id = res_id
else:
res_model_id = self.env[res_model].browse(res_id)
# Check for existing function as this case could happen when
# compute is called from a hook (post_install)
if hasattr(res_model_id, "_get_partner_field_name"):
partner_field_name = res_model_id._get_partner_field_name()
else:
partner_field_name = "partner_id"
if partner_field_name in res_model_id._fields:
partner_id = res_model_id[partner_field_name]
activity.partner_id = partner_id
45 changes: 45 additions & 0 deletions mail_activity_partner/models/mail_activity_mixin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import api, models


class MailActivityMixin(models.AbstractModel):
_inherit = "mail.activity.mixin"

@api.model_create_multi
def create(self, vals_list):
record_ids = super().create(vals_list)
for rec, vals in zip(record_ids, vals_list, strict=True):
if rec and self._activity_partner_need_update(vals):
rec._update_activity_partner()
return record_ids

def write(self, vals):
res = super().write(vals)
if res and self._activity_partner_need_update(vals):
self._update_activity_partner()
return res

@api.model
def _get_partner_field_name(self):
"""Return the name of the partner field to link activities to.
By default, it's `partner_id`, but it can be overridden by models that
want to link activities to a different partner field."""
return "partner_id"

@api.model
def _activity_partner_need_update(self, vals):
res = False
partner_field_name = self._get_partner_field_name()
if partner_field_name in self._fields:
# Use set intersection to find out if the `partner_id` of
# linked activities must be updated
depends_fields = [partner_field_name]
if depends_fields and (set(vals) & set(depends_fields)):
res = True
return res

def _update_activity_partner(self):
for rec in self:
partner_field_name = rec._get_partner_field_name()
partner_id = rec[partner_field_name]
rec.activity_ids.write({"partner_id": partner_id.id})
3 changes: 3 additions & 0 deletions mail_activity_partner/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
3 changes: 3 additions & 0 deletions mail_activity_partner/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Adrià Gil Sorribes (<adria.gil@forgeflow.com>)
- Joan Mateu Jordi (<joan.mateu@forgeflow.com>)
- Yann Papouin (<ypa@decgroupe.com>)
1 change: 1 addition & 0 deletions mail_activity_partner/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module adds a partner and commercial partner field to activities
29 changes: 29 additions & 0 deletions mail_activity_partner/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
## For developers

By default, this module links activities to the `partner_id` field of the record.
If your model uses a different field to hold the related partner (e.g. `address_id`,
`contact_id`), you must override `_get_partner_field_name` to return that field name,
otherwise activity partner synchronization will have no effect on your model.

**When to override:**
- Your model inherits `mail.activity.mixin` but does not have a `partner_id` field.
- Your model has a partner relationship stored under a field with a name other than
`partner_id`.

**Example:**

```python
class MyModel(models.Model):
_name = "my.model"
_inherit = ["mail.activity.mixin", "mail.thread"]

address_id = fields.Many2one("res.partner")

@api.model
def _get_partner_field_name(self):
return "address_id"
```

With this override, every time `address_id` is set or changed on a record, all linked
activities will automatically have their `partner_id` updated to match.

Binary file added mail_activity_partner/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading