From 1ff43729ce9ee3b72541e961757cd9c0720dba3a Mon Sep 17 00:00:00 2001 From: Damien Crier Date: Thu, 16 Jan 2025 15:08:40 +0100 Subject: [PATCH] [MIG] mail_attach_existing_attachment_account: Migration to 17.0 --- .../__manifest__.py | 4 +- ...mail_attach_existing_attachment_account.py | 2 +- .../wizard/__init__.py | 2 +- .../wizard/account_invoice_send.py | 22 ------- .../wizard/account_invoice_send_view.xml | 25 -------- .../wizard/account_move_send.py | 62 +++++++++++++++++++ .../wizard/account_move_send_view.xml | 23 +++++++ 7 files changed, 89 insertions(+), 51 deletions(-) delete mode 100644 mail_attach_existing_attachment_account/wizard/account_invoice_send.py delete mode 100644 mail_attach_existing_attachment_account/wizard/account_invoice_send_view.xml create mode 100644 mail_attach_existing_attachment_account/wizard/account_move_send.py create mode 100644 mail_attach_existing_attachment_account/wizard/account_move_send_view.xml diff --git a/mail_attach_existing_attachment_account/__manifest__.py b/mail_attach_existing_attachment_account/__manifest__.py index 002c4ceda3..46ac674117 100644 --- a/mail_attach_existing_attachment_account/__manifest__.py +++ b/mail_attach_existing_attachment_account/__manifest__.py @@ -7,10 +7,10 @@ "author": "Thore Baden, Odoo Community Association (OCA)", "website": "https://github.com/OCA/social", "category": "Social Network", - "version": "16.0.1.0.1", + "version": "17.0.1.0.0", "license": "AGPL-3", "depends": ["account", "mail_attach_existing_attachment"], - "data": ["wizard/account_invoice_send_view.xml"], + "data": ["wizard/account_move_send_view.xml"], "installable": True, "auto_install": True, } diff --git a/mail_attach_existing_attachment_account/tests/test_mail_attach_existing_attachment_account.py b/mail_attach_existing_attachment_account/tests/test_mail_attach_existing_attachment_account.py index 3b6068aa0a..ef110542bb 100644 --- a/mail_attach_existing_attachment_account/tests/test_mail_attach_existing_attachment_account.py +++ b/mail_attach_existing_attachment_account/tests/test_mail_attach_existing_attachment_account.py @@ -23,7 +23,7 @@ def setUpClass(cls): def test_account_invoice_send(self): compose = Form( - self.env["account.invoice.send"].with_context( + self.env["account.move.send"].with_context( active_ids=self.invoice.ids, default_model=self.invoice._name, default_res_id=self.invoice.id, diff --git a/mail_attach_existing_attachment_account/wizard/__init__.py b/mail_attach_existing_attachment_account/wizard/__init__.py index edaf0442f2..cf39f38e70 100644 --- a/mail_attach_existing_attachment_account/wizard/__init__.py +++ b/mail_attach_existing_attachment_account/wizard/__init__.py @@ -1 +1 @@ -from . import account_invoice_send +from . import account_move_send diff --git a/mail_attach_existing_attachment_account/wizard/account_invoice_send.py b/mail_attach_existing_attachment_account/wizard/account_invoice_send.py deleted file mode 100644 index 8485d3d3cd..0000000000 --- a/mail_attach_existing_attachment_account/wizard/account_invoice_send.py +++ /dev/null @@ -1,22 +0,0 @@ -# Copyright 2021 Tecnativa - Víctor Martínez -# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). - -from odoo import api, fields, models - - -class AccountInvoiceSend(models.TransientModel): - _inherit = "account.invoice.send" - - @api.model - def default_get(self, fields_list): - res = super().default_get(fields_list) - if ( - res.get("res_id") - and res.get("model") - and res.get("composition_mode", "") != "mass_mail" - and not res.get("can_attach_attachment") - ): - res["can_attach_attachment"] = True # pragma: no cover - return res - - can_attach_attachment = fields.Boolean() diff --git a/mail_attach_existing_attachment_account/wizard/account_invoice_send_view.xml b/mail_attach_existing_attachment_account/wizard/account_invoice_send_view.xml deleted file mode 100644 index 5b9718ac68..0000000000 --- a/mail_attach_existing_attachment_account/wizard/account_invoice_send_view.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - Send Invoice - account.invoice.send - - - - - - - - - - - diff --git a/mail_attach_existing_attachment_account/wizard/account_move_send.py b/mail_attach_existing_attachment_account/wizard/account_move_send.py new file mode 100644 index 0000000000..31e6aa5991 --- /dev/null +++ b/mail_attach_existing_attachment_account/wizard/account_move_send.py @@ -0,0 +1,62 @@ +# Copyright 2021 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class AccountMoveSend(models.TransientModel): + _inherit = "account.move.send" + + can_attach_attachment = fields.Boolean() + object_attachment_ids = fields.Many2many( + comodel_name="ir.attachment", + relation="account_move_send_ir_attachments_object_rel", + column1="wizard_id", + column2="attachment_id", + string="Object Attachments", + ) + display_object_attachment_ids = fields.One2many( + comodel_name="ir.attachment", + compute="_compute_display_object_attachment_ids", + ) + + @api.depends("move_ids") + def _compute_display_object_attachment_ids(self): + for wizard in self: + if self.move_ids: + attachments = self.env["ir.attachment"].search( + [ + ("res_model", "=", "account.move"), + ("res_id", "in", self.move_ids.ids), + ] + ) + wizard.display_object_attachment_ids = attachments + else: + wizard.display_object_attachment_ids = False + + # def _prepare_mail_values(self, res_ids): + # res = super()._prepare_mail_values(res_ids) + # if self.object_attachment_ids.ids and self.model and len(res_ids) == 1: + # res[res_ids[0]].setdefault("attachment_ids", []).extend( + # self.object_attachment_ids.ids + # ) + # return res + + @api.model + def _get_invoice_extra_attachments(self, move): + res = super()._get_invoice_extra_attachments(move) + res |= self.object_attachment_ids + return res + + @api.model + def default_get(self, fields_list): + res = super().default_get(fields_list) + if ( + res.get("move_ids") + and res.get("mode", "") != "invoice_multi" + and not res.get("can_attach_attachment") + ): + res["can_attach_attachment"] = True # pragma: no cover + return res + + can_attach_attachment = fields.Boolean() diff --git a/mail_attach_existing_attachment_account/wizard/account_move_send_view.xml b/mail_attach_existing_attachment_account/wizard/account_move_send_view.xml new file mode 100644 index 0000000000..a4707cb240 --- /dev/null +++ b/mail_attach_existing_attachment_account/wizard/account_move_send_view.xml @@ -0,0 +1,23 @@ + + + + + Send Invoice + account.move.send + + + + + + + + +