← Back to team overview

clearcorp team mailing list archive

lp:~dr.clearcorp/openerp-costa-rica/6.1-account_bank_balance_report into lp:openerp-costa-rica

 

Diana Rodríguez Martínez has proposed merging lp:~dr.clearcorp/openerp-costa-rica/6.1-account_bank_balance_report into lp:openerp-costa-rica.

Requested reviews:
  CLEARCORP drivers (clearcorp-drivers)

For more details, see:
https://code.launchpad.net/~dr.clearcorp/openerp-costa-rica/6.1-account_bank_balance_report/+merge/146977

[FIX] Fix style for account_bank_balances report. Change to landscape clearcorp official header.
[FIX] Fix compute for the balance in case of foreing currency 
[ADD] Add cases for no filter and filter_type opening period
-- 
https://code.launchpad.net/~dr.clearcorp/openerp-costa-rica/6.1-account_bank_balance_report/+merge/146977
Your team CLEARCORP development team is subscribed to branch lp:openerp-costa-rica.
=== modified file 'l10n_cr_account_financial_report_webkit/__openerp__.py'
--- l10n_cr_account_financial_report_webkit/__openerp__.py	2012-07-20 16:00:33 +0000
+++ l10n_cr_account_financial_report_webkit/__openerp__.py	2013-02-06 22:25:24 +0000
@@ -29,7 +29,7 @@
     'category': 'Finance',
     'website': "http://clearcorp.co.cr";,
     'images': [],
-    'depends': ['account_financial_report_webkit', 'account' ],
+    'depends': ['account' ],
     'init_xml': [],
     'demo_xml' : [],
     'update_xml': ['account_move_line_view.xml',

=== modified file 'l10n_cr_account_financial_report_webkit/report/account_bank_balances.mako'
--- l10n_cr_account_financial_report_webkit/report/account_bank_balances.mako	2012-09-01 00:22:31 +0000
+++ l10n_cr_account_financial_report_webkit/report/account_bank_balances.mako	2013-02-06 22:25:24 +0000
@@ -1,312 +1,158 @@
 <!DOCTYPE html SYSTEM "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
 <html xmlns="http://www.w3.org/1999/xhtml";>
     <head>
-       		<style type="text/css">
-			.account_level_1 {
-				text-transform: uppercase;
-                font-size: 15px;
-                background-color:#F0F0F0;
-            }
-
-            .account_level_2 {
-                font-size: 12px;
-                background-color:#F0F0F0;
-            }
-
-            .regular_account_type {
-                font-weight: normal;
-            }
-
-            .view_account_type {
-                font-weight: bold;
-            }
-
-            .account_level_consol {
-                font-weight: normal;
-            	font-style: italic;
-            }
-
+        <link rel='stylesheet' href='addons/account_webkit_report_library/webkit_headers/main.css' />
+        <style>
             ${css}
-
-            .list_table .act_as_row {
-                margin-top: 10px;
-                margin-bottom: 10px;
-                font-size:10px;
-            }
         </style>
     </head>
     <body>
-        <%!
-        def amount(text):
-            return text.replace('-', '&#8209;')  # replace by a non-breaking hyphen (it will not word-wrap between hyphen and numbers)
-        %>
-
         <%setLang(user.context_lang)%>
-
         <%
-        initial_balance_text = {'initial_balance': _('Computed'), 'opening_balance': _('Opening Entries'), False: _('No')}
         filter_type = ''
         filter_data = []
+        t_m = target_move(data) 
         %>
-
-        <div class="act_as_table data_table">
-            <div class="act_as_row labels" style="font-weight: bold;">
-                <div class="act_as_cell">${_('Chart of Account')}</div>
-                <div class="act_as_cell">${_('Fiscal Year')}</div>
-                <div class="act_as_cell">
-                    %if filter_form(data) == 'filter_date':
-                        ${_('Dates Filter')}
-                    %else:
-                        ${_('Periods Filter')}
-                    %endif
-                </div>
-                <div class="act_as_cell">${_('Accounts Filter')}</div>
-                <div class="act_as_cell">${_('Target Moves')}</div>
-                <div class="act_as_cell">${_('Initial Balance')}</div>
-            </div>
-            <div class="act_as_row">
-                <div class="act_as_cell">${ chart_account.name }</div>
-                <div class="act_as_cell">${ fiscalyear.name if fiscalyear else '-' }</div>
-                <div class="act_as_cell">
-                    ${_('From:')}
-                    %if filter_form(data) == 'filter_date':
-                        ${formatLang(start_date, date=True) if start_date else u'' }
-                        <% 
-                            filter_data.append(start_date) 
-                            filter_type = 'filter_date'
-                        %>
-                    %elif filter_form(data) == 'filter_period':
-                        ${start_period.name if start_period else u''}
-                        <% 
-                            filter_data.append(start_period) 
-                            filter_type = 'filter_period'
-                        %>
-                    %endif
-                    ${_('To:')}
-                    %if filter_form(data) == 'filter_date':
-                        ${ formatLang(stop_date, date=True) if stop_date else u'' }
-                        <% filter_data.append(stop_date) %>
-                    %elif filter_form(data) == 'filter_period':
-                        ${stop_period.name if stop_period else u'' }
-                        <% filter_data.append(stop_period) %>
-                    %endif
-                </div>
-                <div class="act_as_cell">
-                    %if accounts(data):
-                        ${', '.join([account.code for account in accounts(data)])}
-                    %else:
-                        ${_('All')}
-                    %endif
-                </div>
-                <div class="act_as_cell">${ display_target_move(data) }</div>
-                <div class="act_as_cell">${ initial_balance_text[initial_balance_mode] }</div>
+        <div class="table header">
+           <div class="table-row">
+               <div class="table-cell logo">${helper.embed_logo_by_name('internal_reports_logo', height=100)|n}</div>
+               <br/>
+               <div class="table-cell text">
+                    <p class="title">${_('Account Bank Balance Report')}</p>
+               </div>
+           </div>
+       </div>
+        <div class="table list">
+            <div class="table-header">
+                <div class="table-row labels no-wrap">
+                    <div class="table-cell first-column" style="width: 70px">${_('Chart of Account')}<br/>${ chart_account.name }</div>
+                    <div class="table-cell" style="width: 100px">
+                            %if filter_form(data) == 'filter_date':
+                                ${_('Dates Filter')}
+                            %elif filter_form(data) == 'filter_period': 
+                                ${_('Periods Filter')}
+                            %elif filter_form(data) == '':
+                                ${_('Filter')}
+                             %elif filter_form(data) == 'filter_opening':
+                                ${_('Opening filter')}
+                            %endif
+                            <br/>
+                            %if filter_form(data) == 'filter_date':
+                                ${_('From:')}
+                                ${formatLang(start_date, date=True) if start_date else u'' }
+                                <% 
+                                    filter_data.append(start_date) 
+                                    filter_type = 'filter_date'
+                                %>
+                            %elif filter_form(data) == 'filter_period':
+                                ${_('From:')}
+                                ${start_period.name if start_period else u''}
+                                <% 
+                                    filter_data.append(start_period) 
+                                    filter_type = 'filter_period'
+                                %>
+                            %elif filter_form(data) == '':
+                                ${_('No filters')}                             
+                            %elif filter_form(data) == 'filter_opening':
+                                ${_('Opening balance')}
+                            %endif                              
+                            %if filter_form(data) == 'filter_date':
+                                ${_('To:')}
+                                ${ formatLang(stop_date, date=True) if stop_date else u'' }
+                                <% filter_data.append(stop_date) %>                            
+                            %elif filter_form(data) == 'filter_period':
+                                ${_('To:')}
+                                ${stop_period.name if stop_period else u'' }
+                                <% filter_data.append(stop_period) %>                        
+                            %endif             
+                    </div>
+                    <div class="table-cell" style="width: 100px">${_('Fiscal Year')}<br/>${ fiscalyear.name if fiscalyear else '-' }</div>                
+                    <div div class="table-cell" style="width: 100px">${_('Target Moves')}<br/>${ display_target_move(data) }</div>
+                </div>
             </div>
         </div>
+        <%
+        
+        bank_accounts = get_bank_accounts(cr, uid)
+        accounts_currency = accounts_by_currency(cr, uid, bank_accounts)
 
-        %for index, params in enumerate(comp_params):
-            <div class="act_as_table data_table">
-                <div class="act_as_row">
-                    <div class="act_as_cell">${_('Comparison %s') % (index + 1,)} (${"C%s" % (index + 1,)})</div>
-                    <div class="act_as_cell">
-                        %if params['comparison_filter'] == 'filter_date':
-                            ${_('Dates Filter:')}&nbsp;${formatLang(params['start'], date=True) }&nbsp;-&nbsp;${formatLang(params['stop'], date=True) }
-                        %elif params['comparison_filter'] == 'filter_period':
-                            ${_('Periods Filter:')}&nbsp;${params['start'].name}&nbsp;-&nbsp;${params['stop'].name}
-                        %else:
-                            ${_('Fiscal Year :')}&nbsp;${params['fiscalyear'].name}
-                        %endif
-                    </div>
-                    <div class="act_as_cell">${_('Initial Balance:')} ${ initial_balance_text[params['initial_balance_mode']] }</div>
+        %>
+        %for currency, accounts in accounts_currency.iteritems():
+            <br/><br/>
+            <div class="table header">
+                <div class="table-row">
+                   <div class="table-cell text">
+                        <p class="subtitle">${_('Account Bank Balance in: ')} ${currency}</p>
+                   </div>
                 </div>
             </div>
-        %endfor
-
-        
-            <%
-            last_child_consol_ids = []
-            last_level = False
-            
-            bank_accounts = get_bank_accounts(cr, uid, objects)
-            accounts_currency = accounts_by_currency(cr, uid, bank_accounts)
-            total_balance = 0.0
-
-            %>
-            %for currency in accounts_currency:
-            <%
-                total_tefs_curr = 0.0
-                total_checks_curr = 0.0
-                total_deposit_curr = 0.0
-                total_debit_curr = 0.0
-                total_credit_curr = 0.0
-                account_balance = 0.0
-                total_balance_curr = 0.0
-                total_inital_balance_curr = 0.0
-            %>
-                %if currency[0] != 'CRC':
-                    <div class="account_title bg" style="margin-top: 20px; font-size: 12px; width: 700px;">${_('Account Bank Balance in ')} ${currency[0]}</div>
-                %else:
-                    <div class="account_title bg" style="margin-top: 20px; font-size: 12px; width: 700px;">${_('Account Bank Balance in ')} ${company.currency_id.name}</div>
-                %endif
-                <div class="act_as_table list_table" style="margin-top: 10px;">
-                <div class="act_as_thead">
-                    <div class="act_as_row labels" style="font-weight: bold;">
+            <div class="table list">
+                <div class="table-header">
+                    <div class="table-row labels no-wrap">
                         ## code
-                        <div class="act_as_cell first_column" style="width: 40px;">${_('Code')}</div>
+                        <div class="table-cell first-column" style="width: 40px;">${_('Code')}</div>
                         ## account name
-                        <div class="act_as_cell" style="width: 80px;">${_('Account')}</div>
-                        %if comparison_mode == 'no_comparison':
-                            %if initial_balance_mode:
-                                ## initial balance
-                                <div class="act_as_cell amount" style="width: 50px;">${_('Initial Balance')}</div>
-                            %endif
-                            ## TEFS
-                            <div class="act_as_cell amount" style="width: 50px;">${_('Transfers')}</div>
-                            ## Checks
-                            <div class="act_as_cell amount" style="width: 50px;">${_('Checks')}</div>
-                            ## Deposit
-                            <div class="act_as_cell amount" style="width: 50px;">${_('Deposit')}</div>
-                            ## debit
-                            <div class="act_as_cell amount" style="width: 50px;">${_('Debit')}</div>
-                            ## credit
-                            <div class="act_as_cell amount" style="width: 50px;">${_('Credit')}</div>
-                        %endif
+                        <div class="table-cell" style="width: 80px;">${_('Account')}</div>
+                        ## initial balance
+                        <div class="table-cell" style="width: 50px;">${_('Initial Balance')}</div>
+                        ## TEFS
+                        <div class="table-cell" style="width: 50px;">${_('Transfers')}</div>
+                        ## Checks
+                        <div class="table-cell" style="width: 50px;">${_('Checks')}</div>
+                        ## Deposit
+                        <div class="table-cell" style="width: 50px;">${_('Deposit')}</div>
+                        ## debit
+                        <div class="table-cell" style="width: 50px;">${_('Debit')}</div>
+                        ## credit
+                        <div class="table-cell" style="width: 50px;">${_('Credit')}</div>
                         ## balance
-                        <div class="act_as_cell amount" style="width: 50px;">
-                        %if comparison_mode == 'no_comparison' or not fiscalyear:
-                            ${_('Balance')}
-                        %else:
-                            ${_('Balance %s') % (fiscalyear.name,)}
-                        %endif
-                        </div>
-                        %if comparison_mode in ('single', 'multiple'):
-                            %for index in range(nb_comparison):
-                                <div class="act_as_cell amount" style="width: 50px;">
-                                    %if comp_params[index]['comparison_filter'] == 'filter_year' and comp_params[index].get('fiscalyear', False):
-                                        ${_('Balance %s') % (comp_params[index]['fiscalyear'].name,)}
-                                    %else:
-                                        ${_('Balance C%s') % (index + 1,)}
-                                    %endif
-                                </div>
-                                %if comparison_mode == 'single':  ## no diff in multiple comparisons because it shows too data
-                                    <div class="act_as_cell amount" style="width: 50px;">${_('Difference')}</div>
-                                    <div class="act_as_cell amount" style="width: 50px;">${_('% Difference')}</div>
-                                %endif
-                            %endfor
-                        %endif
+                        <div class="table-cell" style="width: 50px;">${_('Balance')}</div>                        
                     </div>
-                </div>                   
-                
-                <div class="act_as_tbody">
-                    %for account in sorted(currency[1], key=lambda account: account.name):
+                </div>
+                <div class="table-body">
+                    %for account in sorted(set(accounts)):
                         <%
-                        move_lines = get_move_lines_account(cr, uid, filter_type, filter_data, account)
-
-                        if currency[0] != 'CRC':
-                            debit = get_debit_account(cr, uid, move_lines, account.report_currency_id.name)
-                            credit = get_credit_account(cr, uid, move_lines, account.report_currency_id.name)
-                            deposit = get_deposit_account(cr, uid, move_lines, account.report_currency_id.name, account)
-                            tefs = get_tefs_account(cr, uid, move_lines, account.report_currency_id.name, account)
-                            checks = get_checks_account(cr, uid, move_lines, account.report_currency_id.name, account)
-                        else:
-                            debit = get_debit_account(cr, uid, move_lines, company.currency_id.name)
-                            credit = get_credit_account(cr, uid, move_lines, company.currency_id.name)
-                            deposit = get_deposit_account(cr, uid, move_lines, company.currency_id.name, account)
-                            tefs = get_tefs_account(cr, uid, move_lines, company.currency_id.name, account)
-                            checks = get_checks_account(cr, uid, move_lines, company.currency_id.name, account)
-
-                        total_tefs_curr += tefs
-                        total_checks_curr += checks
-                        total_deposit_curr += deposit
-                        total_debit_curr += debit
-                        total_credit_curr += credit
-                        account_balance = debit - credit
-                        total_balance_curr += account_balance
-                        total_inital_balance_curr += account.init_balance
-
-                        if not account.to_display:
-                            continue
-
-                        comparisons = account.comparisons
-
-                        if account.id in last_child_consol_ids:
-                            # current account is a consolidation child of the last account: use the level of last account
-                            level = last_level
-                            level_class = "account_level_consol"
-                        else:
-                            # current account is a not a consolidation child: use its own level
-                            level = account.level or 0
-                            level_class = "account_level_%s" % (level,)
-                            last_child_consol_ids = [child_consol_id.id for child_consol_id in account.child_consol_ids]
-                            last_level = account.level
+                            move_lines = get_move_lines_account(cr, uid, account.id,filter_type,filter_data,fiscalyear,t_m)
+                            total_result = get_total_move_lines(cr, uid, move_lines, account)
+                            initial_balance = get_initia_balance_accounts(cr, uid, accounts,filter_type, filter_data,fiscalyear,t_m,data['form']['chart_account_id'])
                         %>
-
-                        <div class="act_as_row lines ${level_class} ${"%s_account_type" % (account.type,)}">
+                        <div class="table-row ${row_even and 'even' or 'odd'}">
                             ## code
-                            <div class="act_as_cell first_column">${account.code}</div>
+                            <div class="table-cell first-column">${account.code}</div>
                             ## account name
-                            <div class="act_as_cell">${account.name}</div>
-                            %if comparison_mode == 'no_comparison':
-                                %if initial_balance_mode:
-                                    ## opening balance
-                                    <div class="act_as_cell amount">${formatLang(account.init_balance) | amount}</div>
-                                %endif
-                                ## TEFS
-                                <div class="act_as_cell amount">${formatLang(tefs) | amount}</div>
-                                ## checks
-                                <div class="act_as_cell amount">${formatLang(checks) | amount}</div>
-                                ## deposit
-                                <div class="act_as_cell amount">${formatLang(deposit) | amount}</div>
-                                ## debit
-                                <div class="act_as_cell amount">${formatLang(debit) | amount}</div>
-                                ## credit
-                                <div class="act_as_cell amount">${formatLang(credit) | amount}</div>
-                            %endif
-                            ## balance
-                            <div class="act_as_cell amount">${formatLang(account_balance) | amount}</div>
-
-                            %if comparison_mode in ('single', 'multiple'):
-                                %for comp_account in comparisons:
-                                    <div class="act_as_cell amount">${formatLang(comp_account['balance']) | amount}</div>
-                                    %if comparison_mode == 'single':  ## no diff in multiple comparisons because it shows too data
-                                        <div class="act_as_cell amount">${formatLang(comp_account['diff']) | amount}</div>
-                                        <div class="act_as_cell amount"> 
-                                        %if comp_account['percent_diff'] is False:
-                                            ${ '-' }
-                                        %else:
-                                            ${int(round(comp_account['percent_diff'])) | amount} &#37;
-                                        %endif
-                                        </div>
-                                    %endif
-                                %endfor
-                            %endif
-                        </div>
+                            <div class="table-cell">${account.name}</div>
+                            <% 
+                                foreign_currency = not account.company_id.currency_id.id == account.report_currency_id.id 
+                            %>
+                            %if foreign_currency:
+                                ##foreign_balance
+                                <div class="table-cell amount">${formatLang(initial_balance[account.id]['foreign_balance'])}</div>
+                            %else:
+                                 ##balance
+                                <div class="table-cell amount">${formatLang(initial_balance[account.id]['balance'])}</div>
+                            %endif
+                            ##transfer
+                            <div class="table-cell amount">${formatLang(total_result['amount_transf'])}</div>
+                            ##check
+                            <div class="table-cell amount">${formatLang(total_result['amount_check'])}</div>
+                            ##deposit
+                            <div class="table-cell amount">${formatLang(total_result['amount_deposit'])}</div>
+                            ##debit
+                            <div class="table-cell amount">${formatLang(total_result['amount_debit'])}</div>
+                            ##credit
+                            <div class="table-cell amount">${formatLang(total_result['amount_credit'])}</div> 
+                            %if foreign_currency:
+                                ##foreign_balance
+                                <div class="table-cell amount">${formatLang(initial_balance[account.id]['foreign_balance']+total_result['amount_transf']+total_result['amount_check']+total_result['amount_deposit']+total_result['amount_debit']+total_result['amount_credit'])}</div>
+                            %else:                            
+                                ##balance
+                                <div class="table-cell amount">${formatLang(initial_balance[account.id]['balance']+total_result['amount_transf']+total_result['amount_check']+total_result['amount_deposit']+total_result['amount_debit']+total_result['amount_credit'])}</div>
+                           %endif
+                        </div>                        
                     %endfor
                 </div>
-                <div class="act_as_tfoot">
-                    <div class="act_as_row labels"  style="font-weight: bold; font-size: 11x">
-                        <div class="act_as_cell first_column">${_('Total')}</div>
-                        <div class="act_as_cell">${' '}</div>
-                        %if currency[0] != 'CRC':
-                            <div class="act_as_cell amount">${account.report_currency_id.symbol}${formatLang(total_inital_balance_curr)}</div>
-                            <div class="act_as_cell amount">${account.report_currency_id.symbol}${formatLang(total_tefs_curr)}</div>
-                            <div class="act_as_cell amount">${account.report_currency_id.symbol}${formatLang(total_checks_curr)}</div>
-                            <div class="act_as_cell amount">${account.report_currency_id.symbol}${formatLang(total_deposit_curr)}</div>
-                            <div class="act_as_cell amount">${account.report_currency_id.symbol}${formatLang(total_debit_curr)}</div>
-                            <div class="act_as_cell amount">${account.report_currency_id.symbol}${formatLang(total_credit_curr)}</div>
-                            <div class="act_as_cell amount">${account.report_currency_id.symbol}${formatLang(total_balance_curr)}</div>
-                        %else:
-                            <div class="act_as_cell amount">${company.currency_id.symbol}${formatLang(total_inital_balance_curr)}</div>
-                            <div class="act_as_cell amount">${company.currency_id.symbol}${formatLang(total_tefs_curr)}</div>
-                            <div class="act_as_cell amount">${company.currency_id.symbol}${formatLang(total_checks_curr)}</div>
-                            <div class="act_as_cell amount">${company.currency_id.symbol}${formatLang(total_deposit_curr)}</div>
-                            <div class="act_as_cell amount">${company.currency_id.symbol}${formatLang(total_debit_curr)}</div>
-                            <div class="act_as_cell amount">${company.currency_id.symbol}${formatLang(total_credit_curr)}</div>
-                            <div class="act_as_cell amount">${company.currency_id.symbol}${formatLang(total_balance_curr)}</div>
-                        %endif
-                    </div>
-                </div>
-        </div>        
-            %endfor
-        
+            </div>  
+         %endfor  
+        <p style="page-break-after:always"></p>         
     </body>
 </html>

=== modified file 'l10n_cr_account_financial_report_webkit/report/account_bank_balances.py'
--- l10n_cr_account_financial_report_webkit/report/account_bank_balances.py	2012-07-03 21:28:44 +0000
+++ l10n_cr_account_financial_report_webkit/report/account_bank_balances.py	2013-02-06 22:25:24 +0000
@@ -24,6 +24,7 @@
 from tools.translate import _
 import pooler
 from datetime import datetime
+import math 
 
 from openerp.addons.account_financial_report_webkit.report.trial_balance import TrialBalanceWebkit
 from openerp.addons.account_financial_report_webkit.report.webkit_parser_header_fix import HeaderFooterTextWebKitParser
@@ -37,160 +38,333 @@
         super(account_bank_balances, self).__init__(cursor, uid, name, context=context)
         self.pool = pooler.get_pool(self.cr.dbname)
         self.cursor = self.cr   
+        
+        company = self.pool.get('res.users').browse(self.cr, uid, uid, context=context).company_id
+        header_report_name = ' - '.join((_('Account Bank Balance'), company.name, company.currency_id.name))
+        
         self.localcontext.update({
-        'get_bank_accounts': self.get_bank_accounts, 
-        'accounts_by_currency': self.accounts_by_currency,
-        'get_move_lines_account':self.get_move_lines_account,
-        'get_type_move_line':self.get_type_move_line,
-        'get_debit_account':self.get_debit_account,
-        'get_credit_account':self.get_credit_account,
-        'get_deposit_account':self.get_deposit_account,
-        'get_tefs_account':self.get_tefs_account,
-        'get_checks_account':self.get_checks_account,
+                'report_name': _('Account Bank Balance'),
+                'get_bank_accounts': self.get_bank_accounts, 
+                'accounts_by_currency': self.accounts_by_currency,
+                'get_move_lines_account': self.get_move_lines_account,
+                'get_total_move_lines': self.get_total_move_lines,
+                'get_initia_balance_accounts': self.get_initia_balance_accounts,
         })
 
-    def get_bank_accounts(self, cr, uid, objects):
+    #Change the filter by code == BKRE
+    def get_bank_accounts(self, cr, uid):
         bank_accounts = []
-        for account in objects:
-            account_usertype_id = account.user_type.id
-            account_account_type_id = self.pool.get('account.account.type').search(cr, uid, [('name', '=' ,'Banco Saldo Real')])[0]
-            if account_usertype_id == account_account_type_id:
-                bank_accounts.append(account)
+        account_account_type_id = self.pool.get('account.account.type').search(cr, uid, [('code', '=' ,'BKRE')])[0]
+        account_list_ids = self.pool.get('account.account').search(cr, uid, [('user_type.id','=',account_account_type_id)])
+        account_list = self.pool.get('account.account').browse(cr, uid, account_list_ids)
+        
+        for account in account_list:
+            bank_accounts.append(account)
+            
         return bank_accounts
 
+    #Create a dicctionary where each key is the currency and the value is a list with the accounts
+    #Return a dictionary  
+    """
+        dic = {
+                'USD': [1,2,3] -> is a object list
+                'CR' : [5,6,7]
+                } 
+    """
+    #If the currency don't exist, add as a new key for the dictionary.
+    """
+        In the mako, show the account like this.
+            for currency, account in map.iteritems()
+        Print first the currency and then, all accounts that have this currency.
+    """
     def accounts_by_currency(self, cr, uid, accounts):
-        currency_names_list = []
-        accounts_for_currency = []
-        all_accounts_by_currency = []
-
-        for current_account in accounts:
-            current_name = current_account.report_currency_id.name
-            if current_name not in currency_names_list:
-                currency_names_list.append(current_name)
-
-        for current_name in currency_names_list:
-            account_currency = []
-            for current_account in accounts:
-                if current_account.report_currency_id.name == current_name:
-                    account_currency.append(current_account)
-            accounts_for_currency.append(account_currency)
-
-        i = 0
-        for current_name in currency_names_list:
-            tup_temp = (current_name, accounts_for_currency[i])
-            all_accounts_by_currency.append(tup_temp)
-            i += 1
-
-        return all_accounts_by_currency
-
-    def get_move_lines_account(self, cr, uid, filter_type, filter_data, account):
+       account_dic = {}
+       account_list = []
+       
+       for account in accounts:
+           if account.report_currency_id.name in account_dic.keys():
+               account_list =  account_dic[account.report_currency_id.name]
+               account_list.append(account)
+               account_dic[account.report_currency_id.name] = account_list
+               account_list = []
+           else:
+               account_dic[account.report_currency_id.name] = [account]       
+              
+       return account_dic
+   
+    """
+        Use the metod get_move_lines in the object account.webkit.report.library (account_webkit_report_library module)
+    """   
+    def get_move_lines_account(self, cr, uid, account_id, filter_type, filter_data, fiscalyear,target_move): 
+        move_lines = []
+        move_lines = self.pool.get('account.webkit.report.library').get_move_lines(cr, uid, account_ids=[account_id], filter_type=filter_type, filter_data=filter_data, fiscalyear=fiscalyear, target_move=target_move)
+        
+        return move_lines
+    
+        """
+        @param account: Es la cuenta a la cual pertenenecen las lineas
+        @param account_move_lines: Son los move_lines que pertenecen a la cuenta 
+    """
+    def get_total_move_lines(self, cr, uid, account_move_lines, account):
+        
+        """
+        #TODO Translate to english
+         
+        Primero se obtiene de la linea (MLA1) su respectivo account_move (MA). Luego se buscan todos los move_lines (MLA2) asociados al move_line.
+        Se busca aquella que es diferente a MLA y se obtiene la MLA2. Con esta línea se busca la conciliación (MR) y se obtienen todas las líneas de
+        conciliación. Con estas líneas se buscan aquella donde la diferencia de montos debe ser cero o la menor diferencia. Con esa línea se obtiene
+        el move (M2) y de ahi se obtiene el journal para sumar los totales.
+            
+        """
+        amount_transf = amount_check = amount_deposit = amount_debit = amount_credit =  0.0
+        
+        """
+        #LA MONEDA DE LA COMPAÑIA COINCIDA CON LA MONEDA DE LA CUENTA QUE VIENE POR PARÁMETRO -> Si son iguales (Son colones, moneda de la compañía)
+        """
+        foreign_currency = not account.company_id.currency_id.id == account.report_currency_id.id
+
+        for line in account_move_lines:
+            temp_line = temp_line2 = None
+            no_journal = False
+                           
+            #account_move relacionado con la linea (campo de la relacion -> move_id)
+            move =  line.move_id
+            #se buscan las demás lineas asociadas al move (move_id -> line_id)
+            move_lines = move.line_id
+            
+            #si solo existe una -> move_line_final es la línea actual
+            if len(move_lines) < 2:
+                no_journal = True
+            
+            #si existen dos -> se almacena el par de la actual.
+            elif len(move_lines) == 2:
+                for move_line in move_lines:
+                    if move_line.id != line.id:
+                        temp_line = move_line
+            
+            #si son más de dos se conserva la que tenga el monto mayor.
+            else:
+                #Si son dólares se suma el amount_currency
+                if foreign_currency:
+                    amount_temp = math.fabs(line.amount_currency)
+                #si son colones -> se suman los débitos y créditos (uno de los dos es 0)
+                else:
+                    amount_temp = math.fabs(line.debit + line.credit)
+                
+                #se reccorren todas las líneas que no sean iguales a la línea
+                temp_line = line
+                for move_line in move_lines:                    
+                    if not move_line.id == line.id:
+                        #si son dolares -> se saca el valor absoluto del amount_currency y se compara con amount_temp
+                        if foreign_currency:
+                            #Se debe hacer la comparación con los valores contrarios, si el amount_currency de la linea
+                            #original es positivo, se busca su contrario.
+                            if (line.amount_currency > 0 and move_line.amount_currency < 0) or (line.amount_currency < 0 and move_line.amount_currency > 0):
+                                if math.fabs(line.amount_currency + move_line.amount_currency) <= amount_temp:
+                                    temp_line = move_line
+                                    amount_temp = math.fabs(move_line.amount_currency + line.amount_currency)
+                        else:
+                            #si son colones -> se saca el valor absoluto de la diferencia entre los debitos y los créditos de ambas lines
+                            #debe ser menor al amount_temp
+                            #Se debe buscar su contrario, positivos con negativos. La búsqueda no se hace con todos los valores.
+                            if (line.debit > 0 and move_line.credit > 0) or (line.credit > 0 and move_line.debit > 0): 
+                                if math.fabs((move_line.debit + move_line.credit) - (line.debit + line.credit)) <= amount_temp:
+                                    temp_line = move_line
+                                    amount_temp = math.fabs((move_line.debit + move_line.credit) - (line.debit + line.credit))
+            """
+            Debe cumplir ciertas condiciones para seguir el proceso. 
+                1- Debe existir el temp_line, es decir debe ser la misma línea, su línea espejo o bien la línea que cumpla el valor más aproximado
+                2- El temp_line (linea espejo) no puede ser la misma que la línea original
+                3- La línea espejo debe tener conciliación
+            """                    
+            
+            if not temp_line:
+                no_journal = True
+            elif temp_line.id == line.id:
+                no_journal = True
+            elif not temp_line.reconcile_id:
+                no_journal = True
+            
+            """
+                Si se cumplieron las condiciones anteriores entonces se puede buscar la conciliación y las líneas de conciliación correspondientes
+                temp_line corresponde a la línea espejo de la línea original (line)
+            """
+            if not no_journal:
+                #extraemos la conciliacion y las líneas de conciliación 
+                reconcile = temp_line.reconcile_id
+                move_lines = reconcile.line_id
+                
+                #si la conciliación no tiene líneas no se puede continuar el proceso.
+                if len(move_lines) < 2:
+                    no_journal = True
+                
+                #si existen sólo dos líneas de conciliación, se busca la que es diferente. 
+                elif len(move_lines) == 2:
+                    temp_line2 = temp_line
+                    for move_line in move_lines:
+                        if move_line.id != temp_line2.id:
+                            temp_line = move_line
+                
+                else:
+                    if foreign_currency:
+                        amount_temp = math.fabs(temp_line.amount_currency)
+                    else:
+                        amount_temp = math.fabs(temp_line.debit - temp_line.credit)
+                    
+                    temp_line2 = temp_line
+                    for move_line in move_lines:
+                        if not move_line.id == temp_line2.id:
+                            if foreign_currency:
+                                #las comparaciones deben hacerse con el monto opuesto (positivo con negativo)
+                                if (temp_line2.amount_currency > 0 and move_line.amount_currency < 0) or (temp_line2.amount_currency < 0 and move_line.amount_currency > 0):
+                                    if math.fabs(move_line.amount_currency + temp_line2.amount_currency) <= amount_temp:
+                                        temp_line = move_line
+                                        amount_temp = math.fabs(move_line.amount_currency + temp_line2.amount_currency)
+                            else:
+                                #las comparaciones se deben hacer con los montos opuestos, (debit - credit)
+                                if (temp_line2.debit > 0 and move_line.credit > 0) or (temp_line2.credit > 0 and move_line.debit > 0):        
+                                    if math.fabs((move_line.debit + move_line.credit) - (temp_line2.debit + temp_line2.credit)) <= amount_temp:
+                                        temp_line = move_line
+                                        amount_temp = math.fabs((move_line.debit + move_line.credit) - (temp_line2.debit + temp_line2.credit))
+                    
+                    if temp_line2.id == temp_line.id:
+                        temp_line = None                    
+                                        
+                if not temp_line or not temp_line.move_id or not temp_line.move_id.journal_id:
+                    no_journal = True
+                
+                else:
+                    #temp_line debe ser la línea de conciliación que más se acerca a la línea de conciliación
+                    #con los valores del journal, se obtienen los cálculos
+                    journal = temp_line.move_id.journal_id
+                    
+                    if journal.payment_method_customer:
+                        if foreign_currency:
+                            amount_deposit += line.amount_currency
+                        else:
+                            amount_deposit += line.debit - line.credit
+                    
+                    elif journal.payment_method_supplier:
+                        if journal.transfers:
+                            if foreign_currency:
+                                amount_transf += line.amount_currency
+                            else:
+                                amount_transf += line.debit - line.credit
+                        
+                        elif journal.check:
+                            if foreign_currency:
+                                amount_check += line.amount_currency
+                            else:
+                                amount_check += line.debit - line.credit
+                        else:
+                            no_journal = True
+                    else:
+                        no_journal = True
+            
+            #si no cumple ninguna de las condiciones anteriores, se suman los resultados a débitos y créditos. 
+            if no_journal:
+                if foreign_currency:
+                    if line.amount_currency > 0:
+                        amount_debit += line.amount_currency
+                    else:
+                        amount_credit += line.amount_currency
+                else:
+                    amount_debit += line.debit
+                    amount_credit += -1 * line.credit
+     
+        return {
+            'amount_transf' : amount_transf,
+            'amount_check' : amount_check,
+            'amount_deposit' : amount_deposit,
+            'amount_debit' : amount_debit,
+            'amount_credit' : amount_credit,
+        }
+    
+    """
+        @param accounts: cuentas para calcular el balance inicial
+        @param filter_type: tipo de filtro (filter_date, filter_period)
+        @param filter_dat: valores seleccionados en el wizard para generar el reporte
+        @param target_move : posted, all (tipo de apunte)    
+    """
+    def get_initia_balance_accounts (self, cr, uid, accounts, filter_type, filter_data, fiscalyear, target_move,chart_account_id,context={}):
+        accounts_ids = []
+       
+        #todas las cuentas ya vienen agrupadas por moneda.
+        for account in accounts:
+            accounts_ids.append(account.id)
+        
+        #si la moneda no es colones, se pide el foreign_balance. si son colones se pide el balance.
+        account_foreign_currency = accounts[0]  
+        foreign_currency = not account_foreign_currency.company_id.currency_id.id == account_foreign_currency.report_currency_id.id
+        if foreign_currency:
+            field_names = ['foreign_balance']
+        else:
+            field_names = ['balance']
+        
+        #el metodo get_account_balance devuelve un diccionario con la llave de la cuenta
+        #y el valor que se le está pidiendo, en este caso el balance inicial.        
+        if filter_type == 'filter_period':
+            #el método recibe los ids de los períodos (filtro por períodos)
+            if filter_data[0]:
+                start_period_id = filter_data[0].id
+            else:
+                start_period_id = False
+                
+            end_period_id = filter_data[1].id
+            initial_balance = self.pool.get('account.webkit.report.library').get_account_balance(cr,
+                                                                                        uid, 
+                                                                                        accounts_ids, 
+                                                                                        field_names,     
+                                                                                        initial_balance=True,                                                                                   
+                                                                                        fiscal_year_id=fiscalyear.id,                                                                                
+                                                                                        state = target_move,
+                                                                                        start_period_id = start_period_id,
+                                                                                        end_period_id = end_period_id,
+                                                                                        chart_account_id=chart_account_id,
+                                                                                        filter_type=filter_type)
+        if filter_type == 'filter_date':
+            #el método recibe las fechas (en caso de filtro por fechas)
+            start_date = filter_data[0]
+            end_date = filter_data[1]
+            initial_balance = self.pool.get('account.webkit.report.library').get_account_balance(cr, 
+                                                                                        uid, 
+                                                                                        accounts_ids, 
+                                                                                        field_names,  
+                                                                                        initial_balance=True, 
+                                                                                        fiscal_year_id=fiscalyear.id,
+                                                                                        state = target_move, 
+                                                                                        start_date = start_date,                                                                      
+                                                                                        end_date = end_date,                                                                                        
+                                                                                        chart_account_id=chart_account_id,
+                                                                                        filter_type=filter_type)
         if filter_type == '':
-            move_lines_id = self.pool.get('account.move.line').search(cr, uid, [('account_id', '=', account.id)])
-            move_lines = self.pool.get('account.move.line').browse(cr, uid, move_lines_id)
-        else:
-            if filter_type == 'filter_period':
-                periods_ids = self.pool.get('account.period').search(cr, uid, [('date_start', '>=', filter_data[0].date_start), ('date_stop', '<=', filter_data[1].date_stop)])
-                move_lines_id = self.pool.get('account.move.line').search(cr, uid, [('account_id', '=', account.id)])
-                all_move_lines = self.pool.get('account.move.line').browse(cr, uid, move_lines_id)
-                move_lines = []
-                for move_line in all_move_lines:
-                    period_id = move_line.period_id.id
-                    if period_id in periods_ids:
-                        move_lines.append(move_line)
-            elif filter_type == 'filter_date':
-                move_lines_id = self.pool.get('account.move.line').search(cr, uid, [('account_id', '=', account.id), ('date', '>=', filter_data[0]), ('date', '<=', filter_data[1])])
-                move_lines = self.pool.get('account.move.line').browse(cr, uid, move_lines_id)
-        
-
-        return move_lines
-
-    def get_type_move_line(self, cr, uid, move_line):
-        voucher_line_id = self.pool.get('account.voucher.line').search(cr, uid, [('move_line_id', '=', move_line.id)])
-        voucher_line = self.pool.get('account.voucher.line').browse(cr, uid, voucher_line_id)
-        voucher = self.pool.get('account.voucher').browse(cr, uid, voucher_line.voucher_id)
-        
-        type_move_line = voucher.type
-        return type_move_line
-
-    def get_debit_account(self, cr, uid, move_lines, currency):
-        debit = 0.0
-
-        for move_line in move_lines:
-            if currency == 'CRC':
-                debit += move_line.debit
-            elif move_line.amount_currency > 0:
-                debit += move_line.amount_currency
-
-        return debit
-
-    def get_credit_account(self, cr, uid, move_lines, currency):
-        credit = 0.0
-
-        for move_line in move_lines:
-            if currency == 'CRC':
-                credit += move_line.credit
-            elif move_line.amount_currency < 0:
-                credit += move_line.amount_currency*-1
-
-        return credit
-
-    def get_deposit_account(self, cr, uid, move_lines, currency, account):
-        deposit = 0.0
-
-        all_voucher_line_id = self.pool.get('account.voucher.line').search(cr, uid, [('account_id', '=', account.id)])
-        all_voucher_line = self.pool.get('account.voucher.line').browse(cr, uid, all_voucher_line_id)
-
-        for move_line in move_lines:
-            for voucher_line in all_voucher_line:
-                if move_line.id == voucher_line.move_line_id:
-                    if currency == 'CRC':
-                        deposit += move_line.debit
-                    elif move_line.amount_currency > 0:
-                        deposit += move_line.amount_currency
-
-        return deposit
-
-    def get_tefs_account(self, cr, uid, move_lines, currency, account):
-        tefs = 0.0
-
-        all_voucher_line_id = self.pool.get('account.voucher.line').search(cr, uid, [('account_id', '=', account.id)])
-        all_voucher_line = self.pool.get('account.voucher.line').browse(cr, uid, all_voucher_line_id)
-        vouchers = self.pool.get('account.voucher').browse(cr, uid, all_voucher_line_id)
-
-        journal_TEF = self.pool.get('account.journal').search(cr, uid, [('code', 'like', 'TEF')])
-
-        for move_line in move_lines:
-            for voucher_line in all_voucher_line:
-                if move_line.id == voucher_line.move_line_id:
-                    for voucher in vouchers:
-                        if voucher.journal_id in journal_TEF:
-                            if currency == 'CRC':
-                                tefs += move_line.credit
-                            elif move_line.amount_currency > 0:
-                                tefs += move_line.amount_currency*-1
-
-        return tefs
-
-    def get_checks_account(self, cr, uid, move_lines, currency, account):
-        checks = 0.0
-
-        all_voucher_line_id = self.pool.get('account.voucher.line').search(cr, uid, [('account_id', '=', account.id)])
-        all_voucher_line = self.pool.get('account.voucher.line').browse(cr, uid, all_voucher_line_id)
-        vouchers = self.pool.get('account.voucher').browse(cr, uid, all_voucher_line_id)
-
-        journal_CK = self.pool.get('account.journal').search(cr, uid, [('code', 'like', 'CK')])
-
-        for move_line in move_lines:
-            for voucher_line in all_voucher_line:
-                if move_line.id == voucher_line.move_line_id:
-                    for voucher in vouchers:
-                        if voucher.journal_id in journal_CK:
-                            if currency == 'CRC':
-                                checks += move_line.credit
-                            elif move_line.amount_currency > 0:
-                                checks += move_line.amount_currency*-1
-
-        return checks
+            initial_balance = self.pool.get('account.webkit.report.library').get_account_balance(cr, 
+                                                                                        uid, 
+                                                                                        accounts_ids, 
+                                                                                        field_names,  
+                                                                                        initial_balance=True, 
+                                                                                        fiscal_year_id=fiscalyear.id,
+                                                                                        state = target_move, 
+                                                                                        chart_account_id=chart_account_id,
+                                                                                        filter_type=filter_type)
+        
+        #CASO ESPECIAL PARA ESTE TIPO DE REPORTE -> FILTRO DE SOLAMENTE PERIODO DE APERTURA                                                                                        
+        if filter_type == 'filter_opening':
+            period_ids = [self.pool.get('account.period').search(cr, uid, [('fiscalyear_id','=',fiscal_year_id),('special','=',True)],order='date_start asc')[0]]
+            
+            initial_balance = self.pool.get('account.webkit.report.library').get_account_balance(cr, 
+                                                                                        uid, 
+                                                                                        accounts_ids, 
+                                                                                        field_names,  
+                                                                                        initial_balance=True, 
+                                                                                        fiscal_year_id=fiscalyear.id,
+                                                                                        state = target_move, 
+                                                                                        period_ids = period_ids,
+                                                                                        chart_account_id=chart_account_id,
+                                                                                        filter_type=filter_type)
+        
+        
+        return initial_balance
 
 HeaderFooterTextWebKitParser(
     'report.l10n_cr_account_financial_report_webkit.account.account_report_account_bank_balances_webkit',

=== modified file 'l10n_cr_account_financial_report_webkit/report/report.xml'
--- l10n_cr_account_financial_report_webkit/report/report.xml	2012-11-04 16:56:05 +0000
+++ l10n_cr_account_financial_report_webkit/report/report.xml	2013-02-06 22:25:24 +0000
@@ -43,13 +43,11 @@
              <field eval="[(6,0,[])]" name="groups_id"/>
              <field eval="0" name="multi"/>
              <field eval="0" name="auto"/>
-             <field eval="1" name="header"/>
              <field name="model">account.account</field>
              <field name="type">ir.actions.report.xml</field>
              <field name="name">Account Balances Webkit</field>
              <field name="report_rml">l10n_cr_account_financial_report_webkit/report/account_bank_balances.mako</field>
              <field name="report_file">l10n_cr_account_financial_report_webkit/report/account_bank_balances.mako</field>
-             <field name="webkit_header" ref="financial_portrait_header"/>
          </record>
 
         <record id="l10n_cr_account_financial_report_webkit.account_financial_report_webkit" model="ir.actions.report.xml">

=== modified file 'l10n_cr_account_financial_report_webkit/wizard/account_bank_balances_wizard_view.xml'
--- l10n_cr_account_financial_report_webkit/wizard/account_bank_balances_wizard_view.xml	2012-06-13 20:01:31 +0000
+++ l10n_cr_account_financial_report_webkit/wizard/account_bank_balances_wizard_view.xml	2013-02-06 22:25:24 +0000
@@ -22,20 +22,6 @@
                     <field name="chart_account_id" position='attributes'>
                         <attribute name="colspan">4</attribute>
                     </field>
-                    <page name="filters" position="after">
-                        <page string="Accounts Filters" name="accounts">
-                            <separator string="Print only" colspan="4"/>
-                            <field name="account_ids" colspan="4" nolabel="1" domain="[('type', '=', 'view')]">
-                                <tree>
-                                    <field name="code"/>
-                                    <field name="name"/>
-                                    <field name="type"/>
-                                    <field name="company_id"/>
-                                </tree>
-                            </field>
-                        </page>
-                        <page name="placeholder"/>
-                    </page>
                     <page name="journal_ids" position="attributes">
                         <attribute name="invisible">True</attribute>
                     </page>
@@ -49,7 +35,7 @@
                         <attribute name="domain">[('fiscalyear_id', '=', fiscalyear_id), ('special', '=', False)]</attribute>
                     </field>
                     <field name="fiscalyear_id" position="attributes">
-                        <attribute name="attrs">{'required': [('filter', '=', 'filter_opening')]}</attribute>
+                        <attribute name="attrs">{'required':True}</attribute>
                     </field>
                 </data>
             </field>


Follow ups