[IMP] account module : Analytic reports.
authorvra (Tiny) <vra@tinyerp.com>
Thu, 18 Jun 2009 13:15:48 +0000 (18:45 +0530)
committervra (Tiny) <vra@tinyerp.com>
Thu, 18 Jun 2009 13:15:48 +0000 (18:45 +0530)
bzr revid: vra@tinyerp.com-20090618131548-h1xp6j96b2gx1ou6

addons/account/project/report/analytic_balance.py
addons/account/project/report/analytic_journal.rml
addons/account/project/report/inverted_analytic_balance.rml

index 3414249..461f271 100644 (file)
@@ -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):
index 6cb3815..bd4129f 100644 (file)
     <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>
             </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>
         <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>
       <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>
index 1851139..5761fc1 100644 (file)
       <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>
         <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>