Skip to content

Commit

Permalink
[MIG] mail_attach_existing_attachment_account: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
damdam-s committed Jan 20, 2025
1 parent 8afe237 commit 1ff4372
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 51 deletions.
4 changes: 2 additions & 2 deletions mail_attach_existing_attachment_account/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion mail_attach_existing_attachment_account/wizard/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from . import account_invoice_send
from . import account_move_send

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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(

Check warning on line 27 in mail_attach_existing_attachment_account/wizard/account_move_send.py

View check run for this annotation

Codecov / codecov/patch

mail_attach_existing_attachment_account/wizard/account_move_send.py#L27

Added line #L27 was not covered by tests
[
("res_model", "=", "account.move"),
("res_id", "in", self.move_ids.ids),
]
)
wizard.display_object_attachment_ids = attachments

Check warning on line 33 in mail_attach_existing_attachment_account/wizard/account_move_send.py

View check run for this annotation

Codecov / codecov/patch

mail_attach_existing_attachment_account/wizard/account_move_send.py#L33

Added line #L33 was not covered by tests
else:
wizard.display_object_attachment_ids = False

Check warning on line 35 in mail_attach_existing_attachment_account/wizard/account_move_send.py

View check run for this annotation

Codecov / codecov/patch

mail_attach_existing_attachment_account/wizard/account_move_send.py#L35

Added line #L35 was not covered by tests

# 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()
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
Copyright 2019 Thore Baden
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
-->
<odoo>
<record id="account_move_send_form" model="ir.ui.view">
<field name="name">Send Invoice</field>
<field name="model">account.move.send</field>
<field name="inherit_id" ref="account.account_move_send_form" />
<field name="arch" type="xml">
<xpath expr="//field[@name='mail_attachments_widget']" position="after">
<field name="can_attach_attachment" invisible="1" />
<field
name="object_attachment_ids"
widget="many2many_checkboxes"
domain="[('res_model', '=', 'account.move'), ('res_id', 'in', move_ids)]"
invisible="can_attach_attachment==False"
/>
</xpath>
</field>
</record>
</odoo>

0 comments on commit 1ff4372

Please sign in to comment.