From 244b8502d24e847caf9909446ebcffdee4e7c202 Mon Sep 17 00:00:00 2001 From: det Date: Thu, 30 Mar 2023 08:38:23 +0000 Subject: [PATCH] [IMP] account: helper to generate invoices via send&print https://github.com/odoo/odoo/commit/955091e707df1206ccda8314f1f182e2a37a8362 changed the way we want to generate invoices. This commit provides an helper method to be used in others modules to properly generate and send invoices following the send&print flow. task-id:3253019 closes odoo/odoo#119759 X-original-commit: 8dbf4c8390d9d0e4e2050b0ca318fcb2ec9dc3b0 Related: odoo/enterprise#40330 Signed-off-by: Brice Bartoletti (bib) --- addons/account/models/account_move.py | 15 +++++++++++++++ .../tests/common.py | 6 +----- addons/snailmail_account/models/__init__.py | 1 + addons/snailmail_account/models/account_move.py | 14 ++++++++++++++ 4 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 addons/snailmail_account/models/account_move.py diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index baef76b2b44..f0b1f2430a5 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -4011,6 +4011,21 @@ class AccountMove(models.Model): return rslt + def _get_pdf_and_send_invoice_vals(self, template): + return { + 'mail_template_id': template.id, + 'move_ids': self.ids, + 'checkbox_send_mail': True, + 'checkbox_download': False, + } + + def _generate_pdf_and_send_invoice(self, template, from_cron=True): + composer_vals = self._get_pdf_and_send_invoice_vals(template) + composer = self.env['account.move.send'].create(composer_vals) + + # from_cron=True to log errors in chatter instead of raise + composer.action_send_and_print(from_cron=from_cron) + # ------------------------------------------------------------------------- # TOOLING # ------------------------------------------------------------------------- diff --git a/addons/l10n_account_edi_ubl_cii_tests/tests/common.py b/addons/l10n_account_edi_ubl_cii_tests/tests/common.py index c8b24c970b9..d38351163ec 100644 --- a/addons/l10n_account_edi_ubl_cii_tests/tests/common.py +++ b/addons/l10n_account_edi_ubl_cii_tests/tests/common.py @@ -200,13 +200,9 @@ class TestUBLCommon(AccountTestInvoicingCommon): }) account_move.action_post() - self.action_send_and_print(account_move) + account_move._generate_pdf_and_send_invoice(self.move_template) return account_move - def action_send_and_print(self, invoice): - composer = self.env['account.move.send'].create({'mail_template_id': self.move_template.id, 'move_ids': invoice.ids}) - composer.action_send_and_print() - def _assert_invoice_attachment(self, attachment, xpaths, expected_file): """ Get attachment from a posted account.move, and asserts it's the same as the expected xml file. diff --git a/addons/snailmail_account/models/__init__.py b/addons/snailmail_account/models/__init__.py index 883205a7200..bc1b4319653 100644 --- a/addons/snailmail_account/models/__init__.py +++ b/addons/snailmail_account/models/__init__.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +from . import account_move from . import res_company from . import res_config_settings diff --git a/addons/snailmail_account/models/account_move.py b/addons/snailmail_account/models/account_move.py new file mode 100644 index 00000000000..5e623fade6d --- /dev/null +++ b/addons/snailmail_account/models/account_move.py @@ -0,0 +1,14 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import models + + +class AccountMove(models.Model): + _inherit = "account.move" + + def _get_pdf_and_send_invoice_vals(self, template): + # EXTENDS account + vals = super()._get_pdf_and_send_invoice_vals(template) + vals['checkbox_send_by_post'] = False + return vals