[IMP] account module : Analytic reports.
bzr revid: vra@tinyerp.com-20090618131548-h1xp6j96b2gx1ou6
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
|
||||
# $Id$
|
||||
#
|
||||
@@ -28,6 +28,7 @@ from report import report_sxw
|
||||
class account_analytic_balance(report_sxw.rml_parse):
|
||||
def __init__(self, cr, uid, name, context):
|
||||
super(account_analytic_balance, self).__init__(cr, uid, name, context)
|
||||
self.done_l = []
|
||||
self.localcontext.update( {
|
||||
'time': time,
|
||||
'lines_g': self._lines_g,
|
||||
@@ -40,34 +41,41 @@ class account_analytic_balance(report_sxw.rml_parse):
|
||||
'move_sum_balance': self._move_sum_balance,
|
||||
'move_sum_quantity': self._move_sum_quantity,
|
||||
})
|
||||
|
||||
|
||||
def _lines_g(self, account_id, date1, date2):
|
||||
res = []
|
||||
account_analytic_obj = self.pool.get('account.analytic.account')
|
||||
ids = account_analytic_obj.search(self.cr, self.uid,
|
||||
[('parent_id', 'child_of', [account_id])])
|
||||
self.cr.execute("SELECT aa.name AS name, aa.code AS code, \
|
||||
sum(aal.amount) AS balance, sum(aal.unit_amount) AS quantity \
|
||||
FROM account_analytic_line AS aal, account_account AS aa \
|
||||
WHERE (aal.general_account_id=aa.id) \
|
||||
AND (aal.account_id in (" + ','.join(map(str, ids)) + "))\
|
||||
AND (date>=%s) AND (date<=%s) AND aa.active \
|
||||
GROUP BY aal.general_account_id, aa.name, aa.code, aal.code \
|
||||
ORDER BY aal.code", (date1, date2))
|
||||
res = self.cr.dictfetchall()
|
||||
|
||||
for r in res:
|
||||
if r['balance'] > 0:
|
||||
r['debit'] = r['balance']
|
||||
r['credit'] = 0.0
|
||||
elif r['balance'] < 0:
|
||||
r['debit'] = 0.0
|
||||
r['credit'] = -r['balance']
|
||||
temp_l = ids
|
||||
for id in ids:
|
||||
if id not in self.done_l:
|
||||
self.done_l.append(id)
|
||||
else:
|
||||
r['balance'] == 0
|
||||
r['debit'] = 0.0
|
||||
r['credit'] = 0.0
|
||||
temp_l.remove(id)
|
||||
if temp_l:
|
||||
self.cr.execute("SELECT aa.name AS name, aa.code AS code, \
|
||||
sum(aal.amount) AS balance, sum(aal.unit_amount) AS quantity \
|
||||
FROM account_analytic_line AS aal, account_account AS aa \
|
||||
WHERE (aal.general_account_id=aa.id) \
|
||||
AND (aal.account_id in (" + ','.join(map(str, temp_l)) + "))\
|
||||
AND (date>=%s) AND (date<=%s) AND aa.active \
|
||||
GROUP BY aal.general_account_id, aa.name, aa.code, aal.code \
|
||||
ORDER BY aal.code", (date1, date2))
|
||||
res = self.cr.dictfetchall()
|
||||
for r in res:
|
||||
if r['balance'] > 0:
|
||||
r['debit'] = r['balance']
|
||||
r['credit'] = 0.0
|
||||
elif r['balance'] < 0:
|
||||
r['debit'] = 0.0
|
||||
r['credit'] = -r['balance']
|
||||
else:
|
||||
r['balance'] == 0
|
||||
r['debit'] = 0.0
|
||||
r['credit'] = 0.0
|
||||
return res
|
||||
|
||||
|
||||
|
||||
def _move_sum_debit(self, account_id, date1, date2):
|
||||
account_analytic_obj = self.pool.get('account.analytic.account')
|
||||
@@ -90,12 +98,12 @@ class account_analytic_balance(report_sxw.rml_parse):
|
||||
AND date>=%s AND date<=%s AND amount<0",
|
||||
(date1, date2))
|
||||
return self.cr.fetchone()[0] or 0.0
|
||||
|
||||
|
||||
def _move_sum_balance(self, account_id, date1, date2):
|
||||
debit = self._move_sum_debit(account_id, date1, date2)
|
||||
debit = self._move_sum_debit(account_id, date1, date2)
|
||||
credit = self._move_sum_credit(account_id, date1, date2)
|
||||
return (debit-credit)
|
||||
|
||||
|
||||
def _move_sum_quantity(self, account_id, date1, date2):
|
||||
account_analytic_obj = self.pool.get('account.analytic.account')
|
||||
ids = account_analytic_obj.search(self.cr, self.uid,
|
||||
@@ -107,7 +115,7 @@ class account_analytic_balance(report_sxw.rml_parse):
|
||||
(date1, date2))
|
||||
return self.cr.fetchone()[0] or 0.0
|
||||
|
||||
|
||||
|
||||
def _sum_debit(self, accounts, date1, date2):
|
||||
ids = map(lambda x: x.id, accounts)
|
||||
if not len(ids):
|
||||
@@ -121,7 +129,7 @@ class account_analytic_balance(report_sxw.rml_parse):
|
||||
AND date>=%s AND date<=%s AND amount>0",
|
||||
(date1, date2))
|
||||
return self.cr.fetchone()[0] or 0.0
|
||||
|
||||
|
||||
def _sum_credit(self, accounts, date1, date2):
|
||||
ids = map(lambda x: x.id, accounts)
|
||||
if not len(ids):
|
||||
|
||||
@@ -119,7 +119,7 @@
|
||||
<blockTable colWidths="539.0" style="Table_Tilte">
|
||||
<tr>
|
||||
<td>
|
||||
<para style="terp_header_Centre">Analitic Journal - [[ company.currency_id.name ]]</para>
|
||||
<para style="terp_header_Centre">Analytic Journal - [[ company.currency_id.name ]]</para>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
@@ -203,10 +203,10 @@
|
||||
</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="terp_default_9">[[ move.name ]]</para>
|
||||
<para style="terp_default_9">[[ move.name ]] KI</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="terp_default_9">[[ move.account_id.code ]] - [[ move.account_id.name ]]</para>
|
||||
<para style="terp_default_9">[[ move.account_id.code ]] [[ move.account_id.name ]]</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="terp_default_Right_9">[[ formatLang(move.debit-move.credit) ]]</para>
|
||||
@@ -226,13 +226,13 @@
|
||||
<blockTable colWidths="85.0,62.0,168.0,73.0,74.0,77.0" style="Table4">
|
||||
<tr>
|
||||
<td>
|
||||
<para style="terp_default_9">[[ move_a or removeParentNode('blockTable') ]] [[ formatLang(move_a.date,date = True) ]]</para>
|
||||
<para style="terp_default_9">[[ (not move_a) and removeParentNode('blockTable') ]] [[ formatLang(move_a.date,date = True) ]]</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="terp_default_9">[[ move_a.code ]]</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="terp_default_9">[[ move_a.name ]]</para>
|
||||
<para style="terp_default_9">[[ move_a.name ]] asgfas</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="terp_default_9">[[ move_a.account_id.code ]] - [[ move_a.account_id.name ]]</para>
|
||||
@@ -266,7 +266,7 @@
|
||||
<blockTable colWidths="85.0,62.0,168.0,73.0,74.0,77.0" style="Table3">
|
||||
<tr>
|
||||
<td>
|
||||
<para style="terp_default_9">[[ move_a or removeParentNode('blockTable') ]] [[ formatLang(move_a.date,date = True) ]]</para>
|
||||
<para style="terp_default_9">[[ (not move_a) and removeParentNode('blockTable') ]] [[ formatLang(move_a.date,date = True) ]]</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="terp_default_9">[[ move_a.code ]]</para>
|
||||
|
||||
@@ -157,7 +157,7 @@
|
||||
<blockTable colWidths="58.0,238.0,62.0,62.0,60.0,59.0" style="Table3">
|
||||
<tr>
|
||||
<td>
|
||||
<para style="terp_default_Bold_9">[[ move_g or removeParentNode('blockTable') ]] [[ move_g['code'] ]]</para>
|
||||
<para style="terp_default_Bold_9">[[ (not move_g) and removeParentNode('blockTable') ]] [[ move_g['code'] ]]</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="terp_default_Bold_9">[[ move_g['name'] ]]</para>
|
||||
@@ -184,7 +184,7 @@
|
||||
<blockTable colWidths="58.0,238.0,62.0,62.0,60.0,59.0" style="Table4">
|
||||
<tr>
|
||||
<td>
|
||||
<para style="terp_default_9">[[ move_a or removeParentNode('blockTable') ]] [[ move_a['code'] ]]</para>
|
||||
<para style="terp_default_9">[[ (not move_a) and removeParentNode('blockTable') ]] [[ move_a['code'] ]]</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="terp_default_9">[[ move_a['complete_name'] ]]</para>
|
||||
|
||||
Reference in New Issue
Block a user