1
# -*- encoding: utf-8 -*-
2
##############################################################################
4
# Author: Nicolas Bessi.
5
# Copyright Camptocamp SA 2011
7
# This program is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation, either version 3 of the License, or
10
# (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20
##############################################################################
22
from osv import fields, osv
23
from tools.translate import _
26
class AccountMoveLine(osv.osv):
27
"""Overriding Account move line in order to add last_rec_date.
28
Last rec date is the date of the last reconciliation (full or partial) account move line"""
29
_inherit = 'account.move.line'
32
##We do not want to catch error as if sql is not run it will give invalid data
33
cr.execute("UPDATE account_move_line as acm "
34
" SET last_rec_date ="
35
" (SELECT date from account_move_line"
36
" WHERE reconcile_id = acm.reconcile_id"
37
" AND reconcile_id IS NOT NULL"
38
" ORDER BY date DESC LIMIT 1)"
39
" WHERE last_rec_date is null;")
41
cr.execute("UPDATE account_move_line as acm "
42
" SET last_rec_date ="
43
" (SELECT date from account_move_line"
44
" WHERE reconcile_partial_id = acm.reconcile_partial_id"
45
" AND reconcile_partial_id IS NOT NULL"
46
" ORDER BY date DESC LIMIT 1)"
47
" WHERE last_rec_date is null;")
50
def _get_move_line_from_line_rec(self, cr, uid, ids, context=None):
52
for reconcile in self.pool.get('account.move.reconcile').browse(cr, uid, ids, context=context):
53
for move_line in reconcile.line_partial_ids:
54
moves.append(move_line.id)
55
for move_line in reconcile.line_id:
56
moves.append(move_line.id)
57
return list(set(moves))
59
def _get_last_rec_date(self, cursor, uid, ids, name, args, context=None):
60
if not isinstance(ids, list):
63
for line in self.browse(cursor, uid, ids, context):
64
res[line.id] = {'last_rec_date': False}
65
rec = line.reconcile_id or line.reconcile_partial_id or False
67
# we use cursor in order to gain some perfs
68
cursor.execute('SELECT date from account_move_line where'
69
' reconcile_id = %s OR reconcile_partial_id = %s'
70
' ORDER BY date DESC LIMIT 1 ',
72
res_set = cursor.fetchone()
74
res[line.id] = {'last_rec_date': res_set[0]}
78
'last_rec_date': fields.function(_get_last_rec_date,
80
string='Last reconciliation date',
81
store={'account.move.line': (lambda self, cr, uid, ids, c={}: ids, ['date'], 20),
82
'account.move.reconcile': (_get_move_line_from_line_rec, None ,20)},
85
help="the date of the last reconciliation (full or partial) account move line"),