diff --git a/mail_composer_cc_bcc_account/README.rst b/mail_composer_cc_bcc_account/README.rst index 1e5fd159..2902a640 100644 --- a/mail_composer_cc_bcc_account/README.rst +++ b/mail_composer_cc_bcc_account/README.rst @@ -16,14 +16,14 @@ Email CC and BCC when sending invoice .. |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/17.0/mail_composer_cc_bcc_account - :alt: OCA/social +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fmail-lightgray.png?logo=github + :target: https://github.com/OCA/mail/tree/18.0/mail_composer_cc_bcc_account + :alt: OCA/mail .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/social-17-0/social-17-0-mail_composer_cc_bcc_account + :target: https://translation.odoo-community.org/projects/mail-18-0/mail-18-0-mail_composer_cc_bcc_account :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/social&target_branch=17.0 + :target: https://runboat.odoo-community.org/builds?repo=OCA/mail&target_branch=18.0 :alt: Try me on Runboat |badge1| |badge2| |badge3| |badge4| |badge5| @@ -56,10 +56,10 @@ partners then the invoice contact of the customer. Bug Tracker =========== -Bugs are tracked on `GitHub Issues `_. +Bugs are tracked on `GitHub 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 `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -87,8 +87,8 @@ Contributors Other credits ------------- -The creation and migration from 16.0 to 17.0 of this module were -financially supported by Camptocamp. +The creation and migration of this module from 16.0 to 17.0, and then +17.0 to 18.0 were financially supported by Camptocamp. Maintainers ----------- @@ -111,6 +111,6 @@ Current `maintainer `__: |maintainer-hailangvn2023| -This module is part of the `OCA/social `_ project on GitHub. +This module is part of the `OCA/mail `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/mail_composer_cc_bcc_account/__manifest__.py b/mail_composer_cc_bcc_account/__manifest__.py index 1215789d..979c2022 100644 --- a/mail_composer_cc_bcc_account/__manifest__.py +++ b/mail_composer_cc_bcc_account/__manifest__.py @@ -3,10 +3,10 @@ { "name": "Email CC and BCC when sending invoice", "summary": "This module enables sending mail to CC and BCC partners for invoices.", - "version": "17.0.1.0.0", + "version": "18.0.1.0.0", "development_status": "Alpha", "category": "Social", - "website": "https://github.com/OCA/social", + "website": "https://github.com/OCA/mail", "author": "Camptocamp SA, Odoo Community Association (OCA)", "maintainers": ["hailangvn2023"], "license": "AGPL-3", @@ -19,6 +19,6 @@ "mail_composer_cc_bcc", ], "data": [ - "wizards/account_move_send.xml", + "wizards/account_move_send_wizard.xml", ], } diff --git a/mail_composer_cc_bcc_account/readme/CREDITS.md b/mail_composer_cc_bcc_account/readme/CREDITS.md index 2dae1962..53026c98 100644 --- a/mail_composer_cc_bcc_account/readme/CREDITS.md +++ b/mail_composer_cc_bcc_account/readme/CREDITS.md @@ -1,2 +1 @@ -The creation and migration from 16.0 to 17.0 of this module were -financially supported by Camptocamp. +The creation and migration of this module from 16.0 to 17.0, and then 17.0 to 18.0 were financially supported by Camptocamp. diff --git a/mail_composer_cc_bcc_account/static/description/index.html b/mail_composer_cc_bcc_account/static/description/index.html index 3ce40805..b859ea24 100644 --- a/mail_composer_cc_bcc_account/static/description/index.html +++ b/mail_composer_cc_bcc_account/static/description/index.html @@ -369,7 +369,7 @@

Email CC and BCC when sending invoice

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! source digest: sha256:dd944995a010180b76d2bfa93b37c70a3866d21822b825cd811895aca5318ff6 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

Alpha License: AGPL-3 OCA/social Translate me on Weblate Try me on Runboat

+

Alpha License: AGPL-3 OCA/mail Translate me on Weblate Try me on Runboat

This module allows to properly separate To:, Cc:, and Bcc: fields in when sending invoices.

@@ -405,10 +405,10 @@

Usage

Bug Tracker

-

Bugs are tracked on GitHub Issues. +

Bugs are tracked on GitHub 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.

+feedback.

Do not contact contributors directly about support or help with technical issues.

@@ -442,8 +442,8 @@

Contributors

Other credits

-

The creation and migration from 16.0 to 17.0 of this module were -financially supported by Camptocamp.

+

The creation and migration of this module from 16.0 to 17.0, and then +17.0 to 18.0 were financially supported by Camptocamp.

Maintainers

@@ -456,7 +456,7 @@

Maintainers

promote its widespread use.

Current maintainer:

hailangvn2023

-

This module is part of the OCA/social project on GitHub.

+

This module is part of the OCA/mail project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

diff --git a/mail_composer_cc_bcc_account/tests/test_mail_cc_bcc.py b/mail_composer_cc_bcc_account/tests/test_mail_cc_bcc.py index f2025500..388c3952 100644 --- a/mail_composer_cc_bcc_account/tests/test_mail_cc_bcc.py +++ b/mail_composer_cc_bcc_account/tests/test_mail_cc_bcc.py @@ -1,58 +1,38 @@ # Copyright 2023 Camptocamp # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -from datetime import date -from odoo.tests import Form +from odoo.addons.account.tests.test_account_move_send import TestAccountMoveSendCommon +from odoo.addons.mail.tests.common import MailCommon -from odoo.addons.mail_composer_cc_bcc.tests.test_mail_cc_bcc import TestMailCcBcc +class TestMailCcBccInvoice(TestAccountMoveSendCommon, MailCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + env = cls.env + cls.partner = env.ref("base.res_partner_address_31") + cls.partner_cc = env.ref("base.partner_demo") + cls.partner_bcc = env.ref("base.res_partner_main2") -class TestMailCcBccInvoice(TestMailCcBcc): - def open_invoice_mail_composer_form(self): - # Use form to populate data - # init invoice data - self.test_invoice = test_record = self.test_account_move = self.env[ - "account.move" - ].create( - { - "invoice_date": date(2024, 3, 2), - "invoice_date_due": date(2024, 3, 10), - "invoice_line_ids": [ - (0, 0, {"name": "Line1", "price_unit": 100.0}), - (0, 0, {"name": "Line2", "price_unit": 200.0}), - ], - "move_type": "out_invoice", - "name": "invoice test", - "partner_id": self.env.ref("base.res_partner_2").id, - } + def test_invoice_mail_cc_bcc(self): + invoice = self.init_invoice( + "out_invoice", partner=self.partner, amounts=[1000], post=True ) - - self.assertTrue( - self.test_invoice, - "Test setup did not succeed. Invoice not found.", + wizard = self.create_send_and_print( + invoice, + sending_methods=["email", "manual"], + mail_partner_ids=self.partner, + partner_cc_ids=self.partner_cc, + partner_bcc_ids=self.partner_bcc, ) - self.test_invoice.write({"state": "posted"}) - - ctx = { - "active_ids": test_record.ids, - "default_model": "account.move", - "default_res_id": test_record.id, - "mail_notify_force_send": True, - } - form = Form(self.env["account.move.send"].with_context(**ctx)) - form.mail_body = "

Hello

" - return form - def test_invoice_mail_cc_bcc(self): - self.set_company() - form = self.open_invoice_mail_composer_form() - form.mail_subject = "Hello" - composer = form.save() with self.mock_mail_gateway(): - composer.action_send_and_print() - message = self.test_invoice.message_ids[0] + wizard.action_send_and_print() + self.assertEqual(len(self._mails), 3) + + message = self._get_mail_message(invoice) self.assertEqual(len(message.mail_ids), 1) - # Only 2 partners (from default_cc/bcc of company) notified - self.assertEqual(len(message.notified_partner_ids), 2) - self.assertEqual(len(message.notification_ids), 2) + # Only 3 partners (from default_cc/bcc of company) notified + self.assertEqual(len(message.notified_partner_ids), 3) + self.assertEqual(len(message.notification_ids), 3) diff --git a/mail_composer_cc_bcc_account/wizards/__init__.py b/mail_composer_cc_bcc_account/wizards/__init__.py index cf39f38e..589b902b 100644 --- a/mail_composer_cc_bcc_account/wizards/__init__.py +++ b/mail_composer_cc_bcc_account/wizards/__init__.py @@ -1 +1 @@ -from . import account_move_send +from . import account_move_send_wizard diff --git a/mail_composer_cc_bcc_account/wizards/account_move_send.py b/mail_composer_cc_bcc_account/wizards/account_move_send.py deleted file mode 100644 index e300400d..00000000 --- a/mail_composer_cc_bcc_account/wizards/account_move_send.py +++ /dev/null @@ -1,129 +0,0 @@ -# Copyright 2024 Camptocamp -# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). - - -from odoo import Command, api, fields, models, tools - - -class AccountMoveSend(models.TransientModel): - _inherit = "account.move.send" - - partner_cc_ids = fields.Many2many( - "res.partner", - "account_move_send_res_partner_cc_rel", - "wizard_id", - "partner_id", - string="Cc", - compute="_compute_mail_partner_cc_bcc_ids", - store=True, - readonly=False, - ) - partner_bcc_ids = fields.Many2many( - "res.partner", - "account_move_send_res_partner_bcc_rel", - "wizard_id", - "partner_id", - string="Bcc", - compute="_compute_mail_partner_cc_bcc_ids", - store=True, - readonly=False, - ) - - def _get_partner_ids_from_mail(self, move, emails): - partners = self.env["res.partner"].with_company(move.company_id) - for mail_data in tools.email_split(emails): - partners |= partners.find_or_create(mail_data) - return partners - - @api.model - def default_get(self, fields_list): - company = self.env.company - res = super().default_get(fields_list) - partner_cc = company.default_partner_cc_ids - if partner_cc: - res["partner_cc_ids"] = [Command.set(partner_cc.ids)] - partner_bcc = company.default_partner_bcc_ids - if partner_bcc: - res["partner_bcc_ids"] = [Command.set(partner_bcc.ids)] - return res - - @api.depends("mail_template_id") - def _compute_mail_partner_cc_bcc_ids(self): - for wizard in self: - if wizard.mode == "invoice_single" and wizard.mail_template_id: - wizard.partner_cc_ids = self._get_partner_ids_from_mail( - wizard.move_ids, wizard.mail_template_id.email_cc - ) - wizard.partner_bcc_ids = self._get_partner_ids_from_mail( - wizard.move_ids, wizard.mail_template_id.email_bcc - ) - else: - wizard.partner_cc_ids = None - wizard.partner_bcc_ids = None - - def _get_mail_move_values(self, move, wizard=None): - mail_template_id = ( - move.send_and_print_values - and move.send_and_print_values.get("mail_template_id") - ) - mail_template = ( - wizard - and wizard.mail_template_id - or self.env["mail.template"].browse(mail_template_id) - ) - mail_lang = self._get_default_mail_lang(move, mail_template) - return { - "mail_template_id": mail_template, - "mail_lang": mail_lang, - "mail_body": wizard - and wizard.mail_body - or self._get_default_mail_body(move, mail_template, mail_lang), - "mail_subject": wizard - and wizard.mail_subject - or self._get_default_mail_subject(move, mail_template, mail_lang), - "mail_partner_ids": wizard - and wizard.mail_partner_ids - or self._get_default_mail_partner_ids(move, mail_template, mail_lang), - "mail_attachments_widget": wizard - and wizard.mail_attachments_widget - or self._get_default_mail_attachments_widget(move, mail_template), - "partner_cc_ids": wizard - and wizard.partner_cc_ids - or self._get_default_mail_partner_cc_ids(move, mail_template), - "partner_bcc_ids": wizard - and wizard.partner_bcc_ids - or self._get_default_mail_partner_bcc_ids(move, mail_template), - } - - # ------------------------------------------------------------------------- - # BUSINESS ACTIONS - # ------------------------------------------------------------------------- - - @api.model - def _send_mail(self, move, mail_template, **kwargs): - """Send the journal entry passed as parameter by mail.""" - partner_ids = kwargs.get("partner_ids", []) - move_with_context = move.with_context( - no_new_invoice=True, - mail_notify_author=self.env.user.partner_id.id in partner_ids, - is_from_composer=True, - partner_cc_ids=self.partner_cc_ids, - partner_bcc_ids=self.partner_bcc_ids, - ) - extra_args = { - "email_layout_xmlid": "mail.mail_notification_layout_with_responsible_signature", # noqa: E501 - "email_add_signature": not mail_template, - "mail_auto_delete": mail_template.auto_delete, - "mail_server_id": mail_template.mail_server_id.id, - "reply_to_force_new": False, - "message_type": "comment", - } - kwargs.update(extra_args) - new_message = move_with_context.message_post(**kwargs) - # Prevent duplicated attachments linked to the invoice. - new_message.attachment_ids.write( - { - "res_model": new_message._name, - "res_id": new_message.id, - } - ) diff --git a/mail_composer_cc_bcc_account/wizards/account_move_send.xml b/mail_composer_cc_bcc_account/wizards/account_move_send.xml deleted file mode 100644 index 32b5da32..00000000 --- a/mail_composer_cc_bcc_account/wizards/account_move_send.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - account.move.send.form.inherit - account.move.send - - - - - - - - - - diff --git a/mail_composer_cc_bcc_account/wizards/account_move_send_wizard.py b/mail_composer_cc_bcc_account/wizards/account_move_send_wizard.py new file mode 100644 index 00000000..d7a77dba --- /dev/null +++ b/mail_composer_cc_bcc_account/wizards/account_move_send_wizard.py @@ -0,0 +1,78 @@ +# Copyright 2024 Camptocamp +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +# +from odoo import Command, api, fields, models +from odoo.tools.mail import email_split + + +class AccountMoveSendWizard(models.TransientModel): + _inherit = "account.move.send.wizard" + + partner_cc_ids = fields.Many2many( + "res.partner", + "account_move_send_wizard_res_partner_cc_rel", + "wizard_id", + "partner_id", + string="Cc", + compute="_compute_mail_partner_cc_bcc_ids", + store=True, + readonly=False, + ) + partner_bcc_ids = fields.Many2many( + "res.partner", + "account_move_send_wizard_res_partner_bcc_rel", + "wizard_id", + "partner_id", + string="Bcc", + compute="_compute_mail_partner_cc_bcc_ids", + store=True, + readonly=False, + ) + + # ------------------------------------------------------------------------- + # DEFAULTS + # ------------------------------------------------------------------------- + + @api.model + def default_get(self, fields_list): + # EXTENDS 'base' + results = super().default_get(fields_list) + company = self.env.company + partner_cc = company.default_partner_cc_ids + if partner_cc: + results["partner_cc_ids"] = [Command.set(partner_cc.ids)] + partner_bcc = company.default_partner_bcc_ids + if partner_bcc: + results["partner_bcc_ids"] = [Command.set(partner_bcc.ids)] + return results + + # ------------------------------------------------------------------------- + # COMPUTE METHODS + # ------------------------------------------------------------------------- + def _get_partner_ids_from_mail(self, move, emails): + partners = self.env["res.partner"].with_company(move.company_id) + for mail_data in email_split(emails): + partners |= partners.find_or_create(mail_data) + return partners + + @api.depends("mail_template_id") + def _compute_mail_partner_cc_bcc_ids(self): + for wizard in self: + if wizard.mail_template_id: + wizard.partner_cc_ids = self._get_partner_ids_from_mail( + wizard.move_id, wizard.mail_template_id.email_cc + ) + wizard.partner_bcc_ids = self._get_partner_ids_from_mail( + wizard.move_id, wizard.mail_template_id.email_bcc + ) + else: + wizard.partner_cc_ids = wizard.partner_bcc_ids = None + + @api.model + def _send_mail(self, move, mail_template, **kwargs): + move_with_context = move.with_context( + is_from_composer=True, + partner_cc_ids=self.partner_cc_ids, + partner_bcc_ids=self.partner_bcc_ids, + ) + return super()._send_mail(move_with_context, mail_template, **kwargs) diff --git a/mail_composer_cc_bcc_account/wizards/account_move_send_wizard.xml b/mail_composer_cc_bcc_account/wizards/account_move_send_wizard.xml new file mode 100644 index 00000000..31db713f --- /dev/null +++ b/mail_composer_cc_bcc_account/wizards/account_move_send_wizard.xml @@ -0,0 +1,25 @@ + + + + account.move.send.wizard.form.inherit + account.move.send.wizard + + + + + + + + + +