[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) <vfe@odoo.com>
This commit is contained in:
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user