diff --git a/addons/account/wizard/account_move_send.py b/addons/account/wizard/account_move_send.py index 0661de1d9a8..00366a13c48 100644 --- a/addons/account/wizard/account_move_send.py +++ b/addons/account/wizard/account_move_send.py @@ -501,7 +501,7 @@ class AccountMoveSend(models.TransientModel): def _send_mails(self, moves_data): subtype = self.env.ref('mail.mt_comment') - for move, move_data in moves_data.items(): + for move, move_data in [(move, move_data) for move, move_data in moves_data.items() if move.partner_id.email]: mail_template = move_data['mail_template_id'] mail_lang = move_data['mail_lang'] mail_params = self._get_mail_params(move, move_data) @@ -659,7 +659,7 @@ class AccountMoveSend(models.TransientModel): self._generate_invoice_fallback_documents(errors) # Send mail. - success = {move: move_data for move, move_data in moves_data.items() if not move_data.get('error') and move.partner_id.email} + success = {move: move_data for move, move_data in moves_data.items() if not move_data.get('error')} if success: self._hook_if_success(success, from_cron=from_cron, allow_fallback_pdf=allow_fallback_pdf) diff --git a/addons/snailmail_account/tests/__init__.py b/addons/snailmail_account/tests/__init__.py index b81c3a2d614..b7f7b9f9004 100644 --- a/addons/snailmail_account/tests/__init__.py +++ b/addons/snailmail_account/tests/__init__.py @@ -1 +1,2 @@ from . import test_pingen_send +from . import test_snailmail_on_invoice diff --git a/addons/snailmail_account/tests/test_snailmail_on_invoice.py b/addons/snailmail_account/tests/test_snailmail_on_invoice.py new file mode 100644 index 00000000000..9b2f9979737 --- /dev/null +++ b/addons/snailmail_account/tests/test_snailmail_on_invoice.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. +from odoo.tests import TransactionCase, tagged +from odoo import Command + +@tagged('post_install', '-at_install') +class TestSnailmailOnInvoice(TransactionCase): + def test_snailmail_on_invoice_for_partner_without_email(self): + """" + Checks that a snailmail letter is created when one print and send by post a customer invoice + for a partner without email. + """ + + partner_without_email = self.env['res.partner'].create({ + 'name': 'Partner_without_email', + 'email': False, + }) + + product = self.env['product.product'].create({ + 'name': 'product', + 'sale_ok': True, + 'standard_price': 100.0, + }) + + invoice = self.env['account.move'].create({ + 'move_type': 'out_invoice', + 'partner_id': partner_without_email.id, + 'invoice_date': '2019-01-01', + 'invoice_line_ids': [Command.create({'product_id': product.id})], + }) + invoice.action_post() + + print_wiz = self.env['account.move.send'].create({ + 'move_ids': invoice.ids, + 'checkbox_download': False, + 'checkbox_send_mail': False, + 'checkbox_send_by_post': True, + }) + print_wiz.action_send_and_print() + + letter = self.env['snailmail.letter'].search([ + ('partner_id', '=', partner_without_email.id), + ('model', '=', invoice._name), + ('res_id', '=', invoice.id), + ], limit=1) + self.assertTrue(letter)