summaryrefslogtreecommitdiff
path: root/addons/account/wizard
diff options
context:
space:
mode:
authorLaurent Smet <las@odoo.com>2020-08-27 09:55:26 +0000
committerLaurent Smet <las@odoo.com>2020-09-01 13:57:41 +0000
commit3057ee6cdd63c0adb5037041492427268b5e7549 (patch)
tree3fdcefe4e097cc5ed2b106249e163c566713e92c /addons/account/wizard
parentd128097c43d79560aa8e166e04f2675568083f57 (diff)
[FIX] account,stock_account: Fix bad bug fixes
https://github.com/odoo/odoo/commit/5309c252f6d0bc4994265a4c39259b70e7507fb1 This fix isn't working when using the 'modify' refund_method. Also, you can't change the behavior of the whole invoices when there is only one move dealing with the auto_post feature. https://github.com/odoo/odoo/commit/c9cd83e538a0be9d626d7587c465924146327cb2 This fix is only fixing the reversal wizard but must be done everytime a journal entry is duplicated. closes odoo/odoo#56885 X-original-commit: 9b0aca617f20798eeb5ca2a538f6b9e241f752f4 Signed-off-by: oco-odoo <oco-odoo@users.noreply.github.com> Signed-off-by: Laurent Smet <smetl@users.noreply.github.com>
Diffstat (limited to 'addons/account/wizard')
-rw-r--r--addons/account/wizard/account_move_reversal.py50
1 files changed, 27 insertions, 23 deletions
diff --git a/addons/account/wizard/account_move_reversal.py b/addons/account/wizard/account_move_reversal.py
index b8945e92300..a3525107d92 100644
--- a/addons/account/wizard/account_move_reversal.py
+++ b/addons/account/wizard/account_move_reversal.py
@@ -72,6 +72,7 @@ class AccountMoveReversal(models.TransientModel):
}
def _reverse_moves_post_hook(self, moves):
+ # DEPRECATED: TO REMOVE IN MASTER
return
def reverse_moves(self):
@@ -83,28 +84,31 @@ class AccountMoveReversal(models.TransientModel):
for move in moves:
default_values_list.append(self._prepare_default_reversal(move))
+ batches = [
+ [self.env['account.move'], [], True], # Moves to be cancelled by the reverses.
+ [self.env['account.move'], [], False], # Others.
+ ]
+ for move, default_vals in zip(moves, default_values_list):
+ is_auto_post = bool(default_vals.get('auto_post'))
+ is_cancel_needed = not is_auto_post and self.refund_method in ('cancel', 'modify')
+ batch_index = 0 if is_cancel_needed else 1
+ batches[batch_index][0] |= move
+ batches[batch_index][1].append(default_vals)
+
# Handle reverse method.
- if self.refund_method == 'cancel':
- if any(vals.get('auto_post', False) for vals in default_values_list):
- new_moves = moves._reverse_moves(default_values_list)
- else:
- new_moves = moves._reverse_moves(default_values_list, cancel=True)
- elif self.refund_method == 'modify':
- moves._reverse_moves(default_values_list, cancel=True)
- moves_vals_list = []
- for move in moves.with_context(include_business_fields=True):
- moves_vals_list.append(move.copy_data({
- 'date': self.date if self.date_mode == 'custom' else move.date,
- })[0])
- new_moves = self.env['account.move'].create(moves_vals_list)
- elif self.refund_method == 'refund':
- new_moves = moves._reverse_moves(default_values_list)
- else:
- return
+ moves_to_redirect = self.env['account.move']
+ for moves, default_values_list, is_cancel_needed in batches:
+ new_moves = moves._reverse_moves(default_values_list, cancel=is_cancel_needed)
+
+ if self.refund_method == 'modify':
+ moves_vals_list = []
+ for move in moves.with_context(include_business_fields=True):
+ moves_vals_list.append(move.copy_data({'date': self.date if self.date_mode == 'custom' else move.date})[0])
+ new_moves = self.env['account.move'].create(moves_vals_list)
+
+ moves_to_redirect |= new_moves
- self.new_move_ids = new_moves
- if new_moves:
- self._reverse_moves_post_hook(new_moves)
+ self.new_move_ids = moves_to_redirect
# Create action.
action = {
@@ -112,14 +116,14 @@ class AccountMoveReversal(models.TransientModel):
'type': 'ir.actions.act_window',
'res_model': 'account.move',
}
- if len(new_moves) == 1:
+ if len(moves_to_redirect) == 1:
action.update({
'view_mode': 'form',
- 'res_id': new_moves.id,
+ 'res_id': moves_to_redirect.id,
})
else:
action.update({
'view_mode': 'tree,form',
- 'domain': [('id', 'in', new_moves.ids)],
+ 'domain': [('id', 'in', moves_to_redirect.ids)],
})
return action