bank_statement_reconciliation/models/account_bank_statement_line.py
2025-10-27 08:53:48 +07:00

43 lines
1.8 KiB
Python

from odoo import models, fields, api
from odoo.exceptions import UserError
class AccountBankStatementLine(models.Model):
_inherit = 'account.bank.statement.line'
is_reconciled = fields.Boolean(string='Is Reconciled', compute='_compute_is_reconciled', store=True)
@api.depends('move_id')
def _compute_is_reconciled(self):
"""Compute whether the bank line has been reconciled"""
for line in self:
line.is_reconciled = bool(line.move_id and 'Reconciliation:' in line.move_id.name)
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 and 'Reconciliation:' in line.move_id.name))
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,
}
}