Skip to content

Commit

Permalink
[RFC] account_consolidation_oca: method reverse_move
Browse files Browse the repository at this point in the history
  • Loading branch information
kaynnan committed Nov 29, 2023
1 parent 8d55de3 commit 8d72945
Showing 1 changed file with 16 additions and 39 deletions.
55 changes: 16 additions & 39 deletions account_consolidation_oca/wizard/consolidation_consolidate.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,6 @@ def _prepare_rate_difference_line(self, move_lines_list):
}

def reverse_moves(self, subsidiary):
"""
Reverse all consolidation account moves of a subsidiary which have
the "Auto reversed" flag, and wasn't reversed before this date
:param subsidiary: Recordset of the subsidiary
:return: tuple with : Recordset of the reversed moves,
Recordset of the reversal moves
"""
move_obj = self.env["account.move"]
moves_to_reverse = move_obj.search(
[
Expand All @@ -161,32 +152,18 @@ def reverse_moves(self, subsidiary):
)
if not moves_to_reverse:
return moves_to_reverse, False
try:
reversal_action = (
self.env["account.move.reversal"]
.with_context(
active_ids=moves_to_reverse.ids, __conso_reversal_no_post=True
)
.create(
{
"date": self._get_month_first_date(),
"journal_id": self.journal_id.id,
}
)
.reverse_moves()
)
except ValidationError as e:
raise ValidationError(
_(
"The error below appeared while trying to reverse the "
"following moves: \n %s \n %s"
)
% ("\n".join(["- %s" % m.name for m in moves_to_reverse]), e.name)
)

reversal_move = move_obj.browse(reversal_action.get("domain")[0][2])
reversed_moves = self.env["account.move"]
for move in moves_to_reverse:
# Reverse the move
reversal_move = move._reverse_moves()
reversed_moves |= reversal_move
# Update the reversed_entry_id field on the original move
move.write({"reversed_entry_id": reversal_move.id})
# Update the ref field on the reversed move
reversal_move.write({"ref": _("Reverse of %s") % move.name})

return moves_to_reverse, reversal_move
return moves_to_reverse, reversed_moves

def get_account_balance(self, account, partner=False):
"""
Expand Down Expand Up @@ -399,10 +376,10 @@ def consolidate_subsidiary(self, profile):

# Now that all move lines are processed we reset the flag of processed
# accounts
consolidated_move_lines = self.env["account.move.line"].search(
[("consolidated", "=", True)]
self.env.cr.execute(
"UPDATE account_move_line SET consolidated = False "
"WHERE consolidated = True;"
)
consolidated_move_lines.write({"consolidated": False})

if move_lines_to_generate:

Expand Down Expand Up @@ -442,10 +419,10 @@ def run_consolidation(self):

created_moves = self.env["account.move"]

consolidated_move_lines = self.env["account.move.line"].search(
[("consolidated", "=", True)]
self.env.cr.execute(
"UPDATE account_move_line SET consolidated = False "
"WHERE consolidated = True;"
)
consolidated_move_lines.write({"consolidated": False})

for profile in self.consolidation_profile_ids:
created_moves |= self.consolidate_subsidiary(profile)
Expand Down

0 comments on commit 8d72945

Please sign in to comment.