[FIX] sale: correctly send auto-generated invoices

Since 4d2b04a843, invoices
auto-generated on Sales Order payment were not sent to
customers.

Invoices are only marked as 'posted' in the override
of `_reconcile_after_done` in account_payment which means
`_send_invoice` must be called after the super call s.t.
the invoices are correctly posted before being sent.

opw-3158620

closes odoo/odoo#113229

X-original-commit: 82c53dd3404992b14d1db331c37b6d03c9f0ace1
Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
This commit is contained in:
Victor Feyens
2023-02-21 21:07:21 +01:00
parent f8f4e899b5
commit 624b2feef1
2 changed files with 7 additions and 3 deletions
+6 -3
View File
@@ -116,13 +116,16 @@ class PaymentTransaction(models.Model):
confirmed_orders = self._check_amount_and_confirm_order()
confirmed_orders._send_order_confirmation_mail()
# invoice the sale orders if needed and send it
if str2bool(self.env['ir.config_parameter'].sudo().get_param('sale.automatic_invoice')):
auto_invoice = str2bool(
self.env['ir.config_parameter'].sudo().get_param('sale.automatic_invoice'))
if auto_invoice:
# Invoice the sale orders in self instead of in confirmed_orders to create the invoice
# even if only a partial payment was made.
self._invoice_sale_orders()
super()._reconcile_after_done()
if auto_invoice:
# Must be called after the super() call to make sure the invoice are correctly posted.
self._send_invoice()
return super()._reconcile_after_done()
def _send_invoice(self):
template_id = int(self.env['ir.config_parameter'].sudo().get_param(
+1
View File
@@ -230,6 +230,7 @@ class TestSalePayment(AccountPaymentCommon, SaleCommon, PaymentHttpCommon):
self.assertEqual(self.sale_order.state, 'done')
self.assertTrue(tx.invoice_ids)
self.assertTrue(self.sale_order.invoice_ids)
self.assertTrue(tx.invoice_ids.is_move_sent)
def test_so_partial_payment_no_invoice(self):
# Set automatic invoice