1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved
# $Id$
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import pooler
import time
from report import report_sxw
class third_party_ledger(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context):
super(third_party_ledger, self).__init__(cr, uid, name, context)
self.localcontext.update( {
'time': time,
'lines': self.lines,
'sum_debit_partner': self._sum_debit_partner,
'sum_credit_partner': self._sum_credit_partner,
'sum_debit': self._sum_debit,
'sum_credit': self._sum_credit,
'get_company': self._get_company,
'get_currency': self._get_currency,
})
def preprocess(self, objects, data, ids):
if data['form']['category'] == 'Customer' or data['form']['category'] == 'Supplier' :
cat_id=pooler.get_pool(self.cr.dbname).get('res.partner.category').search(self.cr,self.uid,[('name','=',data['form']['category'])])
cat_id+=pooler.get_pool(self.cr.dbname).get('res.partner.category').search(self.cr,self.uid,[('parent_id','child_of',cat_id)])
else:
cat_id=pooler.get_pool(self.cr.dbname).get('res.partner.category').search(self.cr,self.uid,[('name','in',['Customer','Supplier'])])
cat_id+=pooler.get_pool(self.cr.dbname).get('res.partner.category').search(self.cr,self.uid,[('parent_id','child_of',cat_id)])
self.cr.execute('SELECT partner_id from res_partner_category_rel where category_id in ('+','.join(map(str,cat_id))+')')
data_parner=self.cr.fetchall()
self.par_ids=[]
self.par_ids=list(set([x[0] for x in data_parner]))
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
line_query = account_move_line_obj._query_get(self.cr, self.uid, obj='line',
context={'fiscalyear': data['form']['fiscalyear']})
self.cr.execute(
"SELECT DISTINCT line.partner_id " \
"FROM account_move_line AS line, account_account AS account " \
"WHERE line.partner_id IS NOT NULL " \
"AND line.date >= %s " \
"AND line.date <= %s " \
"AND " + line_query + " " \
"AND line.account_id = account.id " \
"AND account.company_id = %d " \
"AND partner_id in ("+','.join(map(str,self.par_ids))+")" \
"AND account.active",
(data['form']['date1'], data['form']['date2'],
data['form']['company_id']))
new_ids = [id for (id,) in self.cr.fetchall()]
self.cr.execute(
"SELECT a.id " \
"FROM account_account a " \
"LEFT JOIN account_account_type t " \
"ON (a.type=t.code) " \
"WHERE t.partner_account=TRUE " \
"AND a.company_id = %d " \
"AND a.active", (data['form']['company_id'],))
self.account_ids = ','.join([str(a) for (a,) in self.cr.fetchall()])
self.partner_ids = ','.join(map(str, new_ids))
objects = self.pool.get('res.partner').browse(self.cr, self.uid, new_ids)
super(third_party_ledger, self).preprocess(objects, data, new_ids)
def lines(self, partner):
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
line_query = account_move_line_obj._query_get(self.cr, self.uid, obj='l',
context={'fiscalyear': self.datas['form']['fiscalyear']})
self.cr.execute(
"SELECT l.date, j.code, l.ref, l.name, l.debit, l.credit " \
"FROM account_move_line l " \
"LEFT JOIN account_journal j " \
"ON (l.journal_id = j.id) " \
"WHERE l.partner_id = %d " \
"AND l.account_id IN (" + self.account_ids + ") " \
"AND l.date >= %s " \
"AND l.date <= %s "
"AND " + line_query + " " \
"ORDER BY l.id",
(partner.id, self.datas['form']['date1'], self.datas['form']['date2']))
res = self.cr.dictfetchall()
sum = 0.0
for r in res:
sum += r['debit'] - r['credit']
r['progress'] = sum
return res
def _sum_debit_partner(self, partner):
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
line_query = account_move_line_obj._query_get(self.cr, self.uid,
obj='account_move_line',
context={'fiscalyear': self.datas['form']['fiscalyear']})
self.cr.execute(
"SELECT sum(debit) " \
"FROM account_move_line " \
"WHERE partner_id = %d " \
"AND account_id IN (" + self.account_ids + ") " \
"AND date >= %s " \
"AND date <= %s " \
"AND " + line_query,
(partner.id, self.datas['form']['date1'], self.datas['form']['date2']))
return self.cr.fetchone()[0] or 0.0
def _sum_credit_partner(self, partner):
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
line_query = account_move_line_obj._query_get(self.cr, self.uid,
obj='account_move_line',
context={'fiscalyear': self.datas['form']['fiscalyear']})
self.cr.execute(
"SELECT sum(credit) " \
"FROM account_move_line " \
"WHERE partner_id=%d " \
"AND account_id IN (" + self.account_ids + ") " \
"AND date >= %s " \
"AND date <= %s " \
"AND " + line_query,
(partner.id, self.datas["form"]["date1"], self.datas["form"]["date2"]))
return self.cr.fetchone()[0] or 0.0
def _sum_debit(self):
if not self.ids:
return 0.0
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
line_query = account_move_line_obj._query_get(self.cr, self.uid,
obj='account_move_line',
context={'fiscalyear': self.datas['form']['fiscalyear']})
self.cr.execute(
"SELECT sum(debit) " \
"FROM account_move_line " \
"WHERE partner_id IN (" + self.partner_ids + ") " \
"AND account_id IN (" + self.account_ids + ") " \
"AND date >= %s " \
"AND date <= %s " \
"AND " + line_query,
(self.datas['form']['date1'], self.datas['form']['date2']))
return self.cr.fetchone()[0] or 0.0
def _sum_credit(self):
if not self.ids:
return 0.0
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
line_query = account_move_line_obj._query_get(self.cr, self.uid,
obj='account_move_line',
context={'fiscalyear': self.datas['form']['fiscalyear']})
self.cr.execute(
"SELECT sum(credit) " \
"FROM account_move_line " \
"WHERE partner_id IN (" + self.partner_ids + ") " \
"AND account_id IN (" + self.account_ids + ") " \
"AND date >= %s " \
"AND date <= %s " \
"AND " + line_query,
(self.datas['form']['date1'], self.datas['form']['date2']))
return self.cr.fetchone()[0] or 0.0
def _get_company(self, form):
return pooler.get_pool(self.cr.dbname).get('res.company').browse(self.cr, self.uid, form['company_id']).name
def _get_currency(self, form):
return pooler.get_pool(self.cr.dbname).get('res.company').browse(self.cr, self.uid, form['company_id']).currency_id.name
report_sxw.report_sxw('report.third_party_ledger', 'res.partner',
'addons/cci_account/report/third_party_ledger.rml',parser=third_party_ledger,
header=False)
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|