*complted Analytic Balance reports.
authorapa-tiny <patelamit2003@gmail.com>
Mon, 6 Oct 2008 09:46:37 +0000 (15:16 +0530)
committerapa-tiny <patelamit2003@gmail.com>
Mon, 6 Oct 2008 09:46:37 +0000 (15:16 +0530)
*add partner_balance with wizard...

bzr revid: patelamit2003@gmail.com-20081006094637-8rpw9qndk6o4uue0

addons/account/project/report/analytic_balance.py
addons/account/project/report/analytic_balance.rml
addons/account/report/account_balance.py
addons/account/report/account_balance.rml
addons/account/report/partner_balance.py
addons/account/report/partner_balance.rml
addons/account/wizard/wizard_partner_balance_report.py

index b16a604..34f8632 100644 (file)
@@ -31,8 +31,9 @@
 import pooler
 import time
 from report import report_sxw
+import rml_parse
 
-class account_analytic_balance(report_sxw.rml_parse):
+class account_analytic_balance(rml_parse.rml_parse):
     def __init__(self, cr, uid, name, context):
         super(account_analytic_balance, self).__init__(cr, uid, name, context)
         self.localcontext.update( {
index 6191906..77d52c2 100644 (file)
@@ -3,6 +3,37 @@
   <template pageSize="(595.0,842.0)" title="Test" author="Martin Simon" allowSplitting="20">
     <pageTemplate id="first">
       <frame id="first" x1="57.0" y1="57.0" width="481" height="728"/>
+      <header>
+                       <pageGraphics>
+                               <!--logo-->
+                               <!--<fill color="darkblue"/>-->
+                               <!--<stroke color="darkblue"/>-->
+
+                               <!--TITLE COMPANY-->
+                               <!-- <drawString x="4.6cm" y="28.7cm">[[ company.partner_id.name ]]</drawString> -->
+
+                               <setFont name="Helvetica-Bold" size="9"/>
+
+
+                               <!--COL 1-->
+                               <drawString x="1.0cm" y="28.1cm">[[ company.name ]]</drawString>
+                               <drawRightString x="20cm" y="28.1cm">Analytic Balance</drawRightString>
+                               
+                               <!-- Header -->
+                               
+                               
+                               <setFont name="Helvetica" size="9"/>
+                               <drawString x="1.0cm" y="1cm"> [[ time.strftime("%Y-%m-%d %H:%M", time.localtime()) ]]</drawString>
+                               <drawString x="19.0cm" y="1cm">Page <pageNumber/></drawString>
+                               <!--<drawRightString x="19.8cm" y="28cm">[[ company.rml_header1 ]]</drawRightString>-->
+                               
+
+                           <lineMode width="0.7"/>
+                               <lines>1cm 27.7cm 20cm 27.7cm</lines>
+                               <setFont name="Helvetica" size="8"/>
+                       
+                       </pageGraphics>
+                       </header>   
     </pageTemplate>
   </template>
   <stylesheet>
       <blockAlignment value="LEFT"/>
       <blockValign value="TOP"/>
     </blockTableStyle>
-    <blockTableStyle id="Tableau1">
-      <blockAlignment value="LEFT"/>
-      <blockValign value="TOP"/>
-      <blockBackground colorName="#e6e6e6" start="0,0" stop="0,0"/>
-      <blockBackground colorName="#e6e6e6" start="1,0" stop="1,0"/>
-      <blockBackground colorName="#e6e6e6" start="2,0" stop="2,0"/>
-      <blockBackground colorName="#e6e6e6" start="0,1" stop="0,1"/>
-      <blockBackground colorName="#e6e6e6" start="1,1" stop="1,1"/>
-      <blockBackground colorName="#e6e6e6" start="2,1" stop="2,1"/>
-    </blockTableStyle>
-    <blockTableStyle id="Tableau8">
-      <blockAlignment value="LEFT"/>
+    <blockTableStyle id="Table1">
       <blockValign value="TOP"/>
-      <lineStyle kind="GRID" colorName="black"/>
+      <lineStyle kind="LINEBELOW" colorName="#000000" start="0,0" stop="-1,0"/>
+      <lineStyle kind="LINEBELOW" colorName="#000000" start="0,1" stop="-1,1"/>
     </blockTableStyle>
     <blockTableStyle id="Table2">
       <blockAlignment value="LEFT"/>
       <blockValign value="TOP"/>
-      <blockBackground colorName="#e6e6e6" start="0,0" stop="0,0"/>
+      
     </blockTableStyle>
-    <blockTableStyle id="Tableau2">
+    <blockTableStyle id="tbl_content">
       <blockAlignment value="LEFT"/>
       <blockValign value="TOP"/>
+      
     </blockTableStyle>
-    <blockTableStyle id="Table1">
+    <blockTableStyle id="tbl_data">
       <blockAlignment value="LEFT"/>
       <blockValign value="TOP"/>
-      <blockBackground colorName="#e6e6e6" start="0,0" stop="0,0"/>
-      <blockBackground colorName="#e6e6e6" start="1,0" stop="1,0"/>
-      <blockBackground colorName="#e6e6e6" start="2,0" stop="2,0"/>
-      <blockBackground colorName="#e6e6e6" start="3,0" stop="3,0"/>
-      <blockBackground colorName="#e6e6e6" start="4,0" stop="4,0"/>
-    </blockTableStyle>
-    <blockTableStyle id="Tableau10">
-      <blockAlignment value="LEFT"/>
-      <blockValign value="TOP"/>
-      <lineStyle kind="GRID" colorName="black"/>
+      <lineStyle kind="LINEBELOW" colorName="#777777" start="0,0" stop="1,0"/>
+      <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,1" stop="-1,-1"/>
     </blockTableStyle>
     <initialize>
       <paraStyle name="all" alignment="justify"/>
     </initialize>
-    <paraStyle name="P1" fontName="Times-Roman" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/>
-    <paraStyle name="P2" fontName="Times-Bold" fontSize="20.0" leading="25" alignment="CENTER" spaceBefore="0.0" spaceAfter="0.0"/>
-    <paraStyle name="P3" fontName="Times-Bold" fontSize="10.0" leading="13" alignment="RIGHT" spaceBefore="0.0" spaceAfter="0.0"/>
-    <paraStyle name="P4" fontName="Times-Roman" fontSize="10.0" leading="13" alignment="RIGHT" spaceBefore="0.0" spaceAfter="0.0"/>
-    <paraStyle name="P5" fontName="Times-Bold" fontSize="11.0" leading="14" alignment="CENTER" spaceBefore="0.0" spaceAfter="0.0"/>
-    <paraStyle name="P6" fontName="Times-Bold" fontSize="9.0" leading="11" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/>
-    <paraStyle name="P7" fontName="Times-Roman" fontSize="9.0" leading="11" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/>
-    <paraStyle name="P8" fontName="Times-Roman" fontSize="9.0" leading="11" alignment="RIGHT" spaceBefore="0.0" spaceAfter="0.0"/>
-    <paraStyle name="P9" fontName="Times-Bold" fontSize="9.0" leading="11" alignment="RIGHT" spaceBefore="0.0" spaceAfter="0.0"/>
-    <paraStyle name="P10" fontName="Times-Roman"/>
-    <paraStyle name="P11" fontName="Times-Roman" fontSize="9.0" leading="11" alignment="CENTER"/>
-    <paraStyle name="P12" fontName="Times-Roman" fontSize="6.0" leading="8"/>
-    <paraStyle name="P13" fontName="Times-Roman" fontSize="10.0" leading="13" alignment="LEFT"/>
-    <paraStyle name="P14" fontName="Times-Roman" fontSize="10.0" leading="13" alignment="LEFT"/>
-    <paraStyle name="P15" fontName="Times-Roman" fontSize="6.0" leading="8"/>
-    <paraStyle name="P16" fontName="Times-Bold" fontSize="11.0" leading="14" alignment="CENTER" spaceBefore="0.0" spaceAfter="0.0"/>
-    <paraStyle name="P17" fontName="Times-Roman" fontSize="10.0" leading="13" alignment="CENTER" spaceBefore="0.0" spaceAfter="0.0"/>
-    <paraStyle name="P18" fontName="Times-Bold" fontSize="9.0" leading="11" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/>
     <paraStyle name="Standard" fontName="Times-Roman"/>
     <paraStyle name="Text body" fontName="Times-Roman" spaceBefore="0.0" spaceAfter="6.0"/>
     <paraStyle name="List" fontName="Times-Roman" spaceBefore="0.0" spaceAfter="6.0"/>
     <paraStyle name="Table Heading" fontName="Times-Roman" alignment="CENTER" spaceBefore="0.0" spaceAfter="0.0"/>
     <paraStyle name="Caption" fontName="Times-Roman" fontSize="10.0" leading="13" spaceBefore="6.0" spaceAfter="6.0"/>
     <paraStyle name="Index" fontName="Times-Roman"/>
+    <paraStyle name="Heading" fontName="Helvetica" fontSize="15.0" leading="19" spaceBefore="12.0" spaceAfter="6.0"/>
+    <paraStyle name="Footer" fontName="Times-Roman"/>
+    <paraStyle name="Horizontal Line" fontName="Times-Roman" fontSize="6.0" leading="8" spaceBefore="0.0" spaceAfter="14.0"/>
+    <paraStyle name="terp_header" fontName="Helvetica-Bold" fontSize="15.0" leading="19" alignment="LEFT" spaceBefore="12.0" spaceAfter="6.0"/>
+    <paraStyle name="Heading 9" fontName="Helvetica-Bold" fontSize="75%" leading="NaN" spaceBefore="12.0" spaceAfter="6.0"/>
+    <paraStyle name="terp_tblheader_General" fontName="Helvetica-Bold" fontSize="8.0" leading="10" alignment="LEFT" spaceBefore="6.0" spaceAfter="6.0"/>
+    <paraStyle name="terp_tblheader_Details" fontName="Helvetica" fontSize="8.0" leading="11" alignment="LEFT" spaceBefore="6.0" spaceAfter="6.0"/>
+    <paraStyle name="terp_default_8" fontName="Helvetica" fontSize="8.0" leading="10" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/>
+    <paraStyle name="terp_default_Bold_8" fontName="Helvetica-Bold" fontSize="8.0" leading="10" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/>
+    <paraStyle name="terp_tblheader_General_Centre" fontName="Helvetica-Bold" fontSize="8.0" leading="10" alignment="CENTER" spaceBefore="6.0" spaceAfter="6.0"/>
+    <paraStyle name="terp_tblheader_General_Right" fontName="Helvetica-Bold" fontSize="8.0" leading="10" alignment="RIGHT" spaceBefore="6.0" spaceAfter="6.0"/>
+    <paraStyle name="terp_tblheader_Details_Centre" fontName="Helvetica" fontSize="8.0" leading="11" alignment="CENTER" spaceBefore="6.0" spaceAfter="6.0"/>
+    <paraStyle name="terp_tblheader_Details_Right" fontName="Helvetica" fontSize="8.0" leading="11" alignment="RIGHT" spaceBefore="6.0" spaceAfter="6.0"/>
+    <paraStyle name="terp_default_Right_8" fontName="Helvetica" fontSize="8.0" leading="10" alignment="RIGHT" spaceBefore="0.0" spaceAfter="0.0"/>
+    <paraStyle name="terp_default_Centre_8" fontName="Helvetica" fontSize="8.0" leading="10" alignment="CENTER" spaceBefore="0.0" spaceAfter="0.0"/>
+    <paraStyle name="terp_header_Right" fontName="Helvetica-Bold" fontSize="15.0" leading="19" alignment="LEFT" spaceBefore="12.0" spaceAfter="6.0"/>
+    <paraStyle name="terp_header_Centre" fontName="Helvetica-Bold" fontSize="15.0" leading="19" alignment="CENTER" spaceBefore="12.0" spaceAfter="6.0"/>
+    <paraStyle name="terp_default_address" fontName="Helvetica" fontSize="10.0" leading="13" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/>
+    <paraStyle name="terp_default_9" fontName="Helvetica" fontSize="9.0" leading="11" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/>
+    <paraStyle name="terp_default_Bold_9" fontName="Helvetica-Bold" fontSize="9.0" leading="11" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/>
+    <paraStyle name="terp_default_Centre_9" fontName="Helvetica" fontSize="9.0" leading="11" alignment="CENTER" spaceBefore="0.0" spaceAfter="0.0"/>
+    <paraStyle name="terp_default_Right_9" fontName="Helvetica" fontSize="9.0" leading="11" alignment="RIGHT" spaceBefore="0.0" spaceAfter="0.0"/>
+    <paraStyle name="terp_default_8_right_bold" fontName="Helvetica-Bold" fontSize="8.0" leading="10" alignment="RIGHT" spaceBefore="0.0" spaceAfter="0.0"/>
+    <paraStyle name="terp_default_8_bold" fontName="Helvetica-Bold" fontSize="8.0" leading="10" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/>
   </stylesheet>
+  <images/>
   <story>
-    <blockTable colWidths="161.0,161.0,161.0" repeatRows="1" style="Tableau1">
-      <tr>
-        <td>
-          <para style="P1">
-            <font color="white"> </font>
-          </para>
-        </td>
-        <td>
-          <para style="P2">Analytic Balance</para>
-        </td>
-        <td>
-          <para style="P3">
-            <font color="white"> </font>
-          </para>
-        </td>
-      </tr>
-      <tr>
-        <td>
-          <para style="P1">[[ company.name ]]</para>
-        </td>
-        <td>
-          <para style="P17">Period from [[ data['form']['date1'] ]] </para>
-          <para style="P17">to [[ data['form']['date2'] ]]</para>
-        </td>
-        <td>
-          <para style="P4">Currency: [[ company.currency_id.name ]]</para>
-        </td>
-      </tr>
-    </blockTable>
-    <para style="P10">
-      <font color="white"> </font>
-    </para>
-    <para style="P11">Printing date: [[ time.strftime('%Y-%m-%d') ]] at [[ time.strftime('%H:%M:%S') ]]</para>
-    <para style="P11">
-      <font color="white"> </font>
-    </para>
-    <blockTable colWidths="57.0,227.0,50.0,50.0,50.0,49.0" style="Tableau8">
-      <tr>
-        <td>
-          <para style="P5">Code</para>
-        </td>
-        <td>
-          <para style="P5">Account Name</para>
-        </td>
-        <td>
-          <para style="P5">Debit </para>
-        </td>
-        <td>
-          <para style="P5">Credit</para>
-        </td>
-        <td>
-          <para style="P5">Balance</para>
-        </td>
-        <td>
-          <para style="P5">Quantity</para>
-        </td>
-      </tr>
-    </blockTable>
-    <para style="P15">
-      <font color="white"> </font>
-    </para>
     <section>
-      <para style="P15">[[ repeatIn(objects,'o') ]]</para>
-      <blockTable colWidths="482.0" style="Table2">
-        <tr>
-          <td>
-            <para style="P6">[[ o.code ]] <font face="Times-Bold" size="9.0">[[ o.complete_name ]]</font></para>
-          </td>
-        </tr>
-      </blockTable>
-      <blockTable colWidths="57.0,227.0,50.0,50.0,49.0,50.0" style="Tableau2">
+      <blockTable colWidths="57.0,280.0,50.0,50.0,50.0,50.0" style="Table1" repeatRows="1">
         <tr>
           <td>
-            <para style="P7">[[ repeatIn(lines_g(o.id,data['form']['date1'],data['form']['date2']),'move_g') ]]</para>
-            <para style="P7">[[ move_g['code'] ]]</para>
+            <para style="terp_tblheader_Details">Code</para>
           </td>
           <td>
-            <para style="P7">[[ move_g['name'] ]]</para>
+            <para style="terp_tblheader_Details">Account Name</para>
           </td>
           <td>
-            <para style="P8">[[ '%.2f' % move_g['debit'] ]]</para>
+            <para style="terp_tblheader_Details_Right">Debit </para>
           </td>
           <td>
-            <para style="P8">[[ '%.2f' % move_g['credit'] ]]</para>
+            <para style="terp_tblheader_Details_Right">Credit</para>
           </td>
           <td>
-            <para style="P8">[[ '%.2f' % move_g['balance'] ]]</para>
+            <para style="terp_tblheader_Details_Right">Balance</para>
           </td>
           <td>
-            <para style="P8">[[ '%.2f' % (move_g['quantity'] or 0.0) ]]</para>
+            <para style="terp_tblheader_Details_Right">Quantity</para>
           </td>
         </tr>
-      </blockTable>
-      <blockTable colWidths="284.0,50.0,50.0,49.0,50.0" style="Table1">
+      
         <tr>
           <td>
-            <para style="P9">Total ([[ o.code ]])</para>
+            <para style="terp_tblheader_General">Total</para>
+          </td>
+          <td></td>
+          <td>
+            <para style="terp_tblheader_General_Right"><u>[[ sum_debit(objects,data['form']['date1'],data['form']['date2']) or 0.0 ]]</u></para>
           </td>
           <td>
-            <para style="P9">[[ '%.2f' % (move_sum_debit(o.id,data['form']['date1'],data['form']['date2']) or 0.0) ]]</para>
+            <para style="terp_tblheader_General_Right"><u>[[ sum_credit(objects,data['form']['date1'],data['form']['date2']) or 0.0 ]]</u></para>
           </td>
           <td>
-            <para style="P9">[[ '%.2f' % (move_sum_credit(o.id,data['form']['date1'],data['form']['date2']) or 0.0 )]]</para>
+            <para style="terp_tblheader_General_Right"><u>[[ sum_balance(objects,data['form']['date1'],data['form']['date2']) or 0.0 ]]</u></para>
           </td>
           <td>
-            <para style="P9">[[ '%.2f' % (move_sum_balance(o.id,data['form']['date1'],data['form']['date2']) or 0.0) ]]</para>
+            <para style="terp_tblheader_General_Right"><u>[[ sum_quantity(objects,data['form']['date1'],data['form']['date2']) or 0.0 ]]</u></para>
           </td>
+        </tr>
+            
+        <tr>
           <td>
-            <para style="P9">[[ '%.2f' % move_sum_quantity(o.id,data['form']['date1'],data['form']['date2']) or 0.0]]</para>
+            <para style="terp_default_8">[[ repeatIn(objects,'o') ]]</para>
+            <blockTable colWidths="51.0,280.0,50.0,50.0,50.0,50.0" style="tbl_data">
+              <tr>
+                <td>
+                  <para style="terp_default_8_bold">[[ o.code ]]</para>
+                </td>
+                <td>
+                  <para style="terp_default_8_bold">[[ o.complete_name ]]</para>
+                </td>
+                <td>
+                  <para style="terp_default_8_right_bold"><u>[[  move_sum_debit(o.id,data['form']['date1'],data['form']['date2']) or 0.0 ]]</u></para>
+                </td>
+                <td>
+                  <para style="terp_default_8_right_bold"><u>[[  move_sum_credit(o.id,data['form']['date1'],data['form']['date2']) or 0.0 ]]</u></para>
+                </td>
+                <td>
+                  <para style="terp_default_8_right_bold"><u>[[  move_sum_balance(o.id,data['form']['date1'],data['form']['date2']) or 0.0 ]]</u></para>
+                </td>
+                <td>
+                  <para style="terp_default_8_right_bold"><u>[[  move_sum_quantity(o.id,data['form']['date1'],data['form']['date2']) or 0.0 ]]</u></para>
+                </td>
+              </tr>
+              <tr>
+                <td>
+                  <para style="terp_default_8">[[ repeatIn(lines_g(o.id,data['form']['date1'],data['form']['date2']),'move_g') ]]</para>
+                  <para style="terp_default_8">[[ move_g['code'] ]]</para>
+                </td>
+                <td>
+                  <para style="terp_default_8">[[ move_g['name']  ]]</para>
+                </td>
+                <td>
+                  <para style="terp_default_Right_8">[[ move_g['debit'] ]]</para>
+                </td>
+                <td>
+                  <para style="terp_default_Right_8">[[ move_g['credit'] ]]</para>
+                </td>
+                <td>
+                  <para style="terp_default_Right_8">[[ move_g['balance'] ]]</para>
+                </td>
+                <td>
+                  <para style="terp_default_Right_8">[[ (move_g['quantity'] or 0.0) ]]</para>
+                </td>
+              </tr>
+            </blockTable>
+            <para style="terp_default_8">
+              <font color="white"> </font>
+            </para>
           </td>
         </tr>
       </blockTable>
-      <para style="P15">
+      <para style="terp_default_8">
         <font color="white"> </font>
       </para>
     </section>
-    <para style="P12">
-      <font color="white"> </font>
-    </para>
-    <blockTable colWidths="284.0,50.0,50.0,50.0,49.0" style="Tableau10">
-      <tr>
-        <td>
-          <para style="P3">Total</para>
-        </td>
-        <td>
-          <para style="P3">[[ '%.2f' % (sum_debit(objects,data['form']['date1'],data['form']['date2']) or 0.0) ]]</para>
-        </td>
-        <td>
-          <para style="P3">[[ '%.2f' % (sum_credit(objects,data['form']['date1'],data['form']['date2']) or 0.0) ]]</para>
-        </td>
-        <td>
-          <para style="P3">[[ '%.2f' % (sum_balance(objects,data['form']['date1'],data['form']['date2']) or 0.0)]]</para>
-        </td>
-        <td>
-          <para style="P3">[[ '%.2f' % sum_quantity(objects,data['form']['date1'],data['form']['date2']) or 0.0 ]]</para>
-        </td>
-      </tr>
-    </blockTable>
-    <para style="P13">
-      <font color="white"> </font>
-    </para>
-    <para style="P14">
-      <font color="white"> </font>
-    </para>
   </story>
-</document>
-
+</document>
\ No newline at end of file
index 5ff60c4..1ecb086 100644 (file)
@@ -71,7 +71,10 @@ class account_balance(report_sxw.rml_parse):
                 self.cr.execute("select name from account_period where id in (%s)" % (period_ids))
                 res=self.cr.fetchall()
                 for r in res:
-                    result+=r[0]+", "
+                    if (r == res[res.__len__()-1]):
+                        result+=r[0]+". "
+                    else:
+                        result+=r[0]+", "
             return str(result and result[:-1]) or ''
     
         def lines(self, form, ids={}, done=None, level=1):
@@ -118,6 +121,7 @@ class account_balance(report_sxw.rml_parse):
                         'credit': account.credit,
                         'balance': account.balance,
                         'leef': not bool(account.child_id),
+                        'bal_type':'',
                     }
                 self.sum_debit += account.debit
                 self.sum_credit += account.credit
@@ -177,6 +181,10 @@ class account_balance(report_sxw.rml_parse):
                 r['credit']=''
                 r['balance']=''
                 r['leef']=''
+                if sum > 0.0:
+                    r['bal_type']=" Dr."
+                else:
+                    r['bal_type']=" Cr."
             return res or ''
         
         def date_range(self,start,end):
index 462a7bd..0b61410 100644 (file)
       <blockLeftPadding length="0" start="0,0" stop="-1,0"/>
     </blockTableStyle>
     <blockTableStyle id="TrLevel4">
-      <lineStyle kind="LINEBELOW" colorName="#777777" start="1,0" stop="1,0"/>
-      <blockLeftPadding length="0" start="0,0" stop="-1,0"/>
+     <blockLeftPadding length="0" start="0,0" stop="-1,0"/>
     </blockTableStyle>
     <blockTableStyle id="TrLevel3">
-      <lineStyle kind="LINEBELOW" colorName="#777777" start="1,0" stop="-1,0"/>
-      <blockLeftPadding length="0" start="0,0" stop="1,0"/>
+     <lineStyle kind="LINEBELOW" colorName="#777777" start="1,0" stop="1,0"/>
+      <blockLeftPadding length="0" start="0,0" stop="-1,0"/>
     </blockTableStyle>
     <blockTableStyle id="TrLevel2">
-      <lineStyle kind="LINEBELOW" colorName="#000000" start="0,0" stop="-1,0"/>
+      <lineStyle kind="LINEBELOW" colorName="#777777" start="1,0" stop="-1,0"/>
       <blockLeftPadding length="0" start="0,0" stop="1,0"/>
     </blockTableStyle>
        <blockTableStyle id="TrLevel1">
@@ -94,7 +93,7 @@
                fontSize="8.0" />
     <paraStyle
                name="Level3" 
-               fontName="Helvetica-Bold" 
+               fontName="Helvetica" 
                fontSize="8.0" />
     <paraStyle name="Level2"
                fontSize="8.0"
                                        <para style="P14">[[ setTag('para','para',{'style':('Level'+str(a['level']))}) ]]<font color="white">[[ (a['level']&lt;6 and removeParentNode('font') or '... '*(a['level']-4)) ]]</font>[[ setTag('blockTable','blockTable',{'style':'TrLevel'+str(a['level'])}) ]][[ a['name'] ]]</para>
                        </td>
                        <td>
-                         <para style="P3">[[ formatLang(a['debit']) and '%.2f'%a['debit'] or '']]</para>
+                         <para style="P3">[[ (a['level']&lt;4) and setTag('para','para',{'style':'P3'}) ]]<u>[[ (a['leef'] and removeParentNode('para')) or formatLang(a['debit']) and '%.2f'%a['debit'] or '0.00' ]]</u></para>
+                                 <para style="P3">[[ ((not a['leef']) and removeParentNode('para')) or formatLang(a['debit']) and '%.2f'%a['debit'] or '0.00' ]]</para>
                        </td>
                        <td>
-                         <para style="P3">[[ formatLang(a['credit']) and '%.2f'%a['credit'] or '']]</para>
+                         <para style="P3">[[ (a['level']&lt;4) and setTag('para','para',{'style':'P3'}) ]]<u>[[ (a['leef'] and removeParentNode('para')) or formatLang(a['credit']) and '%.2f'%a['credit'] or '0.00' ]]</u></para>
+                                 <para style="P3">[[ ((not a['leef']) and removeParentNode('para')) or formatLang(a['credit']) and '%.2f'%a['credit'] or '0.00' ]]</para>
                        </td>
                        <td>
-                               <para style="P3">[[ (a['level']&lt;4) and setTag('para','para',{'style':'P3a'}) ]]<u>[[ (a['leef'] and removeParentNode('para')) or formatLang(a['balance']) and '%.2f'%a['balance'] or '' ]]</u></para>
-                               <para style="P3">[[ ((not a['leef']) and removeParentNode('para')) or formatLang(a['balance']) and formatLang(a['balance']) or '' ]]</para>
+                               <para style="P3">[[ (a['level']&lt;4) and setTag('para','para',{'style':'P3a'}) ]]<u>[[ (a['leef'] and removeParentNode('para')) or formatLang(a['balance']) and '%.2f'%a['balance'] or '0.00' ]]</u></para>
+                               <para style="P3">[[ ((not a['leef']) and removeParentNode('para')) or formatLang(a['balance']) and formatLang(a['balance']) or '0.00' ]]</para>
                        </td>
                      </tr>
                      <tr>
                                <para style="P14"><font color="white">[[ '... '*(a['level']-3) ]]</font>[[ a['lname'] ]]</para>
                        </td>
                        <td>
-                         <para style="P3">[[ formatLang(a['debit1']) and '%.2f'%a['debit1'] or '']]</para>
+                         <para style="P3">[[ formatLang(a['debit1']) and '%.2f'%a['debit1'] or '0.00']]</para>
                        </td>
                        <td>
-                         <para style="P3">[[ formatLang(a['credit1']) and '%.2f'%a['credit1'] or '']]</para>
+                         <para style="P3">[[ formatLang(a['credit1']) and '%.2f'%a['credit1'] or '0.00']]</para>
                        </td>
                        <td>
-                               <para style="P3">[[ formatLang(a['balance1']) and '%.2f'%a['balance1'] or '']]</para>
+                               <para style="P3">[[ formatLang(a['balance1']) and '%.2f'%a['balance1'] or '0.00' ]]</para>
                        </td>           
                      </tr>
                 </blockTable>
index 912e839..e731335 100644 (file)
@@ -1,9 +1,6 @@
-# -*- encoding: utf-8 -*-
 ##############################################################################
 #
-# Copyright (c) 2004-2008 TINY SPRL. (http://tiny.be) All Rights Reserved.
-#
-# $Id$
+# Copyright (c) 2005-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
 #
 # WARNING: This program as such is intended to be used by professional
 # programmers who take the whole responsability of assessing all potential
 
 import pooler
 import time
+import re
+import datetime
 from report import report_sxw
 
 class partner_balance(report_sxw.rml_parse):
     def __init__(self, cr, uid, name, context):
         super(partner_balance, self).__init__(cr, uid, name, context)
+        self.date_lst = []
+        self.date_lst_string = ''
         self.localcontext.update( {
             'time': time,
             'lines': self.lines,
@@ -47,44 +48,138 @@ class partner_balance(report_sxw.rml_parse):
             'solde_credit': self._solde_balance_credit,
             'get_company': self._get_company,
             'get_currency': self._get_currency,
+            'comma_me' : self.comma_me,
         })
-
+        ## Compute account list one time
+    #
+    # Date Management
+    #
+    def date_range(self,start,end):
+        start = datetime.date.fromtimestamp(time.mktime(time.strptime(start,"%Y-%m-%d")))
+        end = datetime.date.fromtimestamp(time.mktime(time.strptime(end,"%Y-%m-%d")))
+        full_str_date = []
+    #
+        r = (end+datetime.timedelta(days=1)-start).days
+    #
+        date_array = [start+datetime.timedelta(days=i) for i in range(r)]
+        for date in date_array:
+            full_str_date.append(str(date))
+        return full_str_date
+        
+    #
+    def transform_period_into_date_array(self,data):
+        ## Get All Period Date
+        #
+        # If we have no period we will take all perdio in the FiscalYear.
+        if not data['form']['periods'][0][2] :
+            periods_id =  self.pool.get('account.period').search(self.cr, self.uid, [('fiscalyear_id','=',data['form']['fiscalyear'])])
+        else:
+            periods_id = data['form']['periods'][0][2]
+        date_array = [] 
+        for period_id in periods_id:
+            period_obj = self.pool.get('account.period').browse(self.cr, self.uid, period_id)
+            date_array = date_array + self.date_range(period_obj.date_start,period_obj.date_stop)
+            
+        self.date_lst = date_array
+        self.date_lst.sort()
+        
+            
+    def transform_date_into_date_array(self,data):
+        return_array = self.date_range(data['form']['date1'],data['form']['date2'])
+        self.date_lst = return_array
+        self.date_lst.sort()
+    
+    
+    
+    def comma_me(self,amount):
+        if  type(amount) is float :
+            amount = str('%.2f'%amount)
+        else :
+            amount = str(amount)
+        if (amount == '0'):
+             return ' '
+        orig = amount
+        new = re.sub("^(-?\d+)(\d{3})", "\g<1>'\g<2>", amount)
+        if orig == new:
+            return new
+        else:
+            return self.comma_me(new)
+        
     def preprocess(self, objects, data, ids):
+        # Transformation des date
+        #
+        #
+        if data['form'].has_key('fiscalyear'): 
+            self.transform_period_into_date_array(data)
+        else:
+            self.transform_date_into_date_array(data)
+        ##
+        self.date_lst_string = '\'' + '\',\''.join(map(str,self.date_lst)) + '\''
+        ## Compute Code
         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 account.active',
-                    (data['form']['date1'], data['form']['date2'],
-                        data['form']['company_id']))
-        new_ids = [id for (id,) in self.cr.fetchall()]
+        #
+        if (data['form']['result_selection'] == 'customer' ):
+            self.ACCOUNT_TYPE = "('receivable')"
+        elif (data['form']['result_selection'] == 'supplier'):
+            self.ACCOUNT_TYPE = "('payable')"
+        else:
+            self.ACCOUNT_TYPE = "('payable','receivable')"
+        #
         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.type IN ' + self.ACCOUNT_TYPE + " " \
                     '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(partner_balance, self).preprocess(objects, data, new_ids)
+        
+        super(partner_balance, self).preprocess(objects, data, ids)
+
+    def lines(self,data):
 
-    def lines(self):
-        if not self.partner_ids:
-            return []
         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'],'state':self.datas['form']['state']})
+        full_account = []
+        result_tmp = 0.0
+
+        #
+        #
+        #
+        if data['form']['soldeinit'] :
+            self.cr.execute(
+                "SELECT p.ref, p.name,l.account_id,ac.name as account_name,ac.code as code , sum(debit) as debit, sum(credit) as credit, " \
+                        "CASE WHEN sum(debit) > sum(credit) " \
+                            "THEN sum(debit) - sum(credit) " \
+                            "ELSE 0 " \
+                        "END AS sdebit, " \
+                        "CASE WHEN sum(debit) < sum(credit) " \
+                            "THEN sum(credit) - sum(debit) " \
+                            "ELSE 0 " \
+                        "END AS scredit, " \
+                        "(SELECT sum(debit-credit) " \
+                            "FROM account_move_line l " \
+                            "WHERE partner_id = p.id " \
+                                "AND date < %s " \
+                                "AND blocked = TRUE AND l.reconcile_id IS NULL " \
+                        ") AS enlitige " \
+                "FROM account_move_line l LEFT JOIN res_partner p ON (l.partner_id=p.id) " \
+                "JOIN account_account ac ON (l.account_id = ac.id)" \
+                "WHERE " \
+#                    " account_id IN (" + self.account_ids + ") " \
+                    "l.date < %s  AND l.reconcile_id IS NULL " \
+                "GROUP BY p.id, p.ref, p.name,l.account_id,ac.name,ac.code " \
+                "ORDER BY l.account_id,p.name",
+                (self.date_lst[0],self.date_lst[0]))
+            res = self.cr.dictfetchall()
+            
+            for r in res:
+                full_account.append(r)
+        #
+        #
+        #
         self.cr.execute(
-            "SELECT p.ref, p.name, sum(debit) as debit, sum(credit) as credit, " \
+            "SELECT p.ref,l.account_id,ac.name as account_name,ac.code as code ,p.name, sum(debit) as debit, sum(credit) as credit, " \
                     "CASE WHEN sum(debit) > sum(credit) " \
                         "THEN sum(debit) - sum(credit) " \
                         "ELSE 0 " \
@@ -96,129 +191,315 @@ class partner_balance(report_sxw.rml_parse):
                     "(SELECT sum(debit-credit) " \
                         "FROM account_move_line l " \
                         "WHERE partner_id = p.id " \
-                            "AND date >= %s " \
-                            "AND date <= %s " \
+                            "AND l.date IN (" + self.date_lst_string + ") " \
                             "AND blocked = TRUE " \
-                            "AND " + line_query + " " \
                     ") AS enlitige " \
             "FROM account_move_line l LEFT JOIN res_partner p ON (l.partner_id=p.id) " \
-            "WHERE partner_id IN (" + self.partner_ids + ") " \
-                "AND account_id IN (" + self.account_ids + ") " \
-                "AND l.date >= %s " \
-                "AND l.date <= %s " \
-                "AND " + line_query + " " \
-            "GROUP BY p.id, p.ref, p.name " \
-            "ORDER BY p.ref, p.name",
-            (self.datas['form']['date1'], self.datas['form']['date2'],
-                self.datas['form']['date1'], self.datas['form']['date2']))
+            "JOIN account_account ac ON (l.account_id = ac.id)" \
+            "WHERE  " \
+#                " account_id IN (" + self.account_ids + ") " \
+                " l.date IN (" + self.date_lst_string + ") " \
+            "GROUP BY p.id, p.ref, p.name,l.account_id,ac.name,ac.code " \
+            "ORDER BY l.account_id,p.name")
         res = self.cr.dictfetchall()
-        return res
+        print"=====res=====",res
+        for r in res:
+            full_account.append(r)
+        
+        ## We will now compute Total
+        return self._add_subtotal(full_account)
 
-    def _sum_debit(self):
+    def _add_subtotal(self,cleanarray):
+        i=0
+        completearray = []
+        tot_debit = 0.0
+        tot_credit = 0.0
+        tot_scredit = 0.0
+        tot_sdebit = 0.0
+        tot_enlitige = 0.0
+        for r in cleanarray:
+            # For the first element we always add the line
+            # type = 1 is the line is the first of the account
+            # type = 2 is an other line of the account
+            if i==0:
+                # We add the first as the header
+                #
+                ##
+                new_header = {}
+                new_header['ref'] = ''
+                new_header['name'] = r['account_name']
+                new_header['code'] = r['code']
+                new_header['debit'] = 0
+                new_header['credit'] = 0
+                new_header['scredit'] = 0
+                new_header['sdebit'] = 0
+                new_header['enlitige'] = 0
+                new_header['balance'] = 0
+                new_header['type'] = 3
+                ##
+                completearray.append(new_header)
+                #
+                r['type'] = 1
+                r['balance'] = float(r['sdebit']) - float(r['scredit'])
+                completearray.append(r)
+                #
+                tot_debit = r['debit']
+                tot_credit = r['credit']
+                tot_scredit = r['scredit']
+                tot_sdebit = r['sdebit']
+                tot_enlitige = (r['enlitige'] or 0.0)
+                #
+            else:
+                if cleanarray[i]['account_id'] <> cleanarray[i-1]['account_id']:
+                    ##
+                    new_tot = {}
+                    new_tot['ref'] = 'Total'
+                    new_tot['name'] = cleanarray[i-1]['account_name']
+                    new_tot['code'] = cleanarray[i-1]['code']
+                    
+                    new_tot['debit'] = tot_debit
+                    new_tot['credit'] = tot_credit
+                    new_tot['scredit'] = tot_scredit
+                    new_tot['sdebit'] = tot_sdebit
+                    new_tot['enlitige'] = tot_enlitige
+                    new_tot['balance'] = float(tot_sdebit) - float(tot_scredit)
+                    new_tot['type'] = 3
+                    ##
+                    completearray.append(new_tot)
+                    
+                    # we reset the counter 
+                    tot_debit = r['debit']
+                    tot_credit = r['credit']
+                    tot_scredit = r['scredit']
+                    tot_sdebit = r['sdebit']
+                    tot_enlitige = (r['enlitige'] or 0.0)
+                    #
+                    ##
+                    new_header = {}
+                    new_header['ref'] = ''
+                    new_header['name'] = r['account_name']
+                    new_header['code'] = r['code']
+                    new_header['debit'] = 0
+                    new_header['credit'] = 0
+                    new_header['scredit'] = 0
+                    new_header['sdebit'] = 0
+                    new_header['enlitige'] = 0
+                    new_header['balance'] = 0
+                    new_header['type'] = 3
+                    ##
+                    ##
+                    completearray.append(new_header)
+                    ##    
+                    #
+                    r['type'] = 1
+                    #
+                    r['balance'] = float(r['sdebit']) - float(r['scredit'])
+                    #
+                    completearray.append(r)
+                if cleanarray[i]['account_id'] == cleanarray[i-1]['account_id']:
+                    # we reset the counter 
+                    tot_debit = tot_debit + r['debit']
+                    tot_credit = tot_credit + r['credit']
+                    tot_scredit = tot_scredit + r['scredit']
+                    tot_sdebit = tot_sdebit + r['sdebit']
+                    tot_enlitige = tot_enlitige + (r['enlitige'] or 0.0)
+                    #
+                    r['type'] = 2
+                    #
+                    r['balance'] = float(r['sdebit']) - float(r['scredit'])
+                    #
+                    completearray.append(r)
+            i = i + 1
+        return completearray
+
+
+    def _sum_debit(self,data):
         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'],'state':self.datas['form']['state']})
+        result_tmp = 0.0
+        #
+        #
+        if data['form']['soldeinit'] :
+            self.cr.execute(
+                    'SELECT sum(debit) ' \
+                    'FROM account_move_line AS l ' \
+                    'WHERE  ' \
+#                        ' account_id IN (' + self.account_ids + ') ' \
+                        ' l.reconcile_id IS NULL ' \
+                        'AND date < %s ',
+                    (self.date_lst[0],))
+            result_tmp = float(self.cr.fetchone()[0] or 0.0)
+        #
+        #
         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
+                'FROM account_move_line AS l ' \
+                'WHERE  ' \
+#                    ' account_id IN (' + self.account_ids + ') ' \
+                    ' l.date IN (' + self.date_lst_string + ') ' )
+        result_tmp = result_tmp + float(self.cr.fetchone()[0] or 0.0)
+        
+        return result_tmp
 
-    def _sum_credit(self):
+    def _sum_credit(self,data):
         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'],'state':self.datas['form']['state']})
+        
+        result_tmp = 0.0
+        #
+        #
+        if data['form']['soldeinit'] :
+            self.cr.execute(
+                    'SELECT sum(credit) ' \
+                    'FROM account_move_line AS l ' \
+                    'WHERE  ' \
+#                        '  account_id IN (' + self.account_ids + ') ' \
+                        ' l.reconcile_id IS NULL ' \
+                        'AND date < %s ' ,
+                (self.date_lst[0],))
+            result_tmp = float(self.cr.fetchone()[0] or 0.0)
+        #
+        #
         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
+                'FROM account_move_line AS l ' \
+                'WHERE  ' \
+#                    ' account_id IN (' + self.account_ids + ') ' \
+                    ' l.date IN (' + self.date_lst_string + ') ' )
+                
+        result_tmp = result_tmp + float(self.cr.fetchone()[0] or 0.0)
+        
+        return result_tmp
 
-    def _sum_litige(self):
+    def _sum_litige(self,data):
         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'],'state':self.datas['form']['state']})
+        result_tmp = 0.0
+        
+        #
+        #
+        if data['form']['soldeinit'] :
+            self.cr.execute(
+                    'SELECT sum(debit-credit) ' \
+                    'FROM account_move_line AS l ' \
+                    'WHERE  ' \
+#                        '  account_id IN (' + self.account_ids + ') ' \
+                        ' l.reconcile_id IS NULL ' \
+                        'AND date < %s ' \
+                        'AND blocked=TRUE ' ,
+                (self.date_lst[0],))
+            result_tmp = float(self.cr.fetchone()[0] or 0.0)
+        #
+        #
         self.cr.execute(
                 'SELECT sum(debit-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 blocked=TRUE ' \
-                    'AND ' + line_query,
-                (self.datas['form']['date1'], self.datas['form']['date2']))
-        return self.cr.fetchone()[0] or 0.0
+                'FROM account_move_line AS l ' \
+                'WHERE  ' \
+#                    '  account_id IN (' + self.account_ids + ') ' \
+                    ' l.date IN (' + self.date_lst_string + ') ' \
+                    'AND blocked=TRUE ' )
+        result_tmp = result_tmp + float(self.cr.fetchone()[0] or 0.0)
+        
+        return result_tmp
 
-    def _sum_sdebit(self):
+    def _sum_sdebit(self,data):
         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'],'state':self.datas['form']['state']})
+        result_tmp = 0.0
+        
+        #
+        #
+        if data['form']['soldeinit'] :
+            self.cr.execute(
+                'SELECT CASE WHEN sum(debit) > sum(credit) ' \
+                        'THEN sum(debit) - sum(credit) ' \
+                        'ELSE 0 ' \
+                    'END ' \
+                'FROM account_move_line AS l  ' \
+                'WHERE  ' \
+#                    '  account_id IN (' + self.account_ids + ') ' \
+                    ' date < %s ' \
+                    'AND reconcile_id IS NULL ' \
+                'GROUP BY partner_id',
+                (self.date_lst[0],))
+            
+            if self.cr.fetchone() != None:
+                result_tmp = float(self.cr.fetchone()[0])
+            else:
+                result_tmp = 0.0
+        #
+        #
         self.cr.execute(
             'SELECT CASE WHEN sum(debit) > sum(credit) ' \
-                    'THEN sum(debit - credit) ' \
+                    'THEN sum(debit) - sum(credit) ' \
                     'ELSE 0 ' \
                 'END ' \
-            '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 + ' ' \
-            'GROUP BY partner_id',
-            (self.datas['form']['date1'], self.datas['form']['date2']))
-        return self.cr.fetchone()[0] or 0.0
+            'FROM account_move_line AS l ' \
+            'WHERE  ' \
+#                '  account_id IN (' + self.account_ids + ') ' \
+                'l.date IN (' + self.date_lst_string + ') ' \
+            'GROUP BY partner_id')
+        
+        if self.cr.fetchone() != None:
+            result_tmp = result_tmp + float(self.cr.fetchone()[0] or 0.0)
+        else:
+            result_tmp = 0.0
+        return result_tmp        
 
-    def _sum_scredit(self):
+    def _sum_scredit(self,data):
         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'],'state':self.datas['form']['state']})
+        result_tmp = 0.0
+        #
+        #
+        if data['form']['soldeinit'] :
+            self.cr.execute(
+                'SELECT CASE WHEN sum(debit) < sum(credit) ' \
+                        'THEN sum(credit) - sum(debit) ' \
+                        'ELSE 0 ' \
+                    'END ' \
+                'FROM account_move_line AS l ' \
+                'WHERE  ' \
+#                    ' account_id IN (' + self.account_ids + ') ' \
+                    ' date <= %s ' \
+                    'AND l.reconcile_id IS NULL ' \
+                'GROUP BY partner_id',
+                (self.date_lst[0],))
+            if self.cr.fetchone() != None:
+                result_tmp = float(self.cr.fetchone()[0])
+            else:
+                result_tmp = 0.0
+        #
+        #
         self.cr.execute(
             'SELECT CASE WHEN sum(debit) < sum(credit) ' \
-                    'THEN sum(credit - debit) ' \
+                    'THEN sum(credit) - sum(debit) ' \
                     'ELSE 0 ' \
                 'END ' \
-            '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 + ' ' \
-            'GROUP BY partner_id',
-            (self.datas['form']['date1'], self.datas['form']['date2']))
-        return self.cr.fetchone()[0] or 0.0
-
-    def _solde_balance_debit(self):
-        debit, credit = self._sum_debit(), self._sum_credit()
+            'FROM account_move_line AS l ' \
+            'WHERE   ' \
+#                ' account_id IN (' + self.account_ids + ') ' \
+                'l.date IN (' + self.date_lst_string + ') ' \
+            'GROUP BY partner_id')
+        
+        if self.cr.fetchone() != None:
+            result_tmp = result_tmp + float(self.cr.fetchone()[0] or 0.0)
+        else:
+            result_tmp = 0.0
+        
+        return result_tmp
+    
+    def _solde_balance_debit(self,data):
+        debit, credit = self._sum_debit(data), self._sum_credit(data)
         return debit > credit and debit - credit
         
-    def _solde_balance_credit(self):
-        debit, credit = self._sum_debit(), self._sum_credit()
+    def _solde_balance_credit(self,data):
+        debit, credit = self._sum_debit(data), self._sum_credit(data)
         return credit > debit and credit - debit
 
     def _get_company(self, form):
@@ -228,9 +509,5 @@ class partner_balance(report_sxw.rml_parse):
         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.account.partner.balance', 'res.partner',
-    'addons/account/report/partner_balance.rml',parser=partner_balance,
+    'account/report/partner_balance.rml',parser=partner_balance,
     header=False)
-
-
-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
-
index c0d9ea6..5e99323 100644 (file)
@@ -1,8 +1,37 @@
 <?xml version="1.0"?>
-<document filename="test.pdf">
+<document filename="HipHop.pdf">
   <template pageSize="(595.0,842.0)" title="Test" author="Martin Simon" allowSplitting="20">
     <pageTemplate id="first">
       <frame id="first" x1="57.0" y1="57.0" width="481" height="728"/>
+                       <pageGraphics>
+                               <!--logo-->
+                               <!--<fill color="darkblue"/>-->
+                               <!--<stroke color="darkblue"/>-->
+
+                               <!--TITLE COMPANY-->
+                               <!-- <drawString x="4.6cm" y="28.7cm">[[ company.partner_id.name ]]</drawString> -->
+
+                               <setFont name="Helvetica-Bold" size="9"/>
+
+
+                               <!--COL 1-->
+                               <drawString x="1.0cm" y="28.1cm">[[ company.name ]]</drawString>
+                               <drawString x="12.7cm" y="28.1cm">Third Party Balance [[ data['form']['result_selection'] == 'customer' and '/ Débiteur' ]] [[ data['form']['result_selection'] == 'supplier' and '/ Créancier' ]] [[ data['form']['result_selection'] == 'all' and '/ Créancier et Débiteur' ]] - [[ get_currency(data['form']) ]]</drawString>
+                               
+                               <!-- Header -->
+                               
+                               
+                               <setFont name="Helvetica" size="9"/>
+                               <drawString x="1.0cm" y="1cm"> [[ time.strftime("%m-%d-%y %H:%M", time.localtime()) ]]</drawString>
+                               <drawString x="19.0cm" y="1cm">Page <pageNumber/></drawString>
+
+                               <!--<drawRightString x="19.8cm" y="28cm">[[ company.rml_header1 ]]</drawRightString>-->
+                               
+
+                           <lineMode width="0.7"/>
+                               <lines>1cm 27.7cm 20cm 27.7cm</lines>
+                               <setFont name="Helvetica" size="8"/>
+                       </pageGraphics>                  
     </pageTemplate>
   </template>
   <stylesheet>
     <blockTableStyle id="Table1">
       <blockAlignment value="LEFT"/>
       <blockValign value="TOP"/>
-      <blockBackground colorName="#e6e6e6" start="0,0" stop="0,-1"/>
-      <blockBackground colorName="#e6e6e6" start="1,0" stop="1,-1"/>
-      <blockBackground colorName="#e6e6e6" start="2,0" stop="2,-1"/>
-      <blockBackground colorName="#e6e6e6" start="0,1" stop="0,-1"/>
-      <blockBackground colorName="#e6e6e6" start="1,1" stop="1,-1"/>
-      <blockBackground colorName="#e6e6e6" start="2,1" stop="2,-1"/>
+      <blockBackground colorName="#e6e6e6" start="0,0" stop="0,0"/>
+      <blockBackground colorName="#e6e6e6" start="1,0" stop="1,0"/>
+      <blockBackground colorName="#e6e6e6" start="2,0" stop="2,0"/>
+      <blockBackground colorName="#e6e6e6" start="0,1" stop="0,1"/>
+      <blockBackground colorName="#e6e6e6" start="1,1" stop="1,1"/>
+      <blockBackground colorName="#e6e6e6" start="2,1" stop="2,1"/>
     </blockTableStyle>
     <blockTableStyle id="Table6">
       <blockAlignment value="LEFT"/>
       <blockValign value="TOP"/>
-      <lineStyle kind="LINEBEFORE" colorName="#000000" start="0,0" stop="0,-1"/>
-      <lineStyle kind="LINEABOVE" colorName="#000000" start="0,0" stop="0,0"/>
-      <lineStyle kind="LINEBELOW" colorName="#000000" start="0,-1" stop="0,-1"/>
-      <lineStyle kind="LINEBEFORE" colorName="#000000" start="1,0" stop="1,-1"/>
-      <lineStyle kind="LINEABOVE" colorName="#000000" start="1,0" stop="1,0"/>
-      <lineStyle kind="LINEBELOW" colorName="#000000" start="1,-1" stop="1,-1"/>
-      <lineStyle kind="LINEBEFORE" colorName="#000000" start="2,0" stop="2,-1"/>
-      <lineStyle kind="LINEABOVE" colorName="#000000" start="2,0" stop="2,0"/>
-      <lineStyle kind="LINEBELOW" colorName="#000000" start="2,-1" stop="2,-1"/>
-      <lineStyle kind="LINEBEFORE" colorName="#000000" start="3,0" stop="3,-1"/>
-      <lineStyle kind="LINEABOVE" colorName="#000000" start="3,0" stop="3,0"/>
-      <lineStyle kind="LINEBELOW" colorName="#000000" start="3,-1" stop="3,-1"/>
-      <lineStyle kind="LINEBEFORE" colorName="#000000" start="4,0" stop="4,-1"/>
-      <lineStyle kind="LINEAFTER" colorName="#000000" start="4,0" stop="4,-1"/>
-      <lineStyle kind="LINEABOVE" colorName="#000000" start="4,0" stop="4,0"/>
-      <lineStyle kind="LINEBELOW" colorName="#000000" start="4,-1" stop="4,-1"/>
+      <lineStyle kind="GRID" colorName="black"/>
     </blockTableStyle>
     <blockTableStyle id="Table2">
-      <blockAlignment value="LEFT"/>
+      <lineStyle kind="LINEBELOW" colorName="#000000" start="0,0" stop="-1,0"/>
+      <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,1" stop="-1,-1"/>
+      
       <blockValign value="TOP"/>
-      <lineStyle kind="LINEBEFORE" colorName="#000000" start="0,0" stop="0,-1"/>
-      <lineStyle kind="LINEABOVE" colorName="#000000" start="0,0" stop="0,0"/>
-      <lineStyle kind="LINEBELOW" colorName="#000000" start="0,-1" stop="0,-1"/>
-      <lineStyle kind="LINEBEFORE" colorName="#000000" start="1,0" stop="1,-1"/>
-      <lineStyle kind="LINEABOVE" colorName="#000000" start="1,0" stop="1,0"/>
-      <lineStyle kind="LINEBELOW" colorName="#000000" start="1,-1" stop="1,-1"/>
-      <lineStyle kind="LINEBEFORE" colorName="#000000" start="2,0" stop="2,-1"/>
-      <lineStyle kind="LINEABOVE" colorName="#000000" start="2,0" stop="2,0"/>
-      <lineStyle kind="LINEBELOW" colorName="#000000" start="2,-1" stop="2,-1"/>
-      <lineStyle kind="LINEBEFORE" colorName="#000000" start="3,0" stop="3,-1"/>
-      <lineStyle kind="LINEABOVE" colorName="#000000" start="3,0" stop="3,0"/>
-      <lineStyle kind="LINEBELOW" colorName="#000000" start="3,-1" stop="3,-1"/>
-      <lineStyle kind="LINEBEFORE" colorName="#000000" start="4,0" stop="4,-1"/>
-      <lineStyle kind="LINEABOVE" colorName="#000000" start="4,0" stop="4,0"/>
-      <lineStyle kind="LINEBELOW" colorName="#000000" start="4,-1" stop="4,-1"/>
-      <lineStyle kind="LINEBEFORE" colorName="#000000" start="5,0" stop="5,-1"/>
-      <lineStyle kind="LINEAFTER" colorName="#000000" start="5,0" stop="5,-1"/>
-      <lineStyle kind="LINEABOVE" colorName="#000000" start="5,0" stop="5,0"/>
-      <lineStyle kind="LINEBELOW" colorName="#000000" start="5,-1" stop="5,-1"/>
+      <blockAlignment value="RIGHT" start="2,1" stop="-1,-1"/>
     </blockTableStyle>
     <blockTableStyle id="Table3">
       <blockAlignment value="LEFT"/>
     <blockTableStyle id="Table4">
       <blockAlignment value="LEFT"/>
       <blockValign value="TOP"/>
-      <lineStyle kind="LINEBEFORE" colorName="#000000" start="0,0" stop="0,-1"/>
-      <lineStyle kind="LINEABOVE" colorName="#000000" start="0,0" stop="0,0"/>
-      <lineStyle kind="LINEBELOW" colorName="#000000" start="0,-1" stop="0,-1"/>
-      <lineStyle kind="LINEBEFORE" colorName="#000000" start="1,0" stop="1,-1"/>
-      <lineStyle kind="LINEABOVE" colorName="#000000" start="1,0" stop="1,0"/>
-      <lineStyle kind="LINEBELOW" colorName="#000000" start="1,-1" stop="1,-1"/>
-      <lineStyle kind="LINEBEFORE" colorName="#000000" start="2,0" stop="2,-1"/>
-      <lineStyle kind="LINEABOVE" colorName="#000000" start="2,0" stop="2,0"/>
-      <lineStyle kind="LINEBELOW" colorName="#000000" start="2,-1" stop="2,-1"/>
-      <lineStyle kind="LINEBEFORE" colorName="#000000" start="3,0" stop="3,-1"/>
-      <lineStyle kind="LINEABOVE" colorName="#000000" start="3,0" stop="3,0"/>
-      <lineStyle kind="LINEBELOW" colorName="#000000" start="3,-1" stop="3,-1"/>
-      <lineStyle kind="LINEBEFORE" colorName="#000000" start="4,0" stop="4,-1"/>
-      <lineStyle kind="LINEABOVE" colorName="#000000" start="4,0" stop="4,0"/>
-      <lineStyle kind="LINEBELOW" colorName="#000000" start="4,-1" stop="4,-1"/>
-      <lineStyle kind="LINEBEFORE" colorName="#000000" start="5,0" stop="5,-1"/>
-      <lineStyle kind="LINEAFTER" colorName="#000000" start="5,0" stop="5,-1"/>
-      <lineStyle kind="LINEABOVE" colorName="#000000" start="5,0" stop="5,0"/>
-      <lineStyle kind="LINEBELOW" colorName="#000000" start="5,-1" stop="5,-1"/>
-      <lineStyle kind="LINEBEFORE" colorName="#000000" start="0,1" stop="0,-1"/>
-      <lineStyle kind="LINEBELOW" colorName="#000000" start="0,-1" stop="0,-1"/>
-      <lineStyle kind="LINEBEFORE" colorName="#000000" start="1,1" stop="1,-1"/>
-      <lineStyle kind="LINEBELOW" colorName="#000000" start="1,-1" stop="1,-1"/>
-      <lineStyle kind="LINEBEFORE" colorName="#000000" start="2,1" stop="2,-1"/>
-      <lineStyle kind="LINEBELOW" colorName="#000000" start="2,-1" stop="2,-1"/>
-      <lineStyle kind="LINEBEFORE" colorName="#000000" start="3,1" stop="3,-1"/>
-      <lineStyle kind="LINEBELOW" colorName="#000000" start="3,-1" stop="3,-1"/>
-      <lineStyle kind="LINEBEFORE" colorName="#000000" start="4,1" stop="4,-1"/>
-      <lineStyle kind="LINEBELOW" colorName="#000000" start="4,-1" stop="4,-1"/>
-      <lineStyle kind="LINEBEFORE" colorName="#000000" start="5,1" stop="5,-1"/>
-      <lineStyle kind="LINEAFTER" colorName="#000000" start="5,1" stop="5,-1"/>
-      <lineStyle kind="LINEBELOW" colorName="#000000" start="5,-1" stop="5,-1"/>
+      <lineStyle kind="GRID" colorName="black"/>
     </blockTableStyle>
+   <blockTableStyle id="Tableau3">
+      <blockAlignment value="LEFT"/>
+      <blockValign value="TOP"/>
+      <lineStyle kind="LINEBELOW" colorName="#e6e6e6" />
+      <lineStyle kind="OUTLINE" colorName="#e6e6e6" />
+      <blockBackground colorName="white" start="0,0" stop="-1,0"/>
+    </blockTableStyle>    
     <initialize>
       <paraStyle name="all" alignment="justify"/>
     </initialize>
-    <paraStyle name="P1" fontName="Times-Roman" fontSize="20.0" leading="25" alignment="CENTER" spaceBefore="0.0" spaceAfter="6.0"/>
-    <paraStyle name="P2" fontName="Times-Roman" fontSize="10.0" leading="13" alignment="RIGHT" spaceBefore="0.0" spaceAfter="6.0"/>
-    <paraStyle name="P3" fontName="Times-Roman" fontSize="8.0" leading="10" alignment="LEFT" spaceBefore="0.0" spaceAfter="6.0"/>
-    <paraStyle name="P4" fontName="Times-Roman" fontSize="8.0" leading="10" alignment="RIGHT" spaceBefore="0.0" spaceAfter="6.0"/>
-    <paraStyle name="P5" fontName="Times-Roman" alignment="CENTER" spaceBefore="0.0" spaceAfter="6.0"/>
-    <paraStyle name="P6" fontName="Times-Roman" fontSize="11.0" leading="14" alignment="RIGHT" spaceBefore="0.0" spaceAfter="6.0"/>
-    <paraStyle name="P7" fontName="Times-Roman" fontSize="11.0" leading="14" alignment="RIGHT" spaceBefore="0.0" spaceAfter="6.0"/>
-    <paraStyle name="P8" fontName="Times-Roman" fontSize="8.0" leading="10" alignment="RIGHT" spaceBefore="0.0" spaceAfter="6.0"/>
-    <paraStyle name="P9" fontName="Times-Roman" alignment="LEFT" spaceBefore="0.0" spaceAfter="6.0"/>
-    <paraStyle name="P10" fontName="Times-Roman" alignment="CENTER"/>
-    <paraStyle name="P11" fontName="Times-Roman" fontSize="8.0" leading="10"/>
-    <paraStyle name="P12" fontName="Times-Roman" fontSize="11.0" leading="14" alignment="CENTER" spaceBefore="0.0" spaceAfter="6.0"/>
-    <paraStyle name="P13" fontName="Times-Roman" fontSize="8.0" leading="10" spaceBefore="0.0" spaceAfter="6.0"/>
+    <paraStyle name="P1" fontName="Helvetica" fontSize="8.0" leading="25" alignment="CENTER" spaceBefore="0.0" spaceAfter="6.0"/>
+    <paraStyle name="P2" fontName="Helvetica" fontSize="10.0" leading="13" alignment="RIGHT" spaceBefore="0.0" spaceAfter="6.0"/>
+    <paraStyle name="P3" fontName="Helvetica" fontSize="8.0" leading="10" alignment="LEFT" spaceBefore="0.0" spaceAfter="6.0"/>
+    <paraStyle name="P4" fontName="Helvetica" fontSize="8.0" leading="10" alignment="RIGHT" spaceBefore="0.0" spaceAfter="6.0"/>
+    <paraStyle name="P5" fontName="Helvetica" alignment="CENTER" spaceBefore="0.0" spaceAfter="6.0"/>
+    <paraStyle name="P6" fontName="Helvetica" fontSize="11.0" leading="14" alignment="RIGHT" spaceBefore="0.0" spaceAfter="6.0"/>
+    <paraStyle name="P7" fontName="Helvetica" fontSize="8.0" leading="14" alignment="RIGHT" spaceBefore="0.0" spaceAfter="6.0"/>
+    <paraStyle name="P8" fontName="Helvetica" fontSize="8.0" leading="10" alignment="RIGHT" spaceBefore="0.0" spaceAfter="6.0"/>
+    <paraStyle name="P9" fontName="Helvetica" alignment="LEFT" spaceBefore="0.0" spaceAfter="6.0"/>
+    <paraStyle name="P9b" fontName="Helvetica-Bold" alignment="RIGHT" spaceBefore="0.0" spaceAfter="6.0"/>
+    <paraStyle name="P10" fontName="Helvetica" alignment="CENTER"/>
+    <paraStyle name="P11" fontName="Helvetica" fontSize="8.0" leading="10"/>
+    <paraStyle name="P12" fontName="Helvetica-Bold" fontSize="8.0" leading="14" alignment="CENTER" spaceBefore="0.0" spaceAfter="6.0"/>
+    <paraStyle name="P12a" fontName="Helvetica-Bold" fontSize="8.0" leading="14" alignment="LEFT" spaceBefore="0.0" spaceAfter="6.0"/>
+    <paraStyle name="P13" fontName="Helvetica" fontSize="8.0" leading="10" spaceBefore="0.0" spaceAfter="6.0"/>
     <paraStyle name="P14" rightIndent="17.0" leftIndent="-0.0" fontName="Times-Bold" fontSize="8.0" leading="10" spaceBefore="0.0" spaceAfter="6.0"/>
-    <paraStyle name="Standard" fontName="Times-Roman"/>
-    <paraStyle name="Text body" fontName="Times-Roman" spaceBefore="0.0" spaceAfter="6.0"/>
-    <paraStyle name="List" fontName="Times-Roman" spaceBefore="0.0" spaceAfter="6.0"/>
-    <paraStyle name="Table Contents" fontName="Times-Roman" spaceBefore="0.0" spaceAfter="6.0"/>
-    <paraStyle name="Table Heading" fontName="Times-Roman" alignment="CENTER" spaceBefore="0.0" spaceAfter="6.0"/>
-    <paraStyle name="Caption" fontName="Times-Roman" fontSize="10.0" leading="13" spaceBefore="6.0" spaceAfter="6.0"/>
-    <paraStyle name="Index" fontName="Times-Roman"/>
+    <paraStyle name="Standard" fontName="Helvetica"/>
+    <paraStyle name="Text body" fontName="Helvetica" spaceBefore="0.0" spaceAfter="6.0"/>
+    <paraStyle name="List" fontName="Helvetica" spaceBefore="0.0" spaceAfter="6.0"/>
+    <paraStyle name="Table Contents" fontName="Helvetica" spaceBefore="0.0" spaceAfter="6.0"/>
+    <paraStyle name="Table Heading" fontName="Helvetica" alignment="CENTER" spaceBefore="0.0" spaceAfter="6.0"/>
+    <paraStyle name="Caption" fontName="Helvetica" fontSize="10.0" leading="13" spaceBefore="6.0" spaceAfter="6.0"/>
+    <paraStyle name="Index" fontName="Helvetica"/>
   </stylesheet>
-  <images/>
   <story>
-    <blockTable colWidths="145.0,186.0,151.0" repeatRows="1" style="Table1">
+       <blockTable colWidths="247.0,60.0,58.0,55.0,54.0,57.0" style="Tableau3">
       <tr>
         <td>
-          <para style="Table Contents">
-            <font color="white"> </font>
-          </para>
+          <para style="P7">Grand total</para>
         </td>
         <td>
-          <para style="P1">Third party balance</para>
+          <para style="P8">[[ comma_me(sum_debit(data)) ]]</para>
         </td>
         <td>
-          <para style="P2"><font face="Times-Roman">From</font> [[ formatLang(data['form']['date1'], date=True) ]]</para>
-          <para style="P2"><font face="Times-Roman">to</font> [[ formatLang(data['form']['date2'], date=True) ]]</para>
+          <para style="P8">[[ comma_me(sum_credit(data)) ]]</para>
         </td>
-      </tr>
-      <tr>
         <td>
-          <para style="Table Contents">[[ get_company(data['form']) ]]</para>
+          <para style="P8">[[ comma_me(sum_sdebit(data)) ]]</para>
         </td>
         <td>
-          <para style="P5">
-            <font color="white"> </font>
-          </para>
+          <para style="P8">[[ comma_me(sum_scredit(data)) ]]</para>
         </td>
         <td>
-          <para style="P6"><font face="Times-Roman">Currency:</font> [[ get_currency(data['form']) ]]</para>
+          <para style="P8">[[ comma_me(sum_litige(data)) ]]</para>
         </td>
       </tr>
-    </blockTable>
-    <para style="Standard">
-      <font color="white"> </font>
-    </para>
-    <para style="P10"><font face="Times-Roman">Printing date:</font> [[ formatLang(time.strftime('%Y-%m-%d'), date=True) ]] <font face="Times-Roman">at</font> [[ time.strftime('%H:%M:%S') ]]</para>
-    <para style="P10">
-      <font color="white"> </font>
-    </para>
-    <blockTable colWidths="60.0,137.0,118.0,109.0,58.0" repeatRows="1" style="Table6">
       <tr>
         <td>
-          <para style="P12">Account number</para>
-        </td>
-        <td>
-          <para style="P12">Account name</para>
-        </td>
-        <td>
-          <para style="P12">Transactions</para>
-        </td>
-        <td>
-          <para style="P12">Balances</para>
-        </td>
-        <td>
-          <para style="P12">In dispute</para>
+          <para style="P7">Balance</para>
         </td>
-      </tr>
-    </blockTable>
-    <blockTable colWidths="197.0,60.0,58.0,55.0,54.0,58.0" repeatRows="1" style="Table2">
-      <tr>
         <td>
-          <para style="P12">
+          <para style="P8">
             <font color="white"> </font>
           </para>
         </td>
         <td>
-          <para style="P12">Debit</para>
-        </td>
-        <td>
-          <para style="P12">Credit</para>
-        </td>
-        <td>
-          <para style="P12">Debit</para>
-        </td>
-        <td>
-          <para style="P12">Credit</para>
-        </td>
-        <td>
-          <para style="P12">
+          <para style="P8">
             <font color="white"> </font>
           </para>
         </td>
-      </tr>
-    </blockTable>
-    <para style="P13">
-      <font color="white"> </font>
-    </para>
-    <blockTable colWidths="61.0,137.0,60.0,58.0,55.0,54.0,57.0" style="Table3">
-      <tr>
-        <td>
-          <para style="P14">[[ repeatIn(lines(), 'a') ]]<font face="Times-Roman">[[ a['ref'] ]]</font></para>
-        </td>
-        <td>
-          <para style="P3">[[ a['name'] ]]</para>
-        </td>
-        <td>
-          <para style="P4">[[ formatLang(a['debit']) ]]</para>
-        </td>
-        <td>
-          <para style="P4">[[ formatLang(a['credit']) ]]</para>
-        </td>
         <td>
-          <para style="P4">[[ formatLang(a['sdebit']) ]]</para>
+          <para style="P8">[[ comma_me(solde_debit(data)) ]]</para>
         </td>
         <td>
-          <para style="P4">[[ formatLang(a['scredit']) ]]</para>
+          <para style="P8">[[ comma_me(solde_credit(data)) ]]</para>
         </td>
         <td>
-          <para style="P4">[[ formatLang((a['enlitige'] or 0.0)) ]]</para>
+          <para style="P8">
+            <font color="white"> </font>
+          </para>
         </td>
       </tr>
     </blockTable>
-    <para style="Standard">
-      <font color="white"> </font>
-    </para>
-    <blockTable colWidths="198.0,60.0,58.0,56.0,53.0,57.0" style="Table4">
+    <blockTable colWidths="61.0,196.0,60.0,58.0,109.0,57.0" repeatRows="1" style="Table2">
       <tr>
         <td>
-          <para style="P7">Grand total</para>
+          <para style="P12a">Code</para>
         </td>
         <td>
-          <para style="P8">[[ formatLang(sum_debit()) ]]</para>
+          <para style="P12a">Partner name</para>
         </td>
         <td>
-          <para style="P8">[[ formatLang(sum_credit()) ]]</para>
+          <para style="P12">Débit</para>
         </td>
         <td>
-          <para style="P8">[[ formatLang(sum_sdebit()) ]]</para>
+          <para style="P12">Crédit</para>
         </td>
         <td>
-          <para style="P8">[[ formatLang(sum_scredit()) ]]</para>
+          <para style="P12">Balance</para>
         </td>
         <td>
-          <para style="P8">[[ formatLang(sum_litige()) ]]</para>
+          <para style="P12">In dispute</para>
         </td>
       </tr>
       <tr>
         <td>
-          <para style="P7">Balance</para>
+          <para style="P3">[[ repeatIn(lines(data), 'a') ]]<font face="Helvetica">[[ a['type']==3 and ( setTag('para','para',{'fontName':'Helvetica-Bold'})) ]] [[ a['ref'] ]]</font></para>
         </td>
         <td>
-          <para style="P8">
-            <font color="white"> </font>
-          </para>
+          <para style="P3">[[ a['type']==3 and ( setTag('para','para',{'fontName':'Helvetica-Bold'})) ]] [[ a['type']==3 and a['code'] ]]  [[ a['name']  ]] </para>
         </td>
         <td>
-          <para style="P8">
-            <font color="white"> </font>
-          </para>
+          <para style="P4">[[ a['type']==3 and ( setTag('para','para',{'fontName':'Helvetica-Bold'})) ]]  [[ comma_me(a['debit']) ]]</para>
         </td>
         <td>
-          <para style="P8">[[ formatLang(solde_debit()) ]]</para>
+          <para style="P4">[[ a['type']==3 and ( setTag('para','para',{'fontName':'Helvetica-Bold'})) ]] [[ comma_me(a['credit']) ]]</para>
         </td>
         <td>
-          <para style="P8">[[ formatLang(solde_credit()) ]]</para>
+          <para style="P4">[[ a['type']==3 and ( setTag('para','para',{'fontName':'Helvetica-Bold'})) ]] [[ comma_me(a['balance']) ]]</para>
         </td>
         <td>
-          <para style="P8">
-            <font color="white"> </font>
-          </para>
+          <para style="P4">[[ a['type']==3 and ( setTag('para','para',{'fontName':'Helvetica-Bold'})) ]] [[ comma_me(a['enlitige']) ]]</para>
         </td>
       </tr>
     </blockTable>
+    <para style="Standard">
+      <font color="white"> </font>
+    </para>
+    
     <para style="P11"/>
     <para style="P9">
       <font color="white"> </font>
     </para>
   </story>
 </document>
-
index d5ce386..08af607 100644 (file)
@@ -1,9 +1,6 @@
-# -*- encoding: utf-8 -*-
 ##############################################################################
 #
-# Copyright (c) 2004-2008 TINY SPRL. (http://tiny.be) All Rights Reserved.
-#
-# $Id$
+# Copyright (c) 2005-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
 #
 # WARNING: This program as such is intended to be used by professional
 # programmers who take the whole responsability of assessing all potential
@@ -32,28 +29,51 @@ import time
 import wizard
 import pooler
 
+report_type =  '''<?xml version="1.0"?>
+<form string="Select Report Type">
+</form>'''
+
+
 dates_form = '''<?xml version="1.0"?>
 <form string="Select period">
     <field name="company_id" colspan="4"/>
     <newline/>
-    <field name="fiscalyear" colspan="4"/>
-    <label align="0.7" colspan="6" string="(If you do not select Fiscal year it will take all open fiscal year)"/>
-    <newline/>
     <field name="date1"/>
     <field name="date2"/>
     <newline/>
-    <field name="state" colspan="4"/>
+    <field name="result_selection"/>
+    <field name="soldeinit"/>
 </form>'''
 
 dates_fields = {
     'company_id': {'string': 'Company', 'type': 'many2one', 'relation': 'res.company', 'required': True},
+    'result_selection':{'string':"Display partner ",'type':'selection','selection':[('customer','Debiteur'),('supplier','Creancier'),('all','Tous')]},
+    'soldeinit':{'string':"Inclure les soldes initiaux",'type':'boolean'},
+    'date1': {'string':'Start date', 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-01-01')},
+    'date2': {'string':'End date', 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-%m-%d')},
+}
+
+period_form = '''<?xml version="1.0"?>
+<form string="Select period">
+    <field name="company_id" colspan="4"/>
+    <newline/>
+    <field name="fiscalyear" colspan="4"/>
+    <field name="periods" colspan="4"/>
+    <newline/>
+    <field name="result_selection"/>
+    <field name="soldeinit"/>
+</form>'''
+
+period_fields = {
+    'company_id': {'string': 'Company', 'type': 'many2one', 'relation': 'res.company', 'required': True},
     'fiscalyear': {'string': 'Fiscal year', 'type': 'many2one', 'relation': 'account.fiscalyear',
         'help': 'Keep empty for all open fiscal year'},
-    'date1': {'string':'Start of period', 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-01-01')},
-    'date2': {'string':'End of period', 'type':'date', 'required':True, 'default': lambda *a: time.strftime('%Y-%m-%d')},
-    'state':{'string':'Target Moves','type':'selection','selection': [('all','All Entries'),('posted','All Posted Entries')]}
+    'periods': {'string': 'Periods', 'type': 'many2many', 'relation': 'account.period', 'help': 'All periods if empty'},
+    'result_selection':{'string':"Display partner",'type':'selection','selection':[('customer','Debiteur'),('supplier','Creancier'),('all','Tous')]},
+    'soldeinit':{'string':"Inclure les soldes initiaux",'type':'boolean'},
 }
 
+
 class wizard_report(wizard.interface):
     def _get_defaults(self, cr, uid, data, context):
         fiscalyear_obj = pooler.get_pool(cr.dbname).get('account.fiscalyear')
@@ -65,22 +85,57 @@ class wizard_report(wizard.interface):
         else:
             company_id = pooler.get_pool(cr.dbname).get('res.company').search(cr, uid, [('parent_id', '=', False)])[0]
         data['form']['company_id'] = company_id
-        data['form']['state']='all'
-
+        data['form']['soldeinit'] = True
+        data['form']['result_selection'] = 'all'
         return data['form']
+    
+    def _get_defaults_fordate(self, cr, uid, data, context):
+        user = pooler.get_pool(cr.dbname).get('res.users').browse(cr, uid, uid, context=context)
+        if user.company_id:
+            company_id = user.company_id.id
+        else:
+            company_id = pooler.get_pool(cr.dbname).get('res.company').search(cr, uid, [('parent_id', '=', False)])[0]
+        data['form']['company_id'] = company_id
+        data['form']['soldeinit'] = True
+        data['form']['result_selection'] = 'all'
+        return data['form']
+    
+    def _check_date(self, cr, uid, data, context):
+        sql = """
+            SELECT f.id, f.date_start, f.date_stop FROM account_fiscalyear f  Where '%s' between f.date_start and f.date_stop """%(data['form']['date1'])
+        cr.execute(sql)
+        res = cr.dictfetchall()
+        if res:
+            if (data['form']['date2'] > res[0]['date_stop'] or data['form']['date2'] < res[0]['date_start']):
+                raise  wizard.except_wizard('UserError','Date to must be set between ' + res[0]['date_start'] + " and " + res[0]['date_stop'])
+            else:
+                return 'report'
+            
+        else:
+            raise wizard.except_wizard('UserError','Date not in a defined fiscal year')
+
 
     states = {
         'init': {
+            'actions': [],
+            'result': {'type':'form', 'arch':report_type,'fields':{}, 'state':[('with_period','Use with Period'),('with_date','Use with Date')]}
+        },
+        'with_period': {
             'actions': [_get_defaults],
-            'result': {'type':'form', 'arch':dates_form, 'fields':dates_fields, 'state':[('end','Cancel'),('report','Print') ]}
+            'result': {'type':'form', 'arch':period_form, 'fields':period_fields, 'state':[('end','Cancel'),('report','Print')]}
+        },
+        'with_date': {
+            'actions': [_get_defaults_fordate],
+            'result': {'type':'form', 'arch':dates_form, 'fields':dates_fields, 'state':[('end','Cancel'),('checkdate','Print')]}
+        },
+        'checkdate': {
+            'actions': [],
+            'result': {'type':'choice','next_state':_check_date}
         },
+        
         'report': {
             'actions': [],
             'result': {'type':'print', 'report':'account.partner.balance', 'state':'end'}
         }
     }
 wizard_report('account.partner.balance.report')
-
-
-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
-