diff --git a/addons/account/wizard/account_invoice_send.py b/addons/account/wizard/account_invoice_send.py index dc42d1541d6..b1d64c971e9 100644 --- a/addons/account/wizard/account_invoice_send.py +++ b/addons/account/wizard/account_invoice_send.py @@ -31,23 +31,23 @@ class AccountInvoiceSend(models.TransientModel): readonly=True) @api.model - def default_get(self, fields): - res = super(AccountInvoiceSend, self).default_get(fields) - res_ids = self._context.get('active_ids') + def default_get(self, fields_list): + result = super().default_get(fields_list) + res_ids = self.env.context.get('active_ids') invoices = self.env['account.move'].browse(res_ids).filtered(lambda move: move.is_invoice(include_receipts=True)) if not invoices: raise UserError(_("You can only send invoices.")) - composer = self.env['mail.compose.message'].create({ - 'composition_mode': 'comment' if len(res_ids) == 1 else 'mass_mail', - 'subtype_id': self.env['ir.model.data']._xmlid_to_res_id('mail.mt_comment'), - }) - res.update({ - 'invoice_ids': res_ids, - 'composer_id': composer.id, - }) - return res + if 'invoice_ids' in fields_list and not result.get('invoice_ids'): + result['invoice_ids'] = res_ids + if 'composer_id' in fields_list and not result.get('composer_id'): + composer = self.env['mail.compose.message'].create({ + 'composition_mode': 'comment' if len(res_ids) == 1 else 'mass_mail', + 'subtype_id': self.env['ir.model.data']._xmlid_to_res_id('mail.mt_comment'), + }) + result['composer_id'] = composer.id + return result @api.onchange('invoice_ids') def _compute_composition_mode(self): diff --git a/addons/account/wizard/account_invoice_send_views.xml b/addons/account/wizard/account_invoice_send_views.xml index f37c5006cf4..46de03f03ed 100644 --- a/addons/account/wizard/account_invoice_send_views.xml +++ b/addons/account/wizard/account_invoice_send_views.xml @@ -14,10 +14,17 @@ + - + + + + + + +
diff --git a/addons/l10n_generic_coa/tests/test_mail_performance.py b/addons/l10n_generic_coa/tests/test_mail_performance.py index eb32053b6f4..b52914c6597 100644 --- a/addons/l10n_generic_coa/tests/test_mail_performance.py +++ b/addons/l10n_generic_coa/tests/test_mail_performance.py @@ -61,7 +61,7 @@ class BaseMailAccountPerformance(AccountTestInvoicingCommon, MailCommon): ]) ], 'login': 'user_account', - 'name': 'Ernest Employee', + 'name': 'Ernest Employee Account', 'notification_type': 'inbox', 'signature': '--\nErnest', }) @@ -77,7 +77,7 @@ class BaseMailAccountPerformance(AccountTestInvoicingCommon, MailCommon): ]) ], 'login': 'user_account_other', - 'name': 'Eglantine Employee', + 'name': 'Eglantine Employee AccountOther', 'notification_type': 'inbox', 'signature': '--\nEglantine', }) @@ -134,6 +134,19 @@ class BaseMailAccountPerformance(AccountTestInvoicingCommon, MailCommon): class TestAccountComposerPerformance(BaseMailAccountPerformance): """ Test performance of custom composer for moves. """ + def test_assert_initial_values(self): + """ Test initial values to ease understanding of results and notifications """ + for move in self.test_account_moves: + with self.subTest(move=move): + self.assertEqual( + move.invoice_user_id, + self.user_account_other, + ) + self.assertEqual( + move.message_partner_ids, + self.user_accountman.partner_id, + ) + @users('user_account') @warmup @mute_logger('odoo.addons.mail.models.mail_mail', 'odoo.models.unlink')