From 217a99387814b12122b0a4e138b4ded23819f426 Mon Sep 17 00:00:00 2001 From: trisdoan Date: Mon, 19 Feb 2024 15:18:08 +0700 Subject: [PATCH] [MIG] mail_composer_cc_bcc_account: Migration to 17.0 --- mail_composer_cc_bcc/README.rst | 8 +- mail_composer_cc_bcc/__manifest__.py | 1 - mail_composer_cc_bcc/readme/CONFIGURE.md | 4 +- .../static/description/index.html | 76 ++++++----- .../tests/test_mail_cc_bcc.py | 12 +- mail_composer_cc_bcc_account/README.rst | 40 +++--- mail_composer_cc_bcc_account/__init__.py | 4 + mail_composer_cc_bcc_account/__manifest__.py | 6 +- .../models/__init__.py | 1 + .../models/mail_thread.py | 19 +++ .../readme/CONFIGURE.md | 3 +- .../readme/CONFIGURE.rst | 2 - .../readme/CONTRIBUTORS.rst | 8 -- .../readme/CREDITS.md | 2 +- .../readme/CREDITS.rst | 1 - .../readme/DESCRIPTION.rst | 2 - mail_composer_cc_bcc_account/readme/USAGE.md | 3 +- mail_composer_cc_bcc_account/readme/USAGE.rst | 2 - .../static/description/index.html | 13 +- .../tests/test_mail_cc_bcc.py | 39 ++++-- .../wizards/__init__.py | 1 + .../wizards/account_move_send.py | 129 ++++++++++++++++++ ...e_send_views.xml => account_move_send.xml} | 15 +- 23 files changed, 277 insertions(+), 114 deletions(-) create mode 100644 mail_composer_cc_bcc_account/models/__init__.py create mode 100644 mail_composer_cc_bcc_account/models/mail_thread.py delete mode 100644 mail_composer_cc_bcc_account/readme/CONFIGURE.rst delete mode 100644 mail_composer_cc_bcc_account/readme/CONTRIBUTORS.rst delete mode 100644 mail_composer_cc_bcc_account/readme/CREDITS.rst delete mode 100644 mail_composer_cc_bcc_account/readme/DESCRIPTION.rst delete mode 100644 mail_composer_cc_bcc_account/readme/USAGE.rst create mode 100644 mail_composer_cc_bcc_account/wizards/__init__.py create mode 100644 mail_composer_cc_bcc_account/wizards/account_move_send.py rename mail_composer_cc_bcc_account/wizards/{account_invoice_send_views.xml => account_move_send.xml} (51%) diff --git a/mail_composer_cc_bcc/README.rst b/mail_composer_cc_bcc/README.rst index d0b2f443b..9f9d0d57a 100644 --- a/mail_composer_cc_bcc/README.rst +++ b/mail_composer_cc_bcc/README.rst @@ -61,14 +61,14 @@ Configuration In company form there are two fields to set default cc and bcc partners. - |image| + |res_company_form_default_cc_bcc| In template form there are two fields to set cc and bcc emails. - |image1| + |email_template_form_cc_bcc| -.. |image| image:: https://raw.githubusercontent.com/OCA/social/17.0/mail_composer_cc_bcc/static/img/res_company_form_default_cc_bcc.png -.. |image1| image:: https://raw.githubusercontent.com/OCA/social/17.0/mail_composer_cc_bcc/static/img/email_template_form_cc_bcc.png +.. |res_company_form_default_cc_bcc| image:: https://raw.githubusercontent.com/OCA/social/17.0/mail_composer_cc_bcc/static/img/res_company_form_default_cc_bcc.png +.. |email_template_form_cc_bcc| image:: https://raw.githubusercontent.com/OCA/social/17.0/mail_composer_cc_bcc/static/img/email_template_form_cc_bcc.png Usage ===== diff --git a/mail_composer_cc_bcc/__manifest__.py b/mail_composer_cc_bcc/__manifest__.py index bd2d7b01a..fded5edf2 100644 --- a/mail_composer_cc_bcc/__manifest__.py +++ b/mail_composer_cc_bcc/__manifest__.py @@ -15,7 +15,6 @@ "preloadable": True, "depends": [ "mail", - "account", ], "data": [ "views/res_company_views.xml", diff --git a/mail_composer_cc_bcc/readme/CONFIGURE.md b/mail_composer_cc_bcc/readme/CONFIGURE.md index 7cb93e65e..8d9cddde2 100644 --- a/mail_composer_cc_bcc/readme/CONFIGURE.md +++ b/mail_composer_cc_bcc/readme/CONFIGURE.md @@ -1,7 +1,7 @@ In company form there are two fields to set default cc and bcc partners. -> ![image](../static/img/res_company_form_default_cc_bcc.png) +> ![res_company_form_default_cc_bcc](../static/img/res_company_form_default_cc_bcc.png) In template form there are two fields to set cc and bcc emails. -> ![image](../static/img/email_template_form_cc_bcc.png) +> ![email_template_form_cc_bcc](../static/img/email_template_form_cc_bcc.png) diff --git a/mail_composer_cc_bcc/static/description/index.html b/mail_composer_cc_bcc/static/description/index.html index d3010396c..7c7fc2c2a 100644 --- a/mail_composer_cc_bcc/static/description/index.html +++ b/mail_composer_cc_bcc/static/description/index.html @@ -8,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. @@ -274,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 } @@ -300,7 +301,7 @@ span.option { span.pre { white-space: pre } -span.problematic { +span.problematic, pre.problematic { color: red } span.section-subtitle { @@ -366,23 +367,24 @@ ul.auto-toc { !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!! source digest: sha256:5e1148fbb1ae19217b0286fcf623c67d487dbee6edd8b1fc072ce53c825f9a0b +!! source digest: sha256:254245c99d868f3a2c4cfdfec26f8d1be09fdc4b8bd2ec691e7f1db4cda9902b !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

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

-

Odoo native does not support defining a Cc field in the Mail Composer -by default; instead, it only has a unique Recipients fields, which is +

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

+

Odoo native does not support defining a Cc field in the Mail Composer by +default; instead, it only has a unique Recipients fields, which is confusing for a lot of end users.

-

This module allows to properly separate To:, Cc:, and Bcc: fields -in the Mail Composer.

+

This module allows to properly separate To:, Cc:, and Bcc: fields in the +Mail Composer.

Features

Important

@@ -402,34 +404,30 @@ Only for development or testing purpose, do not use in production.

Configuration

-

In company form there are two fields to set default cc and bcc -partners.

+

In company form there are two fields to set default cc and bcc partners.

-https://raw.githubusercontent.com/OCA/social/16.0/mail_composer_cc_bcc/static/img/res_company_form_default_cc_bcc.png -
+res_company_form_default_cc_bcc

In template form there are two fields to set cc and bcc emails.

-https://raw.githubusercontent.com/OCA/social/16.0/mail_composer_cc_bcc/static/img/email_template_form_cc_bcc.png -
+email_template_form_cc_bcc

Usage

-

The partners cc and bcc from company form will be used to fill in mail composer -form.

+

The partners cc and bcc from company form will be used to fill in mail +composer form.

-https://raw.githubusercontent.com/OCA/social/16.0/mail_composer_cc_bcc/static/img/mail_compose_message_default_cc_bcc.png -
-

When select a template that has cc and/or bcc emails, the emails will be used -to lookup partners then found partners will be added to corresponding mail -composer’s fields.

+image +

When select a template that has cc and/or bcc emails, the emails will be +used to lookup partners then found partners will be added to +corresponding mail composer’s fields.

-https://raw.githubusercontent.com/OCA/social/16.0/mail_composer_cc_bcc/static/img/mail_compose_message_template_cc_bcc.png -
+image1

Known issues / Roadmap

    -
  • Extract account customization (account.invoice.send wizard) to a specific module mail_composer_cc_bcc_account
  • +
  • Extract account customization (account.invoice.send wizard) to a +specific module mail_composer_cc_bcc_account
@@ -437,7 +435,7 @@ composer’s fields.

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.

@@ -447,7 +445,7 @@ If you spotted it first, help us to smash it by providing a detailed and welcome

Authors

    -
  • Camptocamp SA
  • +
  • Camptocamp
@@ -458,6 +456,7 @@ If you spotted it first, help us to smash it by providing a detailed and welcome @@ -465,18 +464,21 @@ If you spotted it first, help us to smash it by providing a detailed and welcome

Other credits

-

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

+

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

Maintainers

This module is maintained by the OCA.

-Odoo Community Association + +Odoo Community Association +

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.

Current maintainer:

-

hailangvn2023

-

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

+

trisdoan

+

This module is part of the OCA/social 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/tests/test_mail_cc_bcc.py b/mail_composer_cc_bcc/tests/test_mail_cc_bcc.py index ec9fe77b5..051a3a5aa 100644 --- a/mail_composer_cc_bcc/tests/test_mail_cc_bcc.py +++ b/mail_composer_cc_bcc/tests/test_mail_cc_bcc.py @@ -103,8 +103,8 @@ class TestMailCcBcc(TestMailComposerForm): # Company default values env.company.default_partner_cc_ids = self.partner_cc3 env.company.default_partner_bcc_ids = self.partner_cc2 - # Product template values - tmpl_model = env["ir.model"].search([("model", "=", "product.template")]) + # Partner template values + tmpl_model = env["ir.model"].search([("model", "=", "res.partner")]) partner_cc = self.partner_cc partner_bcc = self.partner_bcc vals = { @@ -120,7 +120,7 @@ Test Template

""", (partner_bcc.name or "False", partner_bcc.email or "False") ), } - prod_tmpl = env["mail.template"].create(vals) + partner_tmpl = env["mail.template"].create(vals) # Open mail composer form and check for default values from company form = self.open_mail_composer_form() @@ -130,12 +130,12 @@ Test Template

""", self.assertEqual(composer.partner_bcc_ids, self.partner_cc2) # Change email template and check for values from it - form.template_id = prod_tmpl + form.template_id = partner_tmpl composer = form.save() # Beside existing Cc and Bcc, add template's ones form = Form(composer) - form.template_id = prod_tmpl + form.template_id = partner_tmpl composer = form.save() expecting = self.partner_cc3 + self.partner_cc @@ -153,7 +153,7 @@ Test Template

""", form.save() self.assertFalse(form.template_id) # no template - form.template_id = prod_tmpl + form.template_id = partner_tmpl composer = form.save() expecting = self.partner_cc3 + self.partner_cc diff --git a/mail_composer_cc_bcc_account/README.rst b/mail_composer_cc_bcc_account/README.rst index 9411e0a70..b9ca30011 100644 --- a/mail_composer_cc_bcc_account/README.rst +++ b/mail_composer_cc_bcc_account/README.rst @@ -17,19 +17,19 @@ Email CC and BCC when sending invoice :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/16.0/mail_composer_cc_bcc_account + :target: https://github.com/OCA/social/tree/17.0/mail_composer_cc_bcc_account :alt: OCA/social .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/social-16-0/social-16-0-mail_composer_cc_bcc_account + :target: https://translation.odoo-community.org/projects/social-17-0/social-17-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=16.0 + :target: https://runboat.odoo-community.org/builds?repo=OCA/social&target_branch=17.0 :alt: Try me on Runboat |badge1| |badge2| |badge3| |badge4| |badge5| -This module allows to properly separate To:, Cc:, and Bcc: fields -in when sending invoices. +This module allows to properly separate To:, Cc:, and Bcc: fields in +when sending invoices. .. IMPORTANT:: This is an alpha version, the data model and design can change at any time without warning. @@ -50,8 +50,8 @@ mail_compose_cc_bcc are installed. Usage ===== -Use the cc and bcc fields when sending invoices, to notify other partners then -the invoice contact of the customer. +Use the cc and bcc fields when sending invoices, to notify other +partners then the invoice contact of the customer. Bug Tracker =========== @@ -59,7 +59,7 @@ Bug Tracker 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. @@ -67,29 +67,31 @@ Credits ======= Authors -~~~~~~~ +------- * Camptocamp SA Contributors -~~~~~~~~~~~~ +------------ -* `Trobz `_: +- `Trobz `__: - * Hai N. Le - * Son Ho + - Hai N. Le + - Son Ho + - Tris Doan -* `Therp BV `_: +- `Therp BV `__: - * Ronald Portier + - Ronald Portier Other credits -~~~~~~~~~~~~~ +------------- -The creation and migration from 15.0 to 16.0 of this module were financially supported by Camptocamp. +The creation and migration from 16.0 to 17.0 of this module were +financially supported by Camptocamp. Maintainers -~~~~~~~~~~~ +----------- This module is maintained by the OCA. @@ -109,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/social `_ 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/__init__.py b/mail_composer_cc_bcc_account/__init__.py index ef5ae3587..c5e1e9785 100644 --- a/mail_composer_cc_bcc_account/__init__.py +++ b/mail_composer_cc_bcc_account/__init__.py @@ -1 +1,5 @@ +# Copyright 2024 Camptocamp # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import models +from . import wizards diff --git a/mail_composer_cc_bcc_account/__manifest__.py b/mail_composer_cc_bcc_account/__manifest__.py index 4dcb8f382..1215789db 100644 --- a/mail_composer_cc_bcc_account/__manifest__.py +++ b/mail_composer_cc_bcc_account/__manifest__.py @@ -3,7 +3,7 @@ { "name": "Email CC and BCC when sending invoice", "summary": "This module enables sending mail to CC and BCC partners for invoices.", - "version": "16.0.2.0.0", + "version": "17.0.1.0.0", "development_status": "Alpha", "category": "Social", "website": "https://github.com/OCA/social", @@ -15,10 +15,10 @@ "auto_install": True, "preloadable": True, "depends": [ - "mail_composer_cc_bcc", "account", + "mail_composer_cc_bcc", ], "data": [ - "wizards/account_invoice_send_views.xml", + "wizards/account_move_send.xml", ], } diff --git a/mail_composer_cc_bcc_account/models/__init__.py b/mail_composer_cc_bcc_account/models/__init__.py new file mode 100644 index 000000000..b70a9f2d0 --- /dev/null +++ b/mail_composer_cc_bcc_account/models/__init__.py @@ -0,0 +1 @@ +from . import mail_thread diff --git a/mail_composer_cc_bcc_account/models/mail_thread.py b/mail_composer_cc_bcc_account/models/mail_thread.py new file mode 100644 index 000000000..c459d1dd5 --- /dev/null +++ b/mail_composer_cc_bcc_account/models/mail_thread.py @@ -0,0 +1,19 @@ +# Copyright 2024 Camptocamp +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import models + + +class MailThread(models.AbstractModel): + _inherit = "mail.thread" + + def _message_create(self, values_list): + context = self.env.context + res = super()._message_create(values_list) + partners_cc = context.get("partner_cc_ids", None) + if partners_cc: + res.recipient_cc_ids = partners_cc + partners_bcc = context.get("partner_bcc_ids", None) + if partners_bcc: + res.recipient_bcc_ids = partners_bcc + return res diff --git a/mail_composer_cc_bcc_account/readme/CONFIGURE.md b/mail_composer_cc_bcc_account/readme/CONFIGURE.md index eddd34da0..2ccf27bc9 100644 --- a/mail_composer_cc_bcc_account/readme/CONFIGURE.md +++ b/mail_composer_cc_bcc_account/readme/CONFIGURE.md @@ -1,2 +1 @@ -This module will be automatically installed if both account and -mail_compose_cc_bcc are installed. +This module will be automatically installed if both account and mail_compose_cc_bcc are installed. diff --git a/mail_composer_cc_bcc_account/readme/CONFIGURE.rst b/mail_composer_cc_bcc_account/readme/CONFIGURE.rst deleted file mode 100644 index eddd34da0..000000000 --- a/mail_composer_cc_bcc_account/readme/CONFIGURE.rst +++ /dev/null @@ -1,2 +0,0 @@ -This module will be automatically installed if both account and -mail_compose_cc_bcc are installed. diff --git a/mail_composer_cc_bcc_account/readme/CONTRIBUTORS.rst b/mail_composer_cc_bcc_account/readme/CONTRIBUTORS.rst deleted file mode 100644 index 707d8e429..000000000 --- a/mail_composer_cc_bcc_account/readme/CONTRIBUTORS.rst +++ /dev/null @@ -1,8 +0,0 @@ -* `Trobz `_: - - * Hai N. Le - * Son Ho - -* `Therp BV `_: - - * Ronald Portier diff --git a/mail_composer_cc_bcc_account/readme/CREDITS.md b/mail_composer_cc_bcc_account/readme/CREDITS.md index 920bdd595..2dae1962e 100644 --- a/mail_composer_cc_bcc_account/readme/CREDITS.md +++ b/mail_composer_cc_bcc_account/readme/CREDITS.md @@ -1,2 +1,2 @@ -The creation and migration from 15.0 to 16.0 of this module were +The creation and migration from 16.0 to 17.0 of this module were financially supported by Camptocamp. diff --git a/mail_composer_cc_bcc_account/readme/CREDITS.rst b/mail_composer_cc_bcc_account/readme/CREDITS.rst deleted file mode 100644 index 9b2d6beda..000000000 --- a/mail_composer_cc_bcc_account/readme/CREDITS.rst +++ /dev/null @@ -1 +0,0 @@ -The creation and migration from 15.0 to 16.0 of this module were financially supported by Camptocamp. diff --git a/mail_composer_cc_bcc_account/readme/DESCRIPTION.rst b/mail_composer_cc_bcc_account/readme/DESCRIPTION.rst deleted file mode 100644 index 90919d9a7..000000000 --- a/mail_composer_cc_bcc_account/readme/DESCRIPTION.rst +++ /dev/null @@ -1,2 +0,0 @@ -This module allows to properly separate To:, Cc:, and Bcc: fields -in when sending invoices. diff --git a/mail_composer_cc_bcc_account/readme/USAGE.md b/mail_composer_cc_bcc_account/readme/USAGE.md index b78e5df9f..149cff74b 100644 --- a/mail_composer_cc_bcc_account/readme/USAGE.md +++ b/mail_composer_cc_bcc_account/readme/USAGE.md @@ -1,2 +1 @@ -Use the cc and bcc fields when sending invoices, to notify other -partners then the invoice contact of the customer. +Use the cc and bcc fields when sending invoices, to notify other partners then the invoice contact of the customer. diff --git a/mail_composer_cc_bcc_account/readme/USAGE.rst b/mail_composer_cc_bcc_account/readme/USAGE.rst deleted file mode 100644 index e75bb7cd3..000000000 --- a/mail_composer_cc_bcc_account/readme/USAGE.rst +++ /dev/null @@ -1,2 +0,0 @@ -Use the cc and bcc fields when sending invoices, to notify other partners then -the invoice contact of the customer. diff --git a/mail_composer_cc_bcc_account/static/description/index.html b/mail_composer_cc_bcc_account/static/description/index.html index 6a27db281..f7bd6c6fa 100644 --- a/mail_composer_cc_bcc_account/static/description/index.html +++ b/mail_composer_cc_bcc_account/static/description/index.html @@ -8,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. @@ -274,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 } @@ -300,7 +301,7 @@ span.option { span.pre { white-space: pre } -span.problematic { +span.problematic, pre.problematic { color: red } span.section-subtitle { @@ -441,13 +442,15 @@ If you spotted it first, help us to smash it by providing a detailed and welcome

Other credits

-

The creation and migration from 15.0 to 16.0 of this module were +

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

Maintainers

This module is maintained by the OCA.

-Odoo Community Association + +Odoo Community Association +

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.

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 a189cb713..f20255007 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,5 +1,6 @@ # Copyright 2023 Camptocamp # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from datetime import date from odoo.tests import Form @@ -9,31 +10,49 @@ from odoo.addons.mail_composer_cc_bcc.tests.test_mail_cc_bcc import TestMailCcBc class TestMailCcBccInvoice(TestMailCcBcc): def open_invoice_mail_composer_form(self): # Use form to populate data - for_name = [("name", "like", "%INV/20__/00003")] - self.test_invoice = test_record = self.env["account.move"].search(for_name) + # 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, + } + ) + self.assertTrue( self.test_invoice, - "Test setup did not succeeed. Invoice not found.", + "Test setup did not succeed. Invoice not found.", ) + 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.invoice.send"].with_context(**ctx)) - form.body = "

Hello

" + 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.subject = "Hello" + form.mail_subject = "Hello" composer = form.save() with self.mock_mail_gateway(): - composer._send_email() + composer.action_send_and_print() message = self.test_invoice.message_ids[0] self.assertEqual(len(message.mail_ids), 1) - # Only 4 partners notified - self.assertEqual(len(message.notified_partner_ids), 4) - self.assertEqual(len(message.notification_ids), 4) + + # 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) diff --git a/mail_composer_cc_bcc_account/wizards/__init__.py b/mail_composer_cc_bcc_account/wizards/__init__.py new file mode 100644 index 000000000..cf39f38e7 --- /dev/null +++ b/mail_composer_cc_bcc_account/wizards/__init__.py @@ -0,0 +1 @@ +from . import account_move_send diff --git a/mail_composer_cc_bcc_account/wizards/account_move_send.py b/mail_composer_cc_bcc_account/wizards/account_move_send.py new file mode 100644 index 000000000..e300400d4 --- /dev/null +++ b/mail_composer_cc_bcc_account/wizards/account_move_send.py @@ -0,0 +1,129 @@ +# 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_invoice_send_views.xml b/mail_composer_cc_bcc_account/wizards/account_move_send.xml similarity index 51% rename from mail_composer_cc_bcc_account/wizards/account_invoice_send_views.xml rename to mail_composer_cc_bcc_account/wizards/account_move_send.xml index c618c098b..8ada0cd1c 100644 --- a/mail_composer_cc_bcc_account/wizards/account_invoice_send_views.xml +++ b/mail_composer_cc_bcc_account/wizards/account_move_send.xml @@ -1,23 +1,24 @@ - - account.invoice.send.form.inherit - account.invoice.send - + + account.move.send.form.inherit + account.move.send + - + +