From 5ac8fb18cae190734986a4ec1fa4b607774f4246 Mon Sep 17 00:00:00 2001 From: Valentin Chevalier Date: Thu, 14 Mar 2024 19:09:39 +0100 Subject: [PATCH] [FIX] sale: post processing issues when creating invoices Before this commit, when the automatic invoice setting is enabled, a traceback would be shown when customers pay and the post-processing of the transaction tries to create an invoice. The problem is that the invoice is created in sudo, but it's unsudoed before logging invoices in the chatter. Now, the invoice will stay sudoed if the method is called in sudo. opw-3700576 closes odoo/odoo#157779 Signed-off-by: Victor Feyens (vfe) --- addons/sale/wizard/sale_make_invoice_advance.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/addons/sale/wizard/sale_make_invoice_advance.py b/addons/sale/wizard/sale_make_invoice_advance.py index 08587d7eee2..46d4c211a5d 100644 --- a/addons/sale/wizard/sale_make_invoice_advance.py +++ b/addons/sale/wizard/sale_make_invoice_advance.py @@ -221,7 +221,7 @@ class SaleAdvancePaymentInv(models.TransientModel): invoice = self.env['account.move'].sudo().create( self._prepare_invoice_values(order, down_payment_lines) - ).with_user(self.env.uid) # Unsudo the invoice after creation + ) # Ensure the invoice total is exactly the expected fixed amount. if self.advance_payment_method == 'fixed': @@ -256,6 +256,9 @@ class SaleAdvancePaymentInv(models.TransientModel): line_commands.append(Command.update(line.id, {attr: line[attr] + amt * sign})) invoice.line_ids = line_commands + # Unsudo the invoice after creation if not already sudoed + invoice = invoice.sudo(self.env.su) + poster = self.env.user._is_internal() and self.env.user.id or SUPERUSER_ID invoice.with_user(poster).message_post_with_source( 'mail.message_origin_link',