1
# -*- encoding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
8
# This program is free software: you can redistribute it and/or modify
9
# it under the terms of the GNU General Public License as published by
10
# the Free Software Foundation, either version 3 of the License, or
11
# (at your option) any later version.
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU General Public License for more details.
18
# You should have received a copy of the GNU General Public License
19
# along with this program. If not, see <http://www.gnu.org/licenses/>.
21
##############################################################################
25
from report import report_sxw
27
class account_analytic_analytic_check(report_sxw.rml_parse):
28
def __init__(self, cr, uid, name, context):
29
super(account_analytic_analytic_check, self).__init__(cr, uid, name, context)
30
self.sum_gen_deb = 0.0
31
self.sum_gen_cred = 0.0
32
self.sum_ana_deb = 0.0
33
self.sum_ana_cred = 0.0
34
self.localcontext.update( {
36
'lines_p': self._lines_p,
37
'general_debit': self._gen_deb,
38
'general_credit': self._gen_cred,
39
'analytic_debit': self._ana_deb,
40
'analytic_credit': self._ana_cred,
41
'delta_debit': self._delta_deb,
42
'delta_credit': self._delta_cred,
44
def _lines_p(self, date1, date2):
46
acc_obj = self.pool.get('account.account')
47
# print"3333333acc_obj3333333",acc_obj.read(self.cr, self.uid, self.ids, ['name', 'code','user_type'])
49
for a in acc_obj.read(self.cr, self.uid, self.ids, ['name', 'code']):
50
self.cr.execute("SELECT sum(debit), sum(credit) \
51
FROM account_move_line \
52
WHERE date>=%s AND date<=%s AND state<>'draft' AND account_id = %s", (date1, date2, a['id']))
53
(gd, gc) = self.cr.fetchone()
57
self.cr.execute("SELECT abs(sum(amount)) AS balance \
58
FROM account_analytic_line \
59
WHERE date>=%s AND date<=%s AND amount>0 AND general_account_id = %s", (date1, date2, a['id']))
60
(ad,) = self.cr.fetchone()
62
self.cr.execute("SELECT abs(sum(amount)) AS balance \
63
FROM account_analytic_line \
64
WHERE date>=%s AND date<=%s AND amount<0 AND general_account_id = %s", (date1, date2, a['id']))
65
(ac,) = self.cr.fetchone()
68
res.append({'code': a['code'], 'name': a['name'],
73
'delta_debit': gd - ad,
74
'delta_credit': gc - ac,})
75
self.sum_gen_deb += gd
76
self.sum_gen_cred += gc
77
self.sum_ana_deb += ad
78
self.sum_ana_cred += ac
82
# def _lines_p(self, date1, date2):
84
# acc_obj = self.pool.get('account.account')
85
# for a in acc_obj.read(self.cr, self.uid, self.ids, ['name', 'code','sign']):
86
# self.cr.execute("SELECT sum(debit), sum(credit) \
87
# FROM account_move_line \
88
# WHERE date>=%s AND date<=%s AND state<>'draft' AND account_id = %s", (date1, date2, a['id']))
89
# (gd, gc) = self.cr.fetchone()
93
# self.cr.execute("SELECT abs(sum(amount)) AS balance \
94
# FROM account_analytic_line \
95
# WHERE date>=%s AND date<=%s AND amount*%s>0 AND general_account_id = %s", (date1, date2, a['sign'], a['id']))
96
# (ad,) = self.cr.fetchone()
98
# self.cr.execute("SELECT abs(sum(amount)) AS balance \
99
# FROM account_analytic_line \
100
# WHERE date>=%s AND date<=%s AND amount*%s<0 AND general_account_id = %s", (date1, date2, a['sign'], a['id']))
101
# (ac,) = self.cr.fetchone()
104
# res.append({'code': a['code'], 'name': a['name'],
109
# 'delta_debit': gd - ad,
110
# 'delta_credit': gc - ac,})
111
# self.sum_gen_deb += gd
112
# self.sum_gen_cred += gc
113
# self.sum_ana_deb += ad
114
# self.sum_ana_cred += ac
117
def _gen_deb(self, date1, date2):
118
return self.sum_gen_deb
120
def _gen_cred(self, date1, date2):
121
return self.sum_gen_cred
123
def _ana_deb(self, date1, date2):
124
return self.sum_ana_deb
126
def _ana_cred(self, date1, date2):
127
return self.sum_ana_cred
129
def _delta_deb(self, date1, date2):
130
return (self._gen_deb(date1,date2)-self._ana_deb(date1,date2))
132
def _delta_cred(self, date1, date2):
133
return (self._gen_cred(date1,date2)-self._ana_cred(date1,date2))
135
report_sxw.report_sxw('report.account.analytic.account.analytic.check', 'account.analytic.account', 'addons/account/project/report/analytic_check.rml',parser=account_analytic_analytic_check, header=False)
138
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: