~sharoonthomas/openerpretail/core

« back to all changes in this revision

Viewing changes to bin/addons/account/project/report/analytic_check.py

  • Committer: Sharoon Thomas
  • Date: 2009-07-20 06:25:34 UTC
  • Revision ID: sharoonthomas@teagarden.in-20090720062534-j8jq2nmdy63w9o9c
Initial Release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    OpenERP, Open Source Management Solution   
 
5
#    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
 
6
#    $Id$
 
7
#
 
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.
 
12
#
 
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.
 
17
#
 
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/>.
 
20
#
 
21
##############################################################################
 
22
 
 
23
import pooler
 
24
import time
 
25
from report import report_sxw
 
26
 
 
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( {
 
35
            'time': time,
 
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,
 
43
        })
 
44
    def _lines_p(self, date1, date2):
 
45
        res = []
 
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'])
 
48
 
 
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()
 
54
            gd = gd or 0.0
 
55
            gc = gc or 0.0
 
56
 
 
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()
 
61
            ad = ad or 0.0
 
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()
 
66
            ac = ac or 0.0
 
67
 
 
68
            res.append({'code': a['code'], 'name': a['name'],
 
69
                'gen_debit': gd,
 
70
                'gen_credit': gc,
 
71
                'ana_debit': ad,
 
72
                'ana_credit': ac,
 
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
 
79
 
 
80
        return res
 
81
 
 
82
#    def _lines_p(self, date1, date2):
 
83
#        res = []
 
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()
 
90
#            gd = gd or 0.0
 
91
#            gc = gc or 0.0
 
92
#
 
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()
 
97
#            ad = ad or 0.0
 
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()
 
102
#            ac = ac or 0.0
 
103
#
 
104
#            res.append({'code': a['code'], 'name': a['name'],
 
105
#                'gen_debit': gd,
 
106
#                'gen_credit': gc,
 
107
#                'ana_debit': ad,
 
108
#                'ana_credit': ac,
 
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
 
115
#        return res
 
116
 
 
117
    def _gen_deb(self, date1, date2):
 
118
        return self.sum_gen_deb
 
119
 
 
120
    def _gen_cred(self, date1, date2):
 
121
        return self.sum_gen_cred
 
122
 
 
123
    def _ana_deb(self, date1, date2):
 
124
        return self.sum_ana_deb
 
125
 
 
126
    def _ana_cred(self, date1, date2):
 
127
        return self.sum_ana_cred
 
128
 
 
129
    def _delta_deb(self, date1, date2):
 
130
        return (self._gen_deb(date1,date2)-self._ana_deb(date1,date2))
 
131
 
 
132
    def _delta_cred(self, date1, date2):
 
133
        return (self._gen_cred(date1,date2)-self._ana_cred(date1,date2))
 
134
 
 
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)
 
136
 
 
137
 
 
138
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: