bank_statement_reconciliation/models/bank_statement_line.py

53 lines
2.1 KiB
Python

from odoo import models, fields, api
from odoo.exceptions import UserError
class BankStatementLine(models.Model):
_name = 'bank.statement.line'
_description = 'Bank Statement Line Selection'
@api.model
def default_get(self, fields):
res = super().default_get(fields)
active_model = self.env.context.get('active_model')
active_ids = self.env.context.get('active_ids')
if active_model == 'account.bank.statement.line' and active_ids:
statement_lines = self.env['account.bank.statement.line'].browse(active_ids)
res['line_ids'] = [(6, 0, statement_lines.ids)]
return res
journal_id = fields.Many2one('account.journal', string='Bank Journal',
domain=[('type', '=', 'bank')])
line_ids = fields.Many2many('account.bank.statement.line', string='Bank Statement Lines')
selected_line_ids = fields.Many2many('account.bank.statement.line',
'bank_statement_line_rel',
'wizard_id', 'line_id',
string='Selected Bank Lines')
@api.onchange('journal_id')
def _onchange_journal_id(self):
if self.journal_id:
statement_lines = self.env['account.bank.statement.line'].search([
('journal_id', '=', self.journal_id.id)
])
self.line_ids = statement_lines
else:
self.line_ids = False
def action_open_reconcile_wizard(self):
"""Open the reconciliation wizard"""
if not self.selected_line_ids:
raise UserError("Please select at least one bank statement line to reconcile.")
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': self.selected_line_ids.ids,
}
}