[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) <bib@odoo.com>
This commit is contained in:
det
2023-04-27 00:52:20 +02:00
parent d563481306
commit 244b8502d2
4 changed files with 31 additions and 5 deletions
+15
View File
@@ -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
# -------------------------------------------------------------------------
@@ -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.
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from . import account_move
from . import res_company
from . import res_config_settings
@@ -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