From dcbc48fc91f2ad46c5d8a5fdad85f6cc4f41a94e 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/__manifest__.py | 1 - .../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 | 3 +- .../tests/test_mail_cc_bcc.py | 39 +++-- .../wizards/__init__.py | 1 + .../wizards/account_move_send.py | 139 ++++++++++++++++++ ...e_send_views.xml => account_move_send.xml} | 15 +- 20 files changed, 236 insertions(+), 67 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/__manifest__.py b/mail_composer_cc_bcc/__manifest__.py index bd2d7b01a5..fded5edf2e 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/tests/test_mail_cc_bcc.py b/mail_composer_cc_bcc/tests/test_mail_cc_bcc.py index ec9fe77b58..051a3a5aa4 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 @@ def test_template_cc_bcc(self): # 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 @@ def test_template_cc_bcc(self): (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 @@ def test_template_cc_bcc(self): 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 @@ def test_template_cc_bcc(self): 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 9411e0a70f..b9ca300112 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 ef5ae3587f..c5e1e97859 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 4dcb8f3823..1215789db4 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 0000000000..b70a9f2d08 --- /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 0000000000..c459d1dd5d --- /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 eddd34da07..2ccf27bc9a 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 eddd34da07..0000000000 --- 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 707d8e429d..0000000000 --- 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 920bdd5956..2dae1962ef 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 9b2d6bedaa..0000000000 --- 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 90919d9a7c..0000000000 --- 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 b78e5df9fa..149cff74ba 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 e75bb7cd3a..0000000000 --- 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 6a27db281b..c8416e55a6 100644 --- a/mail_composer_cc_bcc_account/static/description/index.html +++ b/mail_composer_cc_bcc_account/static/description/index.html @@ -1,3 +1,4 @@ + @@ -441,7 +442,7 @@

Contributors

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.

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 a189cb713e..f20255007e 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 @@ 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 0000000000..cf39f38e70 --- /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 0000000000..2d2c437bcc --- /dev/null +++ b/mail_composer_cc_bcc_account/wizards/account_move_send.py @@ -0,0 +1,139 @@ +# 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_default_mail_partner_cc_ids(self, move, mail_template): + partners = self.env["res.partner"].with_company(move.company_id) + if mail_template.email_cc: + for mail_data in tools.email_split(mail_template.email_cc): + partners |= partners.find_or_create(mail_data) + return partners + + def _get_default_mail_partner_bcc_ids(self, move, mail_template): + partners = self.env["res.partner"].with_company(move.company_id) + if mail_template.email_bcc: + for mail_data in tools.email_split(mail_template.email_bcc): + 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_default_mail_partner_cc_ids( + self.move_ids, wizard.mail_template_id + ) + wizard.partner_bcc_ids = self._get_default_mail_partner_bcc_ids( + self.move_ids, wizard.mail_template_id + ) + 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", []) + + new_message = 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, + ).message_post( + message_type="comment", + **kwargs, + **{ + "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, + }, + ) + + # 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 c618c098b1..8ada0cd1c5 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 + - + +