Skip to content

Commit

Permalink
[FIX] account_reconcile_oca: Synchronize manual_partner_id with partn…
Browse files Browse the repository at this point in the history
…er_id without onchange or subsequent changes with the _synchronize_to_moves() method.

We do not define partner_id with the value of manual_partner_id to prevent _synchronize_to_moves()
from making changes to the account.move.line leaving unintended values and/or data.

Related to OCA#779

TT52634
  • Loading branch information
victoralmau committed Jan 21, 2025
1 parent 909977c commit 998286e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
35 changes: 28 additions & 7 deletions account_reconcile_oca/models/account_bank_statement_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,6 @@ def _onchange_manual_reconcile_vals(self):
line["kind"] if line["kind"] != "suspense" else "other"
)
line.update(line_vals)
if line["kind"] == "liquidity":
self._update_move_partner()
if self.manual_line_id and self.manual_line_id.id == line.get(
"original_exchange_line_id"
):
Expand All @@ -501,11 +499,6 @@ def _onchange_manual_reconcile_vals(self):
)
self.can_reconcile = self.reconcile_data_info.get("can_reconcile", False)

def _update_move_partner(self):
if self.partner_id == self.manual_partner_id:
return
self.partner_id = self.manual_partner_id

@api.depends("reconcile_data", "is_reconciled")
def _compute_reconcile_data_info(self):
for record in self:
Expand Down Expand Up @@ -943,6 +936,34 @@ def create(self, mvals):
)(self._prepare_reconcile_line_data(data["data"]))
return result

def _synchronize_to_moves(self, changed_fields):
"""Similar process to what _synchronize_to_moves() method would do but without
the relative to all the changed_fields, we just need to update partner_id.
We precisely do not do an onchange of self.partner_id = self.manual_partner_id
to avoid making all those unnecessary changes, but we need to apply this
change to the account.move and the lines without side effects.
A change of manual_partner_id that has been reconciled should NOT change the
values of the account.move lines.
"""
super()._synchronize_to_moves(changed_fields=changed_fields)
if self._context.get("skip_account_move_synchronization"):
return

if not any(f_name in changed_fields for f_name in ("manual_partner_id",)):
return

for st_line in self.with_context(skip_account_move_synchronization=True):
liquidity_lines, suspense_lines, _other_lines = st_line._seek_for_lines()
line_vals = {"partner_id": st_line.manual_partner_id.id}
line_ids_commands = [(1, liquidity_lines.id, line_vals)]
if suspense_lines:
line_ids_commands.append((1, suspense_lines.id, line_vals))
st_line_vals = {"line_ids": line_ids_commands}
if st_line.move_id.partner_id != st_line.manual_partner_id:
st_line_vals["partner_id"] = st_line.manual_partner_id.id
st_line.move_id.write(st_line_vals)
st_line.write({"partner_id": st_line.manual_partner_id.id})

def _prepare_reconcile_line_data(self, lines):
new_lines = []
reverse_lines = {}
Expand Down
1 change: 1 addition & 0 deletions account_reconcile_oca/tests/test_bank_account_reconcile.py
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,7 @@ def test_widget_invoice_change_partner(self):
self.assertFalse(f.partner_id)
f.manual_reference = "account.move.line;%s" % liquidity_lines.id
f.manual_partner_id = inv1.partner_id
f.save()
self.assertEqual(f.partner_id, inv1.partner_id)
bank_stmt_line.clean_reconcile()
# As we have a set a partner, the cleaning should assign the invoice automatically
Expand Down

0 comments on commit 998286e

Please sign in to comment.