From f210c4c933e4ad36975be3a49fa0cf316f1f457f Mon Sep 17 00:00:00 2001
From: Florent de Labarre <florent.mirieu@gmail.com>
Date: Fri, 4 Aug 2023 08:41:14 +0000
Subject: [PATCH] [FIX] account: fin tunning of
 https://github.com/odoo/odoo/pull/128420

Before this commit there are no rollback if raise.

closes odoo/odoo#130831

Signed-off-by: John Laterre (jol) <jol@odoo.com>
---
 addons/account/models/account_move.py | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py
index 3d96cce9f64e..7f2987d0ea71 100644
--- a/addons/account/models/account_move.py
+++ b/addons/account/models/account_move.py
@@ -3106,11 +3106,13 @@ class AccountMove(models.Model):
         for ids in self._cr.split_for_in_conditions(records.ids, size=100):
             moves = self.browse(ids)
             try:  # try posting in batch
-                moves._post()
+                with self.env.cr.savepoint():
+                    moves._post()
             except UserError:  # if at least one move cannot be posted, handle moves one by one
                 for move in moves:
                     try:
-                        move._post()
+                        with self.env.cr.savepoint():
+                            move._post()
                     except UserError as e:
                         move.to_check = True
                         msg = _('The move could not be posted for the following reason: %(error_message)s', error_message=e)
-- 
GitLab