-
-
Notifications
You must be signed in to change notification settings - Fork 633
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIG] mail_attach_existing_attachment_account: Migration to 17.0
- Loading branch information
Showing
7 changed files
with
89 additions
and
51 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
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 @@ | ||
from . import account_invoice_send | ||
from . import account_move_send |
22 changes: 0 additions & 22 deletions
22
mail_attach_existing_attachment_account/wizard/account_invoice_send.py
This file was deleted.
Oops, something went wrong.
25 changes: 0 additions & 25 deletions
25
mail_attach_existing_attachment_account/wizard/account_invoice_send_view.xml
This file was deleted.
Oops, something went wrong.
62 changes: 62 additions & 0 deletions
62
mail_attach_existing_attachment_account/wizard/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,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() |
23 changes: 23 additions & 0 deletions
23
mail_attach_existing_attachment_account/wizard/account_move_send_view.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
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> |