This repository has been archived by the owner on Dec 21, 2021. It is now read-only.
forked from OCA/account-financial-reporting
-
Notifications
You must be signed in to change notification settings - Fork 0
/
account_move_line.py
77 lines (70 loc) · 3.23 KB
/
account_move_line.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# -*- encoding: utf-8 -*-
##############################################################################
#
# Author: Nicolas Bessi.
# Copyright Camptocamp SA 2011
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.osv import fields, orm
class AccountMoveLine(orm.Model):
"""Overriding Account move line in order to add last_rec_date.
Last rec date is the date of the last reconciliation (full or partial)
account move line"""
_inherit = 'account.move.line'
def _get_move_line_from_line_rec(self, cr, uid, ids, context=None):
moves = []
for reconcile in self.pool['account.move.reconcile'].browse(
cr, uid, ids, context=context):
for move_line in reconcile.line_partial_ids:
moves.append(move_line.id)
for move_line in reconcile.line_id:
moves.append(move_line.id)
return list(set(moves))
def _get_last_rec_date(self, cursor, uid, ids, name, args, context=None):
if not isinstance(ids, list):
ids = [ids]
res = {}
for line in self.browse(cursor, uid, ids, context):
res[line.id] = {'last_rec_date': False}
rec = line.reconcile_id or line.reconcile_partial_id or False
if rec:
# we use cursor in order to gain some perfs.
# also, important point: LIMIT 1 is not used due to
# performance issues when in conjonction with "OR"
# (one backwards index scan instead of 2 scans and a sort)
cursor.execute('SELECT date from account_move_line'
' WHERE reconcile_id = %s'
' OR reconcile_partial_id = %s'
' ORDER BY date DESC',
(rec.id, rec.id))
res_set = cursor.fetchone()
if res_set:
res[line.id] = {'last_rec_date': res_set[0]}
return res
_columns = {
'last_rec_date': fields.function(
_get_last_rec_date,
method=True,
string='Last reconciliation date',
store={'account.move.line': (lambda self, cr, uid, ids, c={}: ids,
['date'], 20),
'account.move.reconcile': (_get_move_line_from_line_rec,
None, 20)},
type='date',
multi='all',
help="the date of the last reconciliation (full or partial) \
account move line"),
}