Hi,

I also had multi-company environment and in my case it gave error on parent 
company(still does) and now doesn't give error on subsidiary. Problem was that 
the transactions were in draft state, when the transactions were 
validated/posted than the error went away (what I gather is that if there is 
nothing to display than the error comes up), try posting the transactions and 
make sure there is data to be displayed in the report.

By the way, below are the contents of aged_trial_balance.py (accounts/reports):


import time
from operator import itemgetter
import pooler
import rml_parse
from report import report_sxw

class aged_trial_report(rml_parse.rml_parse):

    def __init__(self, cr, uid, name, context):
        super(aged_trial_report, 
self).__init__(cr, uid, name, context=context)
        self.line_query = ''
        self.total_account = []


        self.localcontext.update({
            'time': time,
            'get_lines': self._get_lines,
            'get_total': self._get_total,
            'get_direction': 
self._get_direction,
            'get_for_period': 
self._get_for_period,
            'get_company': self._get_company,
            'get_currency': 
self._get_currency,

        })


    def _get_lines(self, form):

        if (form['result_selection'] == 
'customer' ):
            self.ACCOUNT_TYPE = 
('receivable', )
        elif (form['result_selection'] == 
'supplier'):
            self.ACCOUNT_TYPE = ('payable', 
)
        else:
            self.ACCOUNT_TYPE = ('payable', 
'receivable')


        res = []
        account_move_line_obj = 
pooler.get_pool(self.cr.dbname).get('account.move.line')
        self.line_query = 
account_move_line_obj._query_get(self.cr, self.uid, obj='line',
                
context={'fiscalyear': form['fiscalyear']})
        self.cr.execute("""SELECT DISTINCT 
res_partner.id AS id,
                    
res_partner.name AS name
                FROM 
res_partner,account_move_line AS line, account_account
                WHERE 
(line.account_id=account_account.id)
                    AND 
((reconcile_id IS NULL)
                    OR 
(reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon 
WHERE recon.create_date > %s )))
                    AND 
(line.partner_id=res_partner.id)
                    AND 
(account_account.company_id = %s)
                ORDER BY 
res_partner.name""",
                
(form['date1'], form['company_id']))
        partners = self.cr.dictfetchall()
        ## mise a 0 du total
        for i in range(7):
            self.total_account.append(0)

        partner_ids = 
tuple(map(itemgetter('id'), partners))
        # This dictionary will store the debit-credit for 
all partners, using partner_id as key.
        totals = {}
        self.cr.execute("""SELECT partner_id, 
SUM(debit-credit)
                    FROM 
account_move_line AS line, account_account
                    WHERE 
(line.account_id = account_account.id)
                    AND 
(account_account.type IN %s)
                    AND 
(partner_id in %s)
                    AND 
((reconcile_id IS NULL)
                    OR 
(reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon 
WHERE recon.create_date > %s )))
                    AND 
(account_account.company_id = %s)
                    AND 
account_account.active
                    GROUP BY 
partner_id""" , (
                      
  self.ACCOUNT_TYPE, partner_ids,
                      
  form['date1'], form['company_id']))
        t = self.cr.fetchall()
        for i in t:
            totals[i[0]] = 
i[1]

        # This dictionary will store the future or past of 
all partners
        future_past = {}
        if form['direction_selection'] == 
'future':
            self.cr.execute("""SELECT 
partner_id, SUM(debit-credit)
                      
  FROM account_move_line AS line, account_account
                      
  WHERE (line.account_id=account_account.id)
                      
  AND (account_account.type IN %s)
                      
&nbsp; AND &#40;COALESCE&#40;date_maturity,date&#41; <s> %s &#41;&#41;&#41;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; AND &#40;account_account.company_id = %s&#41;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; AND account_account.active
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; GROUP BY partner_id""", &#40;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.ACCOUNT_TYPE, 
form&#91;'date1'&#93;, partner_ids,
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; form&#91;'date1'&#93;, 
form&#91;'company_id'&#93;&#41;&#41;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t = self.cr.fetchall&#40;&#41;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for i in t&#58;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
future_past&#91;i&#91;0&#93;&#93; = i&#91;1&#93;
&nbsp; &nbsp; &nbsp; &nbsp; elif form&#91;'direction_selection'&#93; == 
'past'&#58; # Using elif so people could extend without this breaking
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.cr.execute&#40;"""SELECT 
partner_id, SUM&#40;debit-credit&#41;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FROM 
account_move_line AS line, account_account
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHERE 
&#40;line.account_id=account_account.id&#41;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; AND &#40;account_account.type IN %s&#41;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; AND &#40;COALESCE&#40;date_maturity,date&#41; > %s&#41;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; AND &#40;partner_id in %s&#41;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; AND &#40;&#40;reconcile_id IS NULL&#41;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; OR &#40;reconcile_id IN &#40;SELECT recon.id FROM account_move_reconcile 
AS recon WHERE recon.create_date > %s &#41;&#41;&#41;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; AND &#40;account_account.company_id = %s&#41;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; AND account_account.active
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; GROUP BY partner_id""" , &#40;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.ACCOUNT_TYPE, 
form&#91;'date1'&#93;, partner_ids,
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; form&#91;'date1'&#93;, 
form&#91;'company_id'&#93;&#41;&#41;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t = self.cr.fetchall&#40;&#41;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for i in t&#58;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
future_past&#91;i&#91;0&#93;&#93; = i&#91;1&#93;

&nbsp; &nbsp; &nbsp; &nbsp; # Use one query per period and store results in 
history &#40;a list variable&#41;
&nbsp; &nbsp; &nbsp; &nbsp; # Each history will contain &#58; 
history&#91;1&#93; = &#123;'<partner_id>'&#58; <partner_debit>&#125;
&nbsp; &nbsp; &nbsp; &nbsp; history = &#91;&#93;
&nbsp; &nbsp; &nbsp; &nbsp; for i in range&#40;5&#41;&#58;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.cr.execute&#40;"""SELECT 
partner_id, SUM&#40;debit-credit&#41;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FROM 
account_move_line AS line, account_account
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WHERE 
&#40;line.account_id=account_account.id&#41;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; AND &#40;account_account.type IN %s&#41;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; AND &#40;COALESCE&#40;date_maturity,date&#41; BETWEEN %s AND %s&#41;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; AND &#40;partner_id in %s &#41;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; AND &#40;&#40;reconcile_id IS NULL&#41;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; OR &#40;reconcile_id IN &#40;SELECT recon.id FROM account_move_reconcile 
AS recon WHERE recon.create_date > %s &#41;&#41;&#41;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; AND &#40;account_account.company_id = %s&#41;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; AND account_account.active
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GROUP BY 
partner_id""" , &#40;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; self.ACCOUNT_TYPE, 
form&#91;str&#40;i&#41;&#93;&#91;'start'&#93;, 
form&#91;str&#40;i&#41;&#93;&#91;'stop'&#93;,
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; partner_ids 
,form&#91;'date1'&#93; ,form&#91;'company_id'&#93;&#41;&#41;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t = self.cr.fetchall&#40;&#41;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; d = &#123;&#125;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for i in t&#58;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; d&#91;i&#91;0&#93;&#93; 
= i&#91;1&#93;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; history.append&#40;d&#41;

&nbsp; &nbsp; &nbsp; &nbsp; for partner in partners&#58;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; values = &#123;&#125;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ## If choise selection is in the 
future
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if 
form&#91;'direction_selection'&#93; == 'future'&#58;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # Query here is 
replaced by one query which gets the all the partners their 'before' value
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; before = False
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if 
future_past.has_key&#40;partner&#91;'id'&#93;&#41;&#58;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; before = 
&#91; future_past&#91;partner&#91;'id'&#93;&#93; &#93;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
self.total_account&#91;6&#93; = self.total_account&#91;6&#93; + &#40;before and 
before&#91;0&#93; or 0.0&#41;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
values&#91;'direction'&#93; = before and before&#91;0&#93; or 0.0
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; elif 
form&#91;'direction_selection'&#93; == 'past'&#58; # Changed this so people 
could in the future create new direction_selections
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # Query here is 
replaced by one query which gets the all the partners their 'after' value
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; after = False
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if 
future_past.has_key&#40;partner&#91;'id'&#93;&#41;&#58; # Making sure this 
partner actually was found by the query
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; after = 
&#91; future_past&#91;partner&#91;'id'&#93;&#93; &#93;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
self.total_account&#91;6&#93; = self.total_account&#91;6&#93; + &#40;after and 
after&#91;0&#93; or 0.0&#41;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
values&#91;'direction'&#93; = after and after&#91;0&#93; or ""

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for i in range&#40;5&#41;&#58;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; during = False
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if 
history&#91;i&#93;.has_key&#40;partner&#91;'id'&#93;&#41;&#58;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; during = 
&#91; history&#91;i&#93;&#91;partner&#91;'id'&#93;&#93; &#93;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # Ajout du compteur
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
self.total_account&#91;&#40;i&#41;&#93; = 
self.total_account&#91;&#40;i&#41;&#93; + &#40;during and during&#91;0&#93; or 
0&#41;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
values&#91;str&#40;i&#41;&#93; = during and during&#91;0&#93; or ""

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; total = False
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if totals.has_key&#40; 
partner&#91;'id'&#93; &#41;&#58;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; total = &#91; 
totals&#91;partner&#91;'id'&#93;&#93; &#93;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; values&#91;'total'&#93; = total and 
total&#91;0&#93; or 0.0
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ## Add for total
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
self.total_account&#91;&#40;i+1&#41;&#93; = 
self.total_account&#91;&#40;i+1&#41;&#93; + &#40;total and total&#91;0&#93; or 
0.0&#41;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; values&#91;'name'&#93; = 
partner&#91;'name'&#93;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #t = 0.0
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #for i in 
range&#40;5&#41;+&#91;'direction'&#93;&#58;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #&nbsp; &nbsp;t+= 
float&#40;values.get&#40;str&#40;i&#41;, 0.0&#41; or 0.0&#41;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #values&#91;'total'&#93; = t

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if values&#91;'total'&#93;&#58;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
res.append&#40;values&#41;

&nbsp; &nbsp; &nbsp; &nbsp; total = 0.0
&nbsp; &nbsp; &nbsp; &nbsp; totals = &#123;&#125;
&nbsp; &nbsp; &nbsp; &nbsp; for r in res&#58;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; total += float&#40;r&#91;'total'&#93; 
or 0.0&#41;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for i in 
range&#40;5&#41;+&#91;'direction'&#93;&#58;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
totals.setdefault&#40;str&#40;i&#41;, 0.0&#41;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
totals&#91;str&#40;i&#41;&#93; += float&#40;r&#91;str&#40;i&#41;&#93; or 
0.0&#41;
&nbsp; &nbsp; &nbsp; &nbsp; return res

&nbsp; &nbsp; def _get_total&#40;self,pos&#41;&#58;
&nbsp; &nbsp; &nbsp; &nbsp; period = 
self.total_account&#91;int&#40;pos&#41;&#93;
&nbsp; &nbsp; &nbsp; &nbsp; return period

&nbsp; &nbsp; def _get_direction&#40;self,pos&#41;&#58;
&nbsp; &nbsp; &nbsp; &nbsp; period = 
self.total_account&#91;int&#40;pos&#41;&#93;
&nbsp; &nbsp; &nbsp; &nbsp; return period

&nbsp; &nbsp; def _get_for_period&#40;self,pos&#41;&#58;
&nbsp; &nbsp; &nbsp; &nbsp; period = 
self.total_account&#91;int&#40;pos&#41;&#93;
&nbsp; &nbsp; &nbsp; &nbsp; return period

&nbsp; &nbsp; def _get_company&#40;self, form&#41;&#58;
&nbsp; &nbsp; &nbsp; &nbsp; return 
pooler.get_pool&#40;self.cr.dbname&#41;.get&#40;'res.company'&#41;.browse&#40;self.cr,
 self.uid, form&#91;'company_id'&#93;&#41;.name

&nbsp; &nbsp; def _get_currency&#40;self, form&#41;&#58;
&nbsp; &nbsp; &nbsp; &nbsp; return 
pooler.get_pool&#40;self.cr.dbname&#41;.get&#40;'res.company'&#41;.browse&#40;self.cr,
 self.uid, form&#91;'company_id'&#93;&#41;.currency_id.name


report_sxw.report_sxw&#40;'report.account.aged_trial_balance', 'res.partner',
&nbsp; &nbsp; &nbsp; &nbsp; 
'addons/account/report/aged_trial_balance.rml',parser=aged_trial_report,header=False&#41;






-------------------- m2f --------------------

--
http://www.openobject.com/forum/viewtopic.php?p=59159#59159

-------------------- m2f --------------------


_______________________________________________
Tinyerp-users mailing list
http://tiny.be/mailman2/listinfo/tinyerp-users

Reply via email to