-
-
Notifications
You must be signed in to change notification settings - Fork 637
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIG] mail_composer_cc_bcc_account: Migration to 17.0
- Loading branch information
Showing
11 changed files
with
210 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,6 @@ | |
"preloadable": True, | ||
"depends": [ | ||
"mail", | ||
"account", | ||
], | ||
"data": [ | ||
"views/res_company_views.xml", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
# Copyright 2024 Camptocamp | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from . import models | ||
from . import wizards |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import mail_thread |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
* Hai N. Le <[email protected]> | ||
* Son Ho <[email protected]> | ||
* Tris Doan <[email protected]> | ||
|
||
* `Therp BV <https://therp.nl>`_: | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import account_move_send |
139 changes: 139 additions & 0 deletions
139
mail_composer_cc_bcc_account/wizards/account_move_send.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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", | ||
"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, | ||
} | ||
) |
15 changes: 8 additions & 7 deletions
15
...nt/wizards/account_invoice_send_views.xml → ...bcc_account/wizards/account_move_send.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters