1
##############################################################################
3
# Copyright (c) 2005-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
5
# WARNING: This program as such is intended to be used by professional
6
# programmers who take the whole responsability of assessing all potential
7
# consequences resulting from its eventual inadequacies and bugs
8
# End users who are looking for a ready-to-use solution with commercial
9
# garantees and support are strongly adviced to contract a Free Software
12
# This program is Free Software; you can redistribute it and/or
13
# modify it under the terms of the GNU General Public License
14
# as published by the Free Software Foundation; either version 2
15
# of the License, or (at your option) any later version.
17
# This program is distributed in the hope that it will be useful,
18
# but WITHOUT ANY WARRANTY; without even the implied warranty of
19
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
# GNU General Public License for more details.
22
# You should have received a copy of the GNU General Public License
23
# along with this program; if not, write to the Free Software
24
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
##############################################################################
29
from report import report_sxw
31
class consumo_suc(report_sxw.rml_parse):
32
def __init__(self, cr, uid, name, context):
33
super(consumo_suc, self).__init__(cr, uid, name, context)
34
self.localcontext.update( {
37
'sum_debit_account': self._sum_debit_account,
38
'sum_credit_account': self._sum_credit_account,
39
'sum_debit': self._sum_debit,
40
'sum_credit': self._sum_credit,
41
'category': self._category,
42
'periods': self._periods,
44
self.context = context
46
def _get_child(self, parent):
47
obj = self.pool.get('product.category')
49
categ_id = obj.search(self.cr, self.uid, [])
51
if parent == obj.browse(self.cr, self.uid, c).parent_id.id:
55
def _category(self,form):
56
print "category form = ",form
57
if not form['category']:
59
print "raul categ name = ",categ_name
61
obj = self.pool.get('product.category')
62
categ_name = obj.browse(self.cr, self.uid, form['category']).name
63
print "raul categ_name ",categ_name
64
categ_in = form['category']
65
print "raul categ name = ",categ_name
68
def _periods(self,form):
69
if not form['periods'][0][2]:
72
obj = self.pool.get('account.period')
73
periods = form['periods'][0][2]
75
for period in periods:
76
print "period = ",obj.browse(self.cr, self.uid, period).code
77
todo += obj.browse(self.cr, self.uid, period).code + ", "
82
def raul_category(self,form):
83
print "category form = ",form
84
# if not form['category']:
85
# categ_name = "Todas"
87
obj = self.pool.get('product.category')
88
categ_name = obj.browse(self.cr, self.uid, form['category']).name
89
print "raul categ_name ",categ_name
90
categ_in = form['category']
93
print "raul categ name = ",categ_name
96
def lines(self, account, form):
97
ctx = self.context.copy()
98
ctx['fiscalyear'] = form['fiscalyear']
99
ctx['periods'] = form['periods'][0][2]
100
query = self.pool.get('account.move.line')._query_get(self.cr, self.uid, context=ctx)
102
categ_in = form['category']
103
childs = self._get_child(categ_in)
105
parent = self._get_child(i)
109
print 'childs=',childs
110
categ_in = form['category']
111
self.cr.execute("SELECT l.date, j.code, l.ref, l.name, l.debit, l.credit, l.quantity "\
112
"FROM account_move_line l, account_journal j "\
113
"WHERE l.name in (SELECT name from product_template q WHERE q.categ_id in (SELECT a.id from product_category a where a.parent_id = %d) ) AND l.journal_id = j.id "\
114
"AND account_id = %d AND "+query+" "\
115
"ORDER by l.id", (categ_in,account.id,))
117
self.cr.execute("SELECT l.date, j.code, l.ref, l.name, l.debit, l.credit, l.quantity "\
118
"FROM account_move_line l, account_journal j "\
119
"WHERE l.journal_id = j.id "\
120
"AND account_id = %d AND "+query+" "\
121
"ORDER by l.id", (account.id,))
123
res = self.cr.dictfetchall()
126
sum += (l['debit'] or 0.0) - (l['credit'] or 0.0)
130
def _sum_debit_account(self, account, form):
131
ctx = self.context.copy()
132
ctx['fiscalyear'] = form['fiscalyear']
133
ctx['periods'] = form['periods'][0][2]
134
query = self.pool.get('account.move.line')._query_get(self.cr, self.uid, context=ctx)
135
categ_in = form['category']
136
# self.cr.execute("SELECT sum(debit) "\
137
# "FROM account_move_line l "\
138
# "WHERE l.account_id = %d AND "+query, (account.id,))
139
self.cr.execute("SELECT sum(l.debit) "\
140
"FROM account_move_line l, account_journal j "\
141
"WHERE l.name in (SELECT name from product_template q WHERE q.categ_id in (SELECT a.id from product_category a where a.parent_id = %d) ) AND l.journal_id = j.id "\
142
"AND account_id = %d AND "+query, (categ_in,account.id,))
144
self.cr.execute("SELECT sum(debit) "\
145
"FROM account_move_line l "\
146
"WHERE l.account_id = %d AND "+query, (account.id,))
147
return self.cr.fetchone()[0] or 0.0
149
def _sum_credit_account(self, account, form):
150
ctx = self.context.copy()
151
ctx['fiscalyear'] = form['fiscalyear']
152
ctx['periods'] = form['periods'][0][2]
153
query = self.pool.get('account.move.line')._query_get(self.cr, self.uid, context=ctx)
154
categ_in = form['category']
155
self.cr.execute("SELECT sum(l.credit) "\
156
"FROM account_move_line l, account_journal j "\
157
"WHERE l.name in (SELECT name from product_template q WHERE q.categ_id in (SELECT a.id from product_category a where a.parent_id = %d) ) AND l.journal_id = j.id "\
158
"AND account_id = %d AND "+query, (categ_in,account.id,))
160
self.cr.execute("SELECT sum(credit) "\
161
"FROM account_move_line l "\
162
"WHERE l.account_id = %d AND "+query, (account.id,))
163
return self.cr.fetchone()[0] or 0.0
165
def _sum_debit(self, form):
168
ctx = self.context.copy()
169
ctx['fiscalyear'] = form['fiscalyear']
170
ctx['periods'] = form['periods'][0][2]
171
query = self.pool.get('account.move.line')._query_get(self.cr, self.uid, context=ctx)
172
self.cr.execute("SELECT sum(debit) "\
173
"FROM account_move_line l "\
174
"WHERE l.account_id in ("+','.join(map(str, self.ids))+") AND "+query)
175
return self.cr.fetchone()[0] or 0.0
177
def _sum_credit(self, form):
180
ctx = self.context.copy()
181
ctx['fiscalyear'] = form['fiscalyear']
182
ctx['periods'] = form['periods'][0][2]
183
query = self.pool.get('account.move.line')._query_get(self.cr, self.uid, context=ctx)
184
self.cr.execute("SELECT sum(credit) "\
185
"FROM account_move_line l "\
186
"WHERE l.account_id in ("+','.join(map(str, self.ids))+") AND "+query)
187
return self.cr.fetchone()[0] or 0.0
189
report_sxw.report_sxw('report.account.consumo.suc', 'account.account', 'addons/bias_account/report/consumo_suc.rml', parser=consumo_suc, header=False)