1
# -*- encoding: utf-8 -*-
2
##############################################################################
5
# Authors: * Camptocamp
6
# * oldrev <oldrev@gmail.com>
9
# Copyright (C) 2010-TODAY by The HornERP Team
11
# WARNING: This program as such is intended to be used by professional
12
# programmers who take the whole responsability of assessing all potential
13
# consequences resulting from its eventual inadequacies and bugs
14
# End users who are looking for a ready-to-use solution with commercial
15
# garantees and support are strongly adviced to contract a Free Software
18
# This program is Free Software; you can redistribute it and/or
19
# modify it under the terms of the GNU General Public License
20
# as published by the Free Software Foundation; either version 2
21
# of the License, or (at your option) any later version.
23
# This program is distributed in the hope that it will be useful,
24
# but WITHOUT ANY WARRANTY; without even the implied warranty of
25
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26
# GNU General Public License for more details.
28
# You should have received a copy of the GNU General Public License
29
# along with this program; if not, write to the Free Software
30
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32
##############################################################################
35
from mx.DateTime import *
36
from report import report_sxw
42
class LedgerParser(rml_parse.rml_parse):
46
def __init__(self, cr, uid, name, context):
47
super(LedgerParser, self).__init__(cr, uid, name, context)
48
# self.date_borne = {}
51
self.sql_condition = " "
52
self.tot_currency = 0.0
54
self.sold_accounts = {}
55
self.localcontext.update( { # 注册报表模板里可以访问的函数
58
'type':self._check_type,
59
'period_date':self.get_dete,
60
# 'sum_debit_account': self._sum_debit_account,
61
# 'sum_credit_account': self._sum_credit_account,
62
# 'sum_solde_account': self._sum_solde_account,
63
'sum_debit': self._sum_debit,
64
'sum_credit': self._sum_credit,
65
'sum_solde': self._sum_solde,
66
'get_children_accounts': self.get_children_accounts,
67
# 'sum_currency_amount_account': self._sum_currency_amount_account,
68
'get_direction':self._get_direction,
69
# 'sum_quantity_account':self._sum_quantity_account,
70
'account_name' :self._get_account_name,
71
'get_periods':self._get_periods,
72
'sum_begin_solde':self._sum_begin_solde,
73
'sum_year_amount_solde':self._sum_year_amount_solde,
74
'sum_year_amount_currency':self._sum_year_amount_currency,
75
'sum_amount_currency':self._sum_amount_currency,
76
'sum_amount_quantity':self._sum_amount_quantity,
77
'sum_year_quantity':self._sum_year_quantity,
78
'sum_begin_balance_amount_currency':self._sum_begin_balance_amount_currency,
79
'sum_year_balance_amount_currency':self._sum_year_balance_amount_currency,
80
'sum_begin_balance_quantity':self._sum_begin_balance_quantity,
81
'sum_year_balance_quantity':self._sum_year_balance_quantity,
83
self.context = context
85
def set_context(self, objects, data, ids, report_type = None):
89
# self.borne_date = self.get_date(data['form'])
90
self.all_dete = self.get_dete(data['form'])
91
self.sql_condition = self.get_threecolumns_ledger_type(data['form'])
94
if (data['model'] == 'account.account'):
97
new_ids.append(data['form']['Account_list'])
98
objects = self.pool.get('account.account').browse(self.cr, self.uid, new_ids)
100
super(LedgerParser, self).set_context(objects, data, new_ids, report_type)
102
def get_dete(self, form):
106
period_form_id = form['period_form']
107
period_to_id = form['period_to']
108
period_obj = self.pool.get('account.period')
109
period_start_obj = period_obj.read(self.cr, self.uid, period_form_id, ['date_start','fiscalyear_id'])
110
period_end_obj = period_obj.read(self.cr, self.uid, period_to_id, ['date_stop'])
111
fiscalyear_obj = self.pool.get('account.fiscalyear').read(self.cr, self.uid, period_start_obj['fiscalyear_id'], ['date_start'])
113
'period_start_date_start':period_start_obj['date_start'],
114
'period_end_date_stop':period_end_obj['date_stop'],
115
'fiscalyear_obj_date_start':fiscalyear_obj[0]['date_start'],
120
def _get_periods(self, form):
124
self.cr.execute(("select date_start,date_stop,name as period_name "\
125
"from account_period where "\
126
" date_start>='%s' and date_stop<='%s' "\
127
" order by date_start")% (self.all_dete['period_start_date_start'], self.all_dete['period_end_date_stop']))
128
periods = self.cr.dictfetchall()
131
def _check_type(self, form):
138
res['report_name'] = u'三栏式'
139
if form.get('product',''):
140
res['report_name'] = u'产品'
141
product_sql = """SELECT t.name AS name
142
FROM product_product AS p join product_template AS t on (p.product_tmpl_id=t.id)
143
WHERE p.id='%s'"""%(form['product'])
144
self.cr.execute(product_sql)
145
product_res = self.cr.dictfetchall()
146
res['product']=product_res[0]['name']
147
if form.get('partner',''):
148
res['report_name'] = u'业务伙伴'
149
partner_sql = """SELECT name
151
WHERE res_partner.id='%s'"""%(form['partner'])
152
self.cr.execute(partner_sql)
153
partner_res = self.cr.dictfetchall()
154
res['partner']=partner_res[0]['name']
157
def _calc_contrepartie(self,cr,uid,ids, context={}):
163
# result.setdefault(id, False)
165
for account_line in self.pool.get('account.move.line').browse(cr, uid, ids, context):
166
# For avoid long text in the field we will limit it to 5 lines
168
result[account_line.id] = ' '
169
num_id_move = str(account_line.move_id.id)
170
num_id_line = str(account_line.id)
171
account_id = str(account_line.account_id.id)
172
# search the basic account
173
# We have the account ID we will search all account move line from now until this time
174
# We are in the case of we are on the top of the account move Line
175
cr.execute('SELECT distinct(ac.code) as code_rest,ac.name as name_rest from account_account AS ac, account_move_line mv\
176
where ac.id = mv.account_id and mv.move_id = ' + num_id_move +' and mv.account_id <> ' + account_id )
177
res_mv = cr.dictfetchall()
178
# we need a result more than 2 line to make the test so we will made the the on 1 because we have exclude the current line
179
if (len(res_mv) >=1):
182
for move_rest in res_mv:
183
concat = concat + move_rest['code_rest'] + u' ' + move_rest['name_rest'] + u';'
184
result[account_line.id] = concat
186
# we need to stop the computing and to escape but before we will add "..."
187
result[account_line.id] = concat + '...'
192
def get_date(self, form):
196
period_form_id = form['period_form']
197
period_to_id = form['period_to']
198
period_obj = self.pool.get('account.period')
199
period_start_obj = period_obj.read(self.cr, self.uid, period_form_id, ['date_start'])
200
period_end_obj = period_obj.read(self.cr, self.uid, period_to_id, ['date_stop'])
201
borne_min = period_start_obj['date_start']
202
borne_max = period_end_obj['date_stop']
205
'min_date': borne_min,
206
'max_date': borne_max,
208
return self.date_borne
210
def get_threecolumns_ledger_type(self, form):
211
if form.get('product',''):
212
self.sql_condition = " AND l.product_id ='"+str(form['product'])+"'"
213
if form.get('partner',''):
214
self.sql_condition = " AND l.partner_id ='"+str(form['partner'])+"'"
215
return self.sql_condition
218
def get_children_accounts(self, account, form, period, recursion=True):
222
self.child_ids = self.pool.get('account.account').search(self.cr, self.uid,
223
[('parent_id', 'child_of', self.ids)])
226
ctx = self.context.copy()
227
## We will make the test for period or date
228
## We will now make the test
230
#ctx['state'] = form['context'].get('state','all')
231
#if form.has_key('fiscalyear'):
232
# ctx['fiscalyear'] = form['fiscalyear']
233
# ctx['periods'] = form['periods'][0][2]
235
# ctx['date_from'] = form['date_from']
236
# ctx['date_to'] = form['date_to']
238
self.query = self.pool.get('account.move.line')._query_get(self.cr, self.uid, context=ctx)
239
if account and account.child_consol_ids: # add ids of consolidated childs also of selected account
240
ctx['consolidate_childs'] = True
241
ctx['account_id'] = account.id
243
ids_acc = self.pool.get('account.account').search(
244
self.cr, self.uid,[('parent_id', 'child_of', [account.id])], context=ctx)
246
for child_id in ids_acc:
247
child_account = self.pool.get('account.account').browse(self.cr, self.uid, child_id)
248
sold_account = self._sum_solde_account(child_account,form, period)
249
self.sold_accounts[child_account.id] = sold_account
251
if child_account.type != 'view' \
252
and len(self.pool.get('account.move.line').search(self.cr, self.uid,
253
[('account_id','>=',child_account.id)],
255
res.append(child_account)
260
SOLDEINIT = "SELECT sum(l.debit) AS sum_debit, sum(l.credit) AS sum_credit, sum(l.quantity) AS sum_quantity, sum(l.amount_currency) AS sum_amount_currency FROM account_move_line l WHERE l.account_id = " + str(move.id) + " AND l.date < '" + period['date_stop'] + "'" + " AND l.date > '" + period['date_start'] +"'"+ self.sql_condition
261
self.cr.execute(SOLDEINIT)
262
resultat = self.cr.dictfetchall()
264
if resultat[0]['sum_debit'] == None:
267
sum_debit = resultat[0]['sum_debit']
268
if resultat[0]['sum_credit'] == None:
271
sum_credit = resultat[0]['sum_credit']
272
if resultat[0]['sum_amount_currency'] == None:
273
sum_amount_currency =0
275
sum_amount_currency = resultat[0]['sum_amount_currency']
276
if resultat[0]['sum_quantity'] == None:
279
sum_quantity = resultat[0]['sum_quantity']
281
move.init_credit = sum_credit
282
move.init_debit = sum_debit
283
move.init_amount_currency = sum_amount_currency
284
move.init_quantity = sum_quantity
289
move.init_currency = 0
290
move.init_quantity = 0
295
def lines(self, account, form, period, day=False):
297
按向导指定的参数获取所有的 account.move.line
299
self.tot_currency = 0.0
302
'out_invoice': 'CI: ',
303
'in_invoice': 'SI: ',
304
'out_refund': 'OR: ',
308
SELECT l.id, l.date, j.code,c.code AS currency_code,l.amount_currency ,l.ref, l.name , l.debit, l.credit, l.period_id, l.quantity
309
FROM account_move_line as l
310
LEFT JOIN res_currency c on (l.currency_id=c.id)
311
JOIN account_journal j on (l.journal_id=j.id)
317
ORDER BY l.date, l.id""" % (self.query, self.sql_condition)
319
self.cr.execute(sql, (account.id, day, day,))
320
res = self.cr.dictfetchall()
322
self.cr.execute(sql, (account.id, period['date_stop'], period['date_start'],))
323
res = self.cr.dictfetchall()
325
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
327
line = self.pool.get('account.move.line').browse(self.cr, self.uid, l['id'])
328
l['move'] = line.move_id.name
329
self.cr.execute('Select id from account_invoice where move_id =%s'%(line.move_id.id))
330
tmpres = self.cr.dictfetchall()
332
inv = self.pool.get('account.invoice').browse(self.cr, self.uid, tmpres[0]['id'])
333
l['ref'] = inv_types[inv.type] + ': '+str(inv.number)
335
l['partner'] = line.partner_id.name
339
# 需要修正的地方请加上 FIXME 标记,需要尚未实现完全的地方请加上 TODO
340
# by mrshelly 为啥要初始化, 这里也需要处理
341
if type(l['debit']) == type(None):
343
if type(l['credit']) == type(None):
345
# by mrshelly 为啥要初始化, 这里也需要处理
347
sum = l['debit'] - l ['credit']
349
balance = line.balance
351
l['balance'] = abs(balance)
358
l['direction'] = self._get_direction(l['debit'] - l ['credit'])
359
l['line_corresp'] = self._calc_contrepartie(self.cr,self.uid,[l['id']])[l['id']]
360
# Modification du amount Currency
361
#if (l['credit'] > 0):
362
# if l['amount_currency'] != None:
363
# l['amount_currency'] = abs(l['amount_currency']) * -1
365
#if l['amount_currency'] != None:
366
# l['amount_currency_balance'] = self.tot_currency + l['amount_currency']
369
if (l['quantity'] != None and l['quantity'] !=0):
370
if l['debit'] != 0.0:
371
l['price'] = l['debit']/l['quantity']
372
elif l['credit'] != 0.0:
373
l['price'] = l['credit']/l['quantity']
375
if (l['amount_currency'] != None and l['amount_currency'] !=0):
376
if l['debit'] != 0.0:
377
l['rate'] = l['debit']/l['amount_currency']
378
elif l['credit'] != 0.0:
379
l['rate'] = l['credit']/l['amount_currency']
380
l['sum_balance_amount_currency'] = (self._sum_balance_currency_quantiry(l['date'],l['id']))['sum_balance_amount_currency']
381
l['sum_balance_quantity'] = (self._sum_balance_currency_quantiry(l['date'],l['id']))['sum_balance_quantity']
385
def _sum_solde_account(self, account, form, period=False):
390
self.cr.execute("SELECT (sum(debit) - sum(credit)) as tot_solde "\
391
"FROM account_move_line l "\
392
"WHERE l.account_id = "+str(account.id)+" AND l.date<='"+self.all_dete['period_end_date_stop']+"' AND l.date>='"+self.all_dete['period_start_date_start']+"' AND "+self.query+ " "+self.sql_condition)
394
self.cr.execute("SELECT (sum(debit) - sum(credit)) as tot_solde "\
395
"FROM account_move_line l "\
396
"WHERE l.account_id = "+str(account.id)+" AND l.date<='"+period['date_stop']+"' AND l.date>='"+period['date_start']+"' AND "+self.query+ " "+self.sql_condition)
397
sum_solde = self.cr.fetchone()[0] or 0.0
398
if form.get('soldeinit', False):
399
sum_solde += account.init_debit - account.init_credit
403
def _sum_begin_solde(self):
416
self.cr.execute("SELECT sum(debit) as debit , sum(credit) as credit "\
417
"FROM account_move_line l "\
418
"WHERE l.account_id in ("+','.join(map(str, self.pool.get('account.account').search(self.cr, self.uid,
419
[('parent_id', 'child_of', self.ids)])))+") "+ " AND l.date < '" + self.all_dete['period_start_date_start'] +"'"+self.sql_condition)
420
res = self.cr.dictfetchall()
421
sum_begin_solde = (res[0]['debit'] or 0.0) - (res[0]['credit'] or 0.0)
422
if sum_begin_solde == 0:
423
result['direction'] = u'平'
424
elif sum_begin_solde > 0:
425
result['direction'] = u'借'
427
result['direction'] = u'贷'
428
result['sum_begin_solde'] = abs(sum_begin_solde or 0.0)
429
result['begin_date'] = self.all_dete['period_start_date_start']
432
def _sum_year_amount_solde(self, period):
441
'sum_year_amount_solde':0,
443
self.cr.execute("SELECT sum(debit) as debit , sum(credit) as credit "\
444
"FROM account_move_line l "\
445
"WHERE l.account_id in ("+','.join(map(str, self.pool.get('account.account').search(self.cr, self.uid,
446
[('parent_id', 'child_of', self.ids)])))+") "+ " AND l.state<>'draft' AND l.date <= '" + period['date_stop'] +"'"+ " AND l.date >= '" + self.all_dete['fiscalyear_obj_date_start'] + "'"+self.sql_condition)
447
res = self.cr.dictfetchall()
448
sum_year_amount_solde = (res[0]['debit'] or 0.0) - (res[0]['credit'] or 0.0)
449
if sum_year_amount_solde == 0:
450
result['direction'] = u'平'
451
elif sum_year_amount_solde > 0:
452
result['direction'] = u'借'
454
result['direction'] = u'贷'
455
result['sum_year_amount_solde'] = abs(sum_year_amount_solde or 0.0)
456
result['end_date'] = self.all_dete['fiscalyear_obj_date_start']
457
result['debit'] = res[0]['debit']
458
result['credit'] = res[0]['credit']
461
def _sum_amount_currency_quantiry(self, start_date = False, end_date = False):
466
'sum_debit_amount_currency':0.00,
467
'sum_credit_amount_currency':0.00,
468
'sum_debit_quantity':0.00,
469
'sum_credit_quantity':0.00,
472
end_date_sql = " AND l.date <= '" + end_date +"'"
476
start_date_sql = " AND l.date >= '" + start_date + "'"
481
self.cr.execute("SELECT sum(amount_currency) AS amount_currency, sum(quantity) AS quantity "\
482
" FROM account_move_line l "\
483
" WHERE l.account_id in ("+','.join(map(str, self.pool.get('account.account').search(self.cr, self.uid,
484
[('parent_id', 'child_of', self.ids)])))+") "+
485
" AND l.state<>'draft' AND l.debit-l.credit>0 " + end_date_sql + start_date_sql + self.sql_condition)
486
debit_res = self.cr.dictfetchall()
489
self.cr.execute("SELECT sum(amount_currency) AS amount_currency, sum(quantity) AS quantity "\
490
" FROM account_move_line l "\
491
" WHERE l.account_id in ("+','.join(map(str, self.pool.get('account.account').search(self.cr, self.uid,
492
[('parent_id', 'child_of', self.ids)])))+") "+
493
" AND l.state<>'draft' AND l.debit-l.credit<0 " + end_date_sql + start_date_sql + self.sql_condition)
494
cedit_res = self.cr.dictfetchall()
495
if debit_res[0].get('amount_currency',0.00)!= None:
496
result['sum_debit_amount_currency'] = debit_res[0].get('amount_currency',0.00)
497
if debit_res[0].get('quantity',0.00)!=None:
498
result['sum_debit_quantity'] = debit_res[0].get('quantity',0.00)
499
if cedit_res[0].get('amount_currency',0.00)!=None:
500
result['sum_credit_amount_currency'] = cedit_res[0].get('amount_currency',0.00)
501
if cedit_res[0].get('quantity',0.00)!=None:
502
result['sum_credit_quantity'] = cedit_res[0].get('quantity',0.00)
505
def _sum_balance_currency_quantiry(self,date = False, id = False,):
510
'sum_balance_amount_currency':0.00,
511
'sum_balance_quantity':0.00,
513
sum_debit_amount_currency = 0.00
514
sum_credit_amount_currency = 0.00
515
sum_debit_quantity = 0.00
516
sum_credit_quantity = 0.00
517
balance_condition = ' '
519
balance_condition = " AND l.date <= '" + date +"'"
521
balance_condition = " AND (date<'"+str(date)+"' OR (date='"+str(date)+"' AND id<='"+str(id)+"')) "
524
self.cr.execute("SELECT sum(amount_currency) AS amount_currency, sum(quantity) AS quantity"\
525
" FROM account_move_line l "\
526
" WHERE l.account_id in ("+','.join(map(str, self.pool.get('account.account').search(self.cr, self.uid,
527
[('parent_id', 'child_of', self.ids)])))+") "+
528
" AND l.state<>'draft' AND l.debit-l.credit>0 " + balance_condition + self.sql_condition)
529
debit_res = self.cr.dictfetchall()
532
self.cr.execute("SELECT sum(amount_currency) AS amount_currency, sum(quantity) AS quantity"\
533
" FROM account_move_line l "\
534
" WHERE l.account_id in ("+','.join(map(str, self.pool.get('account.account').search(self.cr, self.uid,
535
[('parent_id', 'child_of', self.ids)])))+") "+
536
" AND l.state<>'draft' AND l.debit-l.credit<0 " + balance_condition + self.sql_condition)
537
cedit_res = self.cr.dictfetchall()
539
if debit_res[0].get('amount_currency',0.0)!=None:
540
sum_debit_amount_currency = debit_res[0].get('amount_currency',0.0)
542
if debit_res[0].get('quantity',0.0)!=None:
543
sum_debit_quantity = debit_res[0].get('quantity',0.0)
545
if cedit_res[0].get('amount_currency',0.0)!=None:
546
sum_credit_amount_currency = cedit_res[0].get('amount_currency',0.0)
548
if cedit_res[0].get('quantity',0.0)!=None:
549
sum_credit_quantity = cedit_res[0].get('quantity',0.0)
551
result['sum_balance_amount_currency'] = abs(sum_debit_amount_currency - sum_credit_amount_currency )
552
result['sum_balance_quantity'] = abs(sum_debit_quantity - sum_credit_quantity )
556
def _sum_begin_balance_amount_currency(self):
560
result = self._sum_balance_currency_quantiry(date = self.all_dete['period_start_date_start'])
563
def _sum_year_balance_amount_currency(self, period):
567
result = self._sum_balance_currency_quantiry(date = period['date_stop'])
570
def _sum_year_amount_currency(self, period):
574
result = self._sum_amount_currency_quantiry(self.all_dete['fiscalyear_obj_date_start'], period['date_stop'])
577
def _sum_amount_currency(self, period):
581
result = self._sum_amount_currency_quantiry(self.all_dete['period_start_date_start'],self.all_dete['period_end_date_stop'])
584
def _sum_year_quantity(self, period):
588
result = self._sum_amount_currency_quantiry(self.all_dete['fiscalyear_obj_date_start'], period['date_stop'])
591
def _sum_amount_quantity(self, form, period=False):
595
result = self._sum_amount_currency_quantiry( self.all_dete['period_start_date_start'], self.all_dete['period_end_date_stop'])
598
def _sum_begin_balance_quantity(self):
602
result = self._sum_balance_currency_quantiry(date = self.all_dete['period_start_date_start'])
605
def _sum_year_balance_quantity(self,period):
609
result = self._sum_balance_currency_quantiry(date = period['date_stop'])
612
def _sum_debit(self, form, period=False):
619
self.cr.execute("SELECT sum(debit) "\
620
"FROM account_move_line l "\
621
"WHERE l.account_id in ("+','.join(map(str, self.child_ids))+") AND "+self.query + " AND l.date < '" +self.all_dete['period_end_date_stop'] + "'" + " AND l.date > '" + self.all_dete['period_start_date_start'] +"'"+self.sql_condition)
623
self.cr.execute("SELECT sum(debit) "\
624
"FROM account_move_line l "\
625
"WHERE l.account_id in ("+','.join(map(str, self.child_ids))+") AND "+self.query + " AND l.date < '" + period['date_stop'] + "'" + " AND l.date > '" + period['date_start'] +"'"+self.sql_condition)
626
sum_debit = self.cr.fetchone()[0] or 0.0
629
def _sum_credit(self, form, period=False):
636
self.cr.execute("SELECT sum(credit) "\
637
"FROM account_move_line l "\
638
"WHERE l.account_id in ("+','.join(map(str, self.child_ids))+") AND "+self.query + " AND l.date < '" +self.all_dete['period_end_date_stop'] + "'" + " AND l.date > '" + self.all_dete['period_start_date_start'] +"'"+self.sql_condition)
640
self.cr.execute("SELECT sum(credit) "\
641
"FROM account_move_line l "\
642
"WHERE l.account_id in ("+','.join(map(str, self.child_ids))+") AND "+self.query + " AND l.date < '" + period['date_stop'] + "'" + " AND l.date > '" + period['date_start'] +"'"+self.sql_condition)
643
## Add solde init to the result
644
sum_credit = self.cr.fetchone()[0] or 0.0
647
def _sum_solde(self, form, period=False):
654
self.cr.execute("SELECT (sum(debit) - sum(credit)) as tot_solde "\
655
"FROM account_move_line l "\
656
"WHERE l.account_id in ("+','.join(map(str, self.child_ids))+") AND "+self.query + " AND l.date < '" +self.all_dete['period_end_date_stop'] + "'" + " AND l.date > '" + self.all_dete['period_start_date_start'] +"'"+self.sql_condition)
658
self.cr.execute("SELECT (sum(debit) - sum(credit)) as tot_solde "\
659
"FROM account_move_line l "\
660
"WHERE l.account_id in ("+','.join(map(str, self.child_ids))+") AND "+self.query + " AND l.date < '" + period['date_stop'] + "'" + " AND l.date > '" + period['date_start'] +"'"+self.sql_condition)
661
sum_solde = abs(self.cr.fetchone()[0] or 0.0)
664
# def _sum_amount_currency(self, form, period=False):
668
# self.cr.execute("SELECT sum(amount_currency) "\
669
# "FROM account_move_line l "\
670
# "WHERE l.account_id in ("+','.join(map(str, self.child_ids))+") AND "+self.query + " AND l.date < '" +self.all_dete['period_end_date_stop'] + "'" + " AND l.date > '" + self.all_dete['period_start_date_start'] +"'"+self.sql_condition)
672
# self.cr.execute("SELECT sum(amount_currency) "\
673
# "FROM account_move_line l "\
674
# "WHERE l.account_id in ("+','.join(map(str, self.child_ids))+") AND "+self.query + " AND l.date < '" + period['date_stop'] + "'" + " AND l.date > '" + period['date_start'] +"'"+self.sql_condition)
675
# sum_amount_currency = self.cr.fetchone()[0] or 0.0
676
# return sum_amount_currency
678
def _set_get_account_currency_code(self, account_id):
679
self.cr.execute("SELECT c.code as code "\
680
"FROM res_currency c,account_account as ac "\
681
"WHERE ac.id = %s AND ac.currency_id = c.id"%(account_id))
682
result = self.cr.fetchone()
684
self.account_currency = result[0]
686
self.account_currency = False
688
# def _sum_currency_amount_account(self, account, form):
689
# self._set_get_account_currency_code(account.id)
690
# self.cr.execute("SELECT sum(aml.amount_currency) FROM account_move_line as aml,res_currency as rc WHERE aml.currency_id = rc.id AND aml.account_id= %s ", (account.id,))
691
# total = self.cr.fetchone()
692
# if self.account_currency:
693
# return_field = str(total[0]) + self.account_currency
694
# return return_field
696
# currency_total = self.tot_currency = 0.0
697
# return currency_total
699
def _get_direction(self, balance):
710
def _get_account_name(self,account):
715
account_name = self.pool.get('account.account').name_get(self.cr, self.uid, id,{})
716
return account_name[0][1]
719
class CashLedgerParser(LedgerParser):
723
def __init__(self, cr, uid, name, context):
724
super(CashLedgerParser, self).__init__(cr, uid, name, context)
725
self.localcontext.update({
729
def days(self, account, form, period):
731
从 account.move.line 里按日期分组
732
也就是把所有的凭证明细的不同日分出来,方便计算单日合计
735
SELECT l.date AS date, SUM(l.debit) AS debit, SUM(l.credit) AS credit, MAX(l.id) AS last_line_id, sum(l.amount_currency) AS sum_currency
736
FROM account_move_line AS l
737
LEFT JOIN res_currency c on (l.currency_id=c.id)
738
JOIN account_journal j on (l.journal_id=j.id)
744
ORDER BY l.date """ % (self.query)
745
max_date = period['date_stop']
746
min_date = period['date_start']
747
self.cr.execute(sql, (account.id, max_date, min_date))
749
res = self.cr.dictfetchall()
750
account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
753
day['sum_balance_amount_currency'] = (self._sum_balance_currency_quantiry( date = str(day.get('date','')))).get('sum_balance_amount_currency',0.0)
754
day['sum_debit_amount_currency'] = (self._sum_amount_currency_quantiry( start_date = str(day.get('date','')),end_date = str(day.get('date','')))).get('sum_debit_amount_currency',0.0)
755
day['sum_credit_amount_currency'] = (self._sum_amount_currency_quantiry( start_date = str(day.get('date','')),end_date = str(day.get('date','')))).get('sum_credit_amount_currency',0.0)
756
line = self.pool.get('account.move.line').browse(self.cr, self.uid, day['last_line_id'])
757
day['balance'] = abs(line.balance)
758
if(type(day['debit']) == type(None)):
759
day['debit'] = 0.0 # by mrshelly 只是为了报表出来.这里需要处理.
760
if(type(day['credit']) == type(None)):
761
day['credit'] = 0.0 # by mrshelly 只是为了报表出来.这里需要处理.
770
report_sxw.report_sxw('report.account.cash_ledger', 'account.account', 'addons/l10n_account_cn/report/cash_ledger.odt', parser=CashLedgerParser, header=False)
773
report_sxw.report_sxw('report.account.foreign_currency_cash_ledger', 'account.account', 'addons/l10n_account_cn/report/foreign_currency_cash_ledger.odt', parser=CashLedgerParser, header=False)
776
report_sxw.report_sxw('report.account.threecolumns_ledger', 'account.account', 'addons/l10n_account_cn/report/threecolumns_ledger.odt', parser=LedgerParser, header=False)
779
report_sxw.report_sxw('report.account.product_ledger', 'account.account', 'addons/l10n_account_cn/report/product_ledger.odt', parser=LedgerParser, header=False)
781
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: