Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][IMP] account_invoice_mass_sending: Add EDI documents to mass sending email #1876

Draft
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion account_invoice_mass_sending/models/account_move.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2019 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import _, fields, models
from odoo import Command, _, fields, models


class AccountInvoice(models.Model):
Expand Down Expand Up @@ -58,6 +58,7 @@ def _send_invoice_individually(self, template=None):
"is_email": True,
"template_id": template.id,
"composition_mode": "comment",
"attachment_ids": [Command.set(self._get_edi_documents())],
}
)
wiz.onchange_template_id()
Expand All @@ -67,3 +68,13 @@ def _send_invoice_individually(self, template=None):
}
)
return wiz.send_and_print_action()

def _get_edi_documents(self):
self.ensure_one()
attachment_ids = []
if getattr(self, "edi_document_ids", False):
for edi in self.edi_document_ids:
attachment = self._get_edi_attachment(edi.edi_format_id)
if attachment:
attachment_ids.append(attachment.id)
return attachment_ids
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,57 @@ def test_invoice_mass_sending_3(self):
)
trap.perform_enqueued_jobs()
self.assertFalse(self.first_eligible_invoice.sending_in_progress)

def _create_attachment(self, invoice):
document = self.env["ir.attachment"].create(
{
"name": "EDI Document",
"res_model": "account.move",
"res_id": invoice.id,
"mimetype": "application/xml",
}
)
return document

def create_edi_document(self, state, move=None, move_type=None):
edi_format = (
self.env["account.edi.format"]
.sudo()
.create(
{
"name": "test_edi_format",
"code": "test_edi_format",
}
)
)
return self.env["account.edi.document"].create(
{"edi_format_id": edi_format.id, "move_id": move.id, "state": state}
)

def test_invoice_mass_sending_4(self):
# test one invoice to send with edi document attached
invoice = self.first_eligible_invoice
attachment = self._create_attachment(invoice)
edi_document = self.create_edi_document("sent", invoice, invoice.move_type)
edi_document.attachment_id = attachment.id
self.assertEqual(len(invoice.edi_document_ids), 1)
self.assertEqual(len(invoice.attachment_ids), 1)
with trap_jobs() as trap:
wizard = self.wizard_obj.with_context(
active_ids=invoice.ids,
active_model=self.first_eligible_invoice._name,
discard_logo_check=True,
).create({})
wizard.enqueue_invoices()
trap.assert_jobs_count(1)
trap.assert_enqueued_job(
invoice._send_invoice_individually,
kwargs={"template": self.mail_template_obj},
)
trap.perform_enqueued_jobs()
mail = self.env["mail.mail"].search(
[("model", "=", "account.move"), ("res_id", "=", invoice.id)]
)
self.assertTrue(mail)
attachment_ids = mail.attachment_ids.ids
self.assertIn(attachment_ids[0], invoice.attachment_ids.ids)
Loading