1
##############################################################################
3
# Copyright (c) 2004 TINY SPRL. (http://tiny.be) All Rights Reserved.
4
# Fabien Pinckaers <fp@tiny.Be>
6
# WARNING: This program as such is intended to be used by professional
7
# programmers who take the whole responsability of assessing all potential
8
# consequences resulting FROM its eventual inadequacies AND bugs
9
# End users who are looking for a ready-to-use solution with commercial
10
# garantees AND support are strongly adviced to contract a Free Software
13
# This program is Free Software; you can redistribute it AND/or
14
# modify it under the terms of the GNU General Public License
15
# as published by the Free Software Foundation; either version 2
16
# of the License, or (at your option) any later version.
18
# This program is distributed in the hope that it will be useful,
19
# but WITHOUT ANY WARRANTY; without even the implied warranty of
20
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
# GNU General Public License for more details.
23
# You should have received a copy of the GNU General Public License
24
# along with this program; if not, write to the Free Software
25
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27
##############################################################################
31
from report import report_sxw
33
class account_analytic_year_to_date_check(report_sxw.rml_parse):
34
def __init__(self, cr, uid, name, context):
35
super(account_analytic_year_to_date_check, self).__init__(cr, uid, name, context)
36
self.localcontext.update( {
38
'start_date': self._get_start_date,
39
'end_date': self._get_end_date,
40
'lines_p': self._lines_p,
41
'general_debit': self._gen_deb,
42
'general_credit': self._gen_cred,
43
'analytic_debit': self._ana_deb,
44
'analytic_credit': self._ana_cred,
45
'delta_debit': self._delta_deb,
46
'delta_credit': self._delta_cred,
49
def _get_periods(self, date1, date2):
50
self.cr.execute("SELECT name, date_start, date_stop FROM account_period WHERE (date_start>=%s) AND (date_stop<=%s) ORDER BY date_start, date_stop", (date1, date2))
51
return self.cr.dictfetchall()
53
def _get_start_date(self, date1, date2):
54
periods = self._get_periods(date1, date2)
55
return periods[0]['date_start']
57
def _get_end_date(self, date1, date2):
58
periods = self._get_periods(date1, date2)
59
return periods[-1]['date_stop']
61
def _lines_p(self, date1, date2):
62
periods = self._get_periods(date1, date2)
64
self.cr.execute("SELECT sum(debit),sum(credit) FROM account_move_line WHERE (date>=%s) AND (date<=%s) AND state<>'draft'", (r['date_start'], r['date_stop']))
65
(gd, gc) = self.cr.fetchone()
68
self.cr.execute("SELECT sum(amount) AS balance FROM account_analytic_line WHERE (date>=%s) AND (date<=%s) AND (amount>0)", (r['date_start'], r['date_stop']))
69
(ad,) = self.cr.fetchone()
72
self.cr.execute("SELECT sum(amount) AS balance FROM account_analytic_line WHERE (date>=%s) AND (date<=%s) AND (amount<0)", (r['date_start'], r['date_stop']))
73
(ac,) = self.cr.fetchone()
76
r['gen_debit'] = '%.2f' % gd
77
r['gen_credit'] = '%.2f' % gc
78
r['ana_debit'] = '%.2f' % ad
79
r['ana_credit'] = '%.2f' % ac
80
r['delta_debit'] = '%.2f' % (gd - ad) or ''
81
r['delta_credit'] = '%.2f' % (gc - ac) or ''
85
def _gen_deb(self, date1, date2):
86
start = self._get_start_date(date1, date2)
87
stop = self._get_end_date(date1, date2)
88
self.cr.execute("SELECT sum(debit) FROM account_move_line WHERE date>=%s AND date<=%s AND state<>'draft'", (start, stop))
89
return self.cr.fetchone()[0] or 0.0
91
def _gen_cred(self, date1, date2):
92
start = self._get_start_date(date1, date2)
93
stop = self._get_end_date(date1, date2)
94
self.cr.execute("SELECT sum(credit) FROM account_move_line WHERE date>=%s AND date<=%s AND state<>'draft'", (start, stop))
95
return self.cr.fetchone()[0] or 0.0
97
def _ana_deb(self, date1, date2):
98
start = self._get_start_date(date1, date2)
99
stop = self._get_end_date(date1, date2)
100
self.cr.execute("SELECT sum(amount) FROM account_analytic_line WHERE date>=%s AND date<=%s AND amount>0", (start, stop))
101
return self.cr.fetchone()[0] or 0.0
103
def _ana_cred(self, date1, date2):
104
start = self._get_start_date(date1, date2)
105
stop = self._get_end_date(date1, date2)
106
self.cr.execute("SELECT sum(amount) FROM account_analytic_line WHERE date>=%s AND date<=%s AND amount<0", (start, stop))
107
res = self.cr.fetchone()[0] or 0.0
110
def _delta_deb(self, date1, date2):
111
return (self._gen_deb(date1,date2)-self._ana_deb(date1,date2))
113
def _delta_cred(self, date1, date2):
114
return (self._gen_cred(date1,date2)-self._ana_cred(date1,date2))
116
report_sxw.report_sxw('report.account.analytic.account.year_to_date_check', 'account.analytic.account', 'addons/account/project/report/year_to_date_check.rml',parser=account_analytic_year_to_date_check)