-
-
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.
- Loading branch information
Showing
4 changed files
with
55 additions
and
25 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
2 changes: 1 addition & 1 deletion
2
mail_template_attach_existing_attachment_account/wizard/__init__.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 |
---|---|---|
@@ -1 +1 @@ | ||
from . import account_invoice_send | ||
from . import account_move_send |
14 changes: 0 additions & 14 deletions
14
mail_template_attach_existing_attachment_account/wizard/account_invoice_send.py
This file was deleted.
Oops, something went wrong.
44 changes: 44 additions & 0 deletions
44
mail_template_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,44 @@ | ||
# Copyright 2022 Foodles (http://www.foodles.co). | ||
# @author Pierre Verkest <[email protected]> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
import re | ||
|
||
from odoo import api, models | ||
|
||
|
||
class AccountMoveSend(models.TransientModel): | ||
_inherit = "account.move.send" | ||
|
||
@api.model | ||
def _match_attachment(self, re_pattern, model, res_ids): | ||
"""Could be nice to perform regex in sql side using PGSQL `~` operator""" | ||
return ( | ||
self.env["ir.attachment"] | ||
.sudo() | ||
.search( | ||
[ | ||
("res_model", "=", model), | ||
("res_id", "in", res_ids), | ||
], | ||
order="res_id", | ||
) | ||
.filtered( | ||
lambda attachement, pattern=re_pattern: pattern.match(attachement.name) | ||
is not None | ||
) | ||
) | ||
|
||
def _get_regex_attachment_ids(self): | ||
self.ensure_one() | ||
object_attachment_ids = self.env["ir.attachment"].browse() | ||
if self.mail_template_id and self.mail_template_id.attach_exist_document_regex: | ||
pattern = re.compile(self.mail_template_id.attach_exist_document_regex) | ||
object_attachment_ids |= self._match_attachment( | ||
pattern, "account.move", self.move_ids.ids | ||
) | ||
|
||
@api.model | ||
def _get_invoice_extra_attachments(self, move): | ||
res = super()._get_invoice_extra_attachments(move) | ||
res |= self._get_regex_attachment_ids() | ||
return res |