bank_statement_reconciliation/models/account_bank_statement_line.py
2025-10-27 13:41:17 +07:00

35 lines
1.4 KiB
Python

from odoo import models, fields, api
from odoo.exceptions import UserError
class AccountBankStatementLine(models.Model):
_inherit = 'account.bank.statement.line'
def action_reconcile_selected_lines(self):
"""Open the reconciliation wizard for selected lines"""
# Get the selected records from the context
active_ids = self.env.context.get('active_ids')
active_model = self.env.context.get('active_model')
if active_model == 'account.bank.statement.line' and active_ids:
selected_lines = self.browse(active_ids)
else:
# If called from a single record, use self
selected_lines = self
# Filter out already reconciled lines by checking if they have a move_id with reconciliation in the name
unreconciled_lines = selected_lines.filtered(lambda line: not line.move_id)
if not unreconciled_lines:
raise UserError("All selected bank statement lines have already been reconciled.")
return {
'name': 'Select Journal Entry to Reconcile',
'type': 'ir.actions.act_window',
'res_model': 'bank.reconcile.wizard',
'view_mode': 'form',
'target': 'new',
'context': {
'default_bank_line_ids': unreconciled_lines.ids,
}
}