Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion account_payment_pro/models/account_payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,13 @@ def _inverse_to_pay_amount(self):
):
rec.unreconciled_amount = rec.to_pay_amount - rec.selected_debt

@api.onchange("to_pay_move_line_ids")
def _onchange_to_pay_move_line_ids(self):
"""Evitar que se recompute automáticamente cuando el usuario edita manualmente
el campo many2many desde la UI"""
for rec in self.filtered(lambda x: x.partner_id and x.state == "draft"):
rec.to_pay_move_line_ids = rec.to_pay_move_line_ids.filtered("partner_id")

# We dont set 'is_internal_transfer' as a dependencies as it could leed to recompute to_pay_move_line_ids
@api.depends("partner_id", "partner_type", "company_id")
def _compute_to_pay_move_lines(self):
Expand Down Expand Up @@ -598,6 +605,7 @@ def _get_filter_payments(self, records, extra_fields):

def _get_to_pay_move_lines_domain(self):
self.ensure_one()

domain = [
("partner_id", "=", self.partner_id.commercial_partner_id.id),
("company_id", "=", self.company_id.id),
Expand All @@ -611,7 +619,7 @@ def _get_to_pay_move_lines_domain(self):
"asset_receivable" if self.partner_type == "customer" else "liability_payable",
),
]
# TODO revisar bien estos, no debería ser necesario, ver el blame porque se agrego lo del active_ids
# Solo agregar active_ids si estamos en contexto de seleccionar líneas específicas
if self.env.context.get("active_ids") and self.env.context.get("active_model") == "account.move.line":
domain.append(("move_id.line_ids", "in", self.env.context.get("active_ids")))
return domain
Expand All @@ -628,6 +636,7 @@ def action_add_all(self):

def remove_all(self):
self.to_pay_move_line_ids = False
self.to_pay_amount = 0.0
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

En remove_all() se escribe directamente to_pay_amount, que es un campo compute con inverse. Esto puede dejar unreconciled_amount sin resetear si currency_id todavía no está seteada (el inverse hace un guard con if rec.currency_id), o introducir ajustes negativos no deseados. Sería más seguro/resetear explícitamente unreconciled_amount (y dejar que _compute_to_pay_amount derive to_pay_amount) en lugar de escribir el campo compute.

Suggested change
self.to_pay_amount = 0.0
self.unreconciled_amount = 0.0

Copilot uses AI. Check for mistakes.

@api.constrains("partner_id", "to_pay_move_line_ids")
def check_to_pay_lines(self):
Expand Down
Loading