1+ # Copyright 2018 Lorenzo Battistini - Agile Business Group
2+ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
4+ from odoo import models
5+ from odoo .osv import expression
6+
7+
8+ class AccountBankStatementLine (models .Model ):
9+ _inherit = 'account.bank.statement.line'
10+
11+ def get_move_lines_for_reconciliation (
12+ self , excluded_ids = None , str = False , offset = 0 , limit = None ,
13+ additional_domain = None , overlook_partner = False
14+ ):
15+ res = super (
16+ AccountBankStatementLine , self
17+ ).get_move_lines_for_reconciliation (
18+ excluded_ids = excluded_ids , str = str , offset = offset , limit = limit ,
19+ additional_domain = additional_domain ,
20+ overlook_partner = overlook_partner
21+ )
22+
23+ reconciliation_aml_accounts = [
24+ self .journal_id .default_credit_account_id .id ,
25+ self .journal_id .default_debit_account_id .id
26+ ]
27+ ctx = dict (self ._context or {})
28+ ctx ['bank_statement_line' ] = self
29+ generic_domain = self .env ['account.move.line' ].with_context (
30+ ctx
31+ ).domain_move_lines_for_reconciliation (
32+ excluded_ids = excluded_ids , str = str )
33+
34+ # Include move lines without payment_id but linked to a RiBa distinta
35+ # in order to allow to close bank statement lines with accreditation
36+ # journal items
37+ accr_domain = [
38+ '&' ,
39+ '&' ,
40+ '&' ,
41+ ('move_id.riba_accredited_ids' , '!=' , False ),
42+ ('payment_id' , '=' , False ),
43+ ('statement_id' , '=' , False ),
44+ ('account_id' , 'in' , reconciliation_aml_accounts ),
45+ ]
46+ accr_domain = expression .AND ([accr_domain , generic_domain ])
47+ accr_res = self .env ['account.move.line' ].search (
48+ accr_domain , offset = offset , limit = limit ,
49+ order = "date_maturity asc, id asc" )
50+
51+ # Include move lines without payment_id but linked to a RiBa distinta
52+ # in order to allow to close bank statement lines with unsolved
53+ # journal items
54+ unsolved_domain = [
55+ '&' ,
56+ '&' ,
57+ '&' ,
58+ ('move_id.riba_unsolved_ids' , '!=' , False ),
59+ ('payment_id' , '=' , False ),
60+ ('statement_id' , '=' , False ),
61+ ('account_id' , 'in' , reconciliation_aml_accounts ),
62+ ]
63+ unsolved_domain = expression .AND ([unsolved_domain , generic_domain ])
64+ unsolved_res = self .env ['account.move.line' ].search (
65+ unsolved_domain , offset = offset , limit = limit ,
66+ order = "date_maturity asc, id asc" )
67+
68+ res = accr_res | unsolved_res | res
69+ return res
0 commit comments