2009-10-13 05:58:37 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2006-12-07 13:41:40 +00:00
|
|
|
##############################################################################
|
2009-11-30 10:24:22 +00:00
|
|
|
#
|
2009-10-14 11:15:34 +00:00
|
|
|
# OpenERP, Open Source Management Solution
|
2010-01-12 09:18:39 +00:00
|
|
|
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
2006-12-07 13:41:40 +00:00
|
|
|
#
|
2008-11-03 19:18:56 +00:00
|
|
|
# This program is free software: you can redistribute it and/or modify
|
2009-10-14 11:15:34 +00:00
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
2006-12-07 13:41:40 +00:00
|
|
|
#
|
2008-11-03 19:18:56 +00:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2009-10-14 11:15:34 +00:00
|
|
|
# GNU Affero General Public License for more details.
|
2006-12-07 13:41:40 +00:00
|
|
|
#
|
2009-10-14 11:15:34 +00:00
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
2009-11-30 10:24:22 +00:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2006-12-07 13:41:40 +00:00
|
|
|
#
|
|
|
|
##############################################################################
|
2010-08-04 07:34:06 +00:00
|
|
|
|
2006-12-07 13:41:40 +00:00
|
|
|
import time
|
|
|
|
from report import report_sxw
|
2010-08-04 07:34:06 +00:00
|
|
|
from common_report_header import common_report_header
|
2006-12-07 13:41:40 +00:00
|
|
|
|
2010-10-26 09:35:41 +00:00
|
|
|
class aged_trial_report(report_sxw.rml_parse, common_report_header):
|
2008-10-21 14:02:46 +00:00
|
|
|
|
2010-08-30 10:59:53 +00:00
|
|
|
def __init__(self, cr, uid, name, context):
|
|
|
|
super(aged_trial_report, self).__init__(cr, uid, name, context=context)
|
|
|
|
self.total_account = []
|
|
|
|
self.localcontext.update({
|
|
|
|
'time': time,
|
2010-09-07 05:55:19 +00:00
|
|
|
'get_lines_with_out_partner': self._get_lines_with_out_partner,
|
2010-08-30 10:59:53 +00:00
|
|
|
'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,
|
|
|
|
'get_partners':self._get_partners,
|
|
|
|
'get_account': self._get_account,
|
|
|
|
'get_fiscalyear': self._get_fiscalyear,
|
2010-10-04 11:31:09 +00:00
|
|
|
'get_target_move': self._get_target_move,
|
2010-08-30 10:59:53 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
def set_context(self, objects, data, ids, report_type=None):
|
2010-10-01 10:26:34 +00:00
|
|
|
obj_move = self.pool.get('account.move.line')
|
2011-01-10 11:15:33 +00:00
|
|
|
ctx = data['form'].get('used_context', {})
|
|
|
|
ctx.update({'fiscalyear': False, 'all_fiscalyear': True})
|
|
|
|
self.query = obj_move._query_get(self.cr, self.uid, obj='l', context=ctx)
|
2010-08-30 10:59:53 +00:00
|
|
|
self.direction_selection = data['form'].get('direction_selection', 'past')
|
2010-09-15 10:56:24 +00:00
|
|
|
self.target_move = data['form'].get('target_move', 'all')
|
2010-08-30 10:59:53 +00:00
|
|
|
self.date_from = data['form'].get('date_from', time.strftime('%Y-%m-%d'))
|
|
|
|
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']
|
|
|
|
return super(aged_trial_report, self).set_context(objects, data, ids, report_type=report_type)
|
|
|
|
|
|
|
|
def _get_lines(self, form):
|
|
|
|
res = []
|
2010-11-18 14:41:15 +00:00
|
|
|
move_state = ['draft','posted']
|
|
|
|
if self.target_move == 'posted':
|
|
|
|
move_state = ['posted']
|
2010-08-30 10:59:53 +00:00
|
|
|
self.cr.execute('SELECT DISTINCT res_partner.id AS id,\
|
|
|
|
res_partner.name AS name \
|
2010-11-18 14:41:15 +00:00
|
|
|
FROM res_partner,account_move_line AS l, account_account, account_move am\
|
2010-09-16 05:10:06 +00:00
|
|
|
WHERE (l.account_id=account_account.id) \
|
2010-11-18 14:41:15 +00:00
|
|
|
AND (l.move_id=am.id) \
|
|
|
|
AND (am.state IN %s)\
|
|
|
|
AND (account_account.type IN %s)\
|
|
|
|
AND account_account.active\
|
2010-08-30 10:59:53 +00:00
|
|
|
AND ((reconcile_id IS NULL)\
|
2010-11-18 14:41:15 +00:00
|
|
|
OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > %s )))\
|
2010-08-30 10:59:53 +00:00
|
|
|
AND (l.partner_id=res_partner.id)\
|
2010-11-18 14:41:15 +00:00
|
|
|
AND (l.date <= %s)\
|
2010-08-30 10:59:53 +00:00
|
|
|
AND ' + self.query + ' \
|
2010-11-18 14:41:15 +00:00
|
|
|
ORDER BY res_partner.name', (tuple(move_state), tuple(self.ACCOUNT_TYPE), self.date_from, self.date_from,))
|
2010-08-30 10:59:53 +00:00
|
|
|
partners = self.cr.dictfetchall()
|
|
|
|
## mise a 0 du total
|
|
|
|
for i in range(7):
|
|
|
|
self.total_account.append(0)
|
|
|
|
#
|
|
|
|
# Build a string like (1,2,3) for easy use in SQL query
|
|
|
|
partner_ids = [x['id'] for x in partners]
|
2010-10-09 16:01:43 +00:00
|
|
|
if not partner_ids:
|
|
|
|
return []
|
2010-08-30 10:59:53 +00:00
|
|
|
# This dictionary will store the debit-credit for all partners, using partner_id as key.
|
2010-09-16 05:37:56 +00:00
|
|
|
|
2010-08-30 10:59:53 +00:00
|
|
|
totals = {}
|
2010-09-16 05:10:06 +00:00
|
|
|
self.cr.execute('SELECT l.partner_id, SUM(l.debit-l.credit) \
|
|
|
|
FROM account_move_line AS l, account_account, account_move am \
|
|
|
|
WHERE (l.account_id = account_account.id) AND (l.move_id=am.id) \
|
|
|
|
AND (am.state IN %s)\
|
2010-08-30 10:59:53 +00:00
|
|
|
AND (account_account.type IN %s)\
|
2010-09-16 05:10:06 +00:00
|
|
|
AND (l.partner_id IN %s)\
|
|
|
|
AND ((l.reconcile_id IS NULL)\
|
|
|
|
OR (l.reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > %s )))\
|
2010-08-30 10:59:53 +00:00
|
|
|
AND ' + self.query + '\
|
|
|
|
AND account_account.active\
|
2010-11-18 14:41:15 +00:00
|
|
|
AND (l.date <= %s)\
|
|
|
|
GROUP BY l.partner_id ', (tuple(move_state), tuple(self.ACCOUNT_TYPE), tuple(partner_ids), self.date_from, self.date_from,))
|
2010-08-30 10:59:53 +00:00
|
|
|
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 self.direction_selection == 'future':
|
2010-09-16 05:10:06 +00:00
|
|
|
self.cr.execute('SELECT l.partner_id, SUM(l.debit-l.credit) \
|
|
|
|
FROM account_move_line AS l, account_account, account_move am \
|
|
|
|
WHERE (l.account_id=account_account.id) AND (l.move_id=am.id) \
|
|
|
|
AND (am.state IN %s)\
|
2010-08-30 10:59:53 +00:00
|
|
|
AND (account_account.type IN %s)\
|
2010-09-16 05:10:06 +00:00
|
|
|
AND (COALESCE(l.date_maturity, l.date) < %s)\
|
|
|
|
AND (l.partner_id IN %s)\
|
|
|
|
AND ((l.reconcile_id IS NULL)\
|
|
|
|
OR (l.reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > %s )))\
|
2010-08-30 10:59:53 +00:00
|
|
|
AND '+ self.query + '\
|
|
|
|
AND account_account.active\
|
2010-11-18 14:41:15 +00:00
|
|
|
AND (l.date <= %s)\
|
|
|
|
GROUP BY l.partner_id', (tuple(move_state), tuple(self.ACCOUNT_TYPE), self.date_from, tuple(partner_ids),self.date_from, self.date_from,))
|
2010-08-30 10:59:53 +00:00
|
|
|
t = self.cr.fetchall()
|
|
|
|
for i in t:
|
|
|
|
future_past[i[0]] = i[1]
|
|
|
|
elif self.direction_selection == 'past': # Using elif so people could extend without this breaking
|
2010-09-16 05:10:06 +00:00
|
|
|
self.cr.execute('SELECT l.partner_id, SUM(l.debit-l.credit) \
|
|
|
|
FROM account_move_line AS l, account_account, account_move am \
|
|
|
|
WHERE (l.account_id=account_account.id) AND (l.move_id=am.id)\
|
|
|
|
AND (am.state IN %s)\
|
2010-08-30 10:59:53 +00:00
|
|
|
AND (account_account.type IN %s)\
|
2010-09-16 05:10:06 +00:00
|
|
|
AND (COALESCE(l.date_maturity,l.date) > %s)\
|
|
|
|
AND (l.partner_id IN %s)\
|
|
|
|
AND ((l.reconcile_id IS NULL)\
|
|
|
|
OR (l.reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > %s )))\
|
2010-08-30 10:59:53 +00:00
|
|
|
AND '+ self.query + '\
|
|
|
|
AND account_account.active\
|
2010-11-18 14:41:15 +00:00
|
|
|
AND (l.date <= %s)\
|
|
|
|
GROUP BY l.partner_id', (tuple(move_state), tuple(self.ACCOUNT_TYPE), self.date_from, tuple(partner_ids), self.date_from, self.date_from,))
|
2010-08-30 10:59:53 +00:00
|
|
|
t = self.cr.fetchall()
|
|
|
|
for i in t:
|
|
|
|
future_past[i[0]] = i[1]
|
|
|
|
|
|
|
|
# Use one query per period and store results in history (a list variable)
|
2010-10-13 09:45:27 +00:00
|
|
|
# Each history will contain: history[1] = {'<partner_id>': <partner_debit-credit>}
|
2010-08-30 10:59:53 +00:00
|
|
|
history = []
|
|
|
|
for i in range(5):
|
2010-10-11 06:03:40 +00:00
|
|
|
args_list = (tuple(move_state), tuple(self.ACCOUNT_TYPE), tuple(partner_ids),self.date_from,)
|
2010-09-16 05:10:06 +00:00
|
|
|
dates_query = '(COALESCE(l.date_maturity,l.date)'
|
2010-09-02 14:01:19 +00:00
|
|
|
if form[str(i)]['start'] and form[str(i)]['stop']:
|
|
|
|
dates_query += ' BETWEEN %s AND %s)'
|
|
|
|
args_list += (form[str(i)]['start'], form[str(i)]['stop'])
|
|
|
|
elif form[str(i)]['start']:
|
|
|
|
dates_query += ' > %s)'
|
|
|
|
args_list += (form[str(i)]['start'],)
|
|
|
|
else:
|
|
|
|
dates_query += ' < %s)'
|
|
|
|
args_list += (form[str(i)]['stop'],)
|
2010-11-18 14:41:15 +00:00
|
|
|
args_list += (self.date_from,)
|
|
|
|
self.cr.execute('''SELECT l.partner_id, SUM(l.debit-l.credit)
|
|
|
|
FROM account_move_line AS l, account_account, account_move am
|
|
|
|
WHERE (l.account_id = account_account.id) AND (l.move_id=am.id)
|
|
|
|
AND (am.state IN %s)
|
|
|
|
AND (account_account.type IN %s)
|
|
|
|
AND (l.partner_id IN %s)
|
|
|
|
AND ((l.reconcile_id IS NULL)
|
|
|
|
OR (l.reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > %s )))
|
|
|
|
AND ''' + self.query + '''
|
|
|
|
AND account_account.active
|
|
|
|
AND ''' + dates_query + '''
|
|
|
|
AND (l.date <= %s)
|
|
|
|
GROUP BY l.partner_id''', args_list)
|
2010-08-30 10:59:53 +00:00
|
|
|
t = self.cr.fetchall()
|
|
|
|
d = {}
|
|
|
|
for i in t:
|
|
|
|
d[i[0]] = i[1]
|
|
|
|
history.append(d)
|
|
|
|
|
|
|
|
for partner in partners:
|
|
|
|
values = {}
|
|
|
|
## If choise selection is in the future
|
|
|
|
if self.direction_selection == 'future':
|
|
|
|
# Query here is replaced by one query which gets the all the partners their 'before' value
|
|
|
|
before = False
|
|
|
|
if future_past.has_key(partner['id']):
|
|
|
|
before = [ future_past[partner['id']] ]
|
|
|
|
self.total_account[6] = self.total_account[6] + (before and before[0] or 0.0)
|
|
|
|
values['direction'] = before and before[0] or 0.0
|
|
|
|
elif self.direction_selection == 'past': # Changed this so people could in the future create new direction_selections
|
|
|
|
# Query here is replaced by one query which gets the all the partners their 'after' value
|
|
|
|
after = False
|
|
|
|
if future_past.has_key(partner['id']): # Making sure this partner actually was found by the query
|
|
|
|
after = [ future_past[partner['id']] ]
|
|
|
|
|
|
|
|
self.total_account[6] = self.total_account[6] + (after and after[0] or 0.0)
|
2010-09-15 08:57:12 +00:00
|
|
|
values['direction'] = after and after[0] or 0.0
|
2010-08-30 10:59:53 +00:00
|
|
|
|
|
|
|
for i in range(5):
|
|
|
|
during = False
|
|
|
|
if history[i].has_key(partner['id']):
|
|
|
|
during = [ history[i][partner['id']] ]
|
|
|
|
# Ajout du compteur
|
|
|
|
self.total_account[(i)] = self.total_account[(i)] + (during and during[0] or 0)
|
2010-09-15 08:57:12 +00:00
|
|
|
values[str(i)] = during and during[0] or 0.0
|
2010-08-30 10:59:53 +00:00
|
|
|
total = False
|
|
|
|
if totals.has_key( partner['id'] ):
|
|
|
|
total = [ totals[partner['id']] ]
|
|
|
|
values['total'] = total and total[0] or 0.0
|
|
|
|
## Add for total
|
|
|
|
self.total_account[(i+1)] = self.total_account[(i+1)] + (total and total[0] or 0.0)
|
|
|
|
values['name'] = partner['name']
|
|
|
|
|
2010-11-18 14:41:15 +00:00
|
|
|
res.append(values)
|
2010-08-30 10:59:53 +00:00
|
|
|
|
|
|
|
total = 0.0
|
|
|
|
totals = {}
|
|
|
|
for r in res:
|
|
|
|
total += float(r['total'] or 0.0)
|
|
|
|
for i in range(5)+['direction']:
|
|
|
|
totals.setdefault(str(i), 0.0)
|
2010-09-07 05:55:19 +00:00
|
|
|
totals[str(i)] += float(r[str(i)] or 0.0)
|
|
|
|
return res
|
|
|
|
|
|
|
|
def _get_lines_with_out_partner(self, form):
|
|
|
|
res = []
|
2010-09-16 05:10:06 +00:00
|
|
|
move_state = ['draft','posted']
|
|
|
|
if self.target_move == 'posted':
|
|
|
|
move_state = ['posted']
|
|
|
|
|
2010-09-07 05:55:19 +00:00
|
|
|
## mise a 0 du total
|
|
|
|
for i in range(7):
|
|
|
|
self.total_account.append(0)
|
|
|
|
totals = {}
|
2010-09-16 05:10:06 +00:00
|
|
|
self.cr.execute('SELECT SUM(l.debit-l.credit) \
|
2010-10-11 06:03:40 +00:00
|
|
|
FROM account_move_line AS l, account_account, account_move am \
|
2010-09-16 05:10:06 +00:00
|
|
|
WHERE (l.account_id = account_account.id) AND (l.move_id=am.id)\
|
|
|
|
AND (am.state IN %s)\
|
2010-09-07 05:55:19 +00:00
|
|
|
AND (l.partner_id IS NULL)\
|
|
|
|
AND (account_account.type IN %s)\
|
2010-09-16 05:10:06 +00:00
|
|
|
AND ((l.reconcile_id IS NULL) \
|
|
|
|
OR (l.reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > %s )))\
|
2010-09-07 05:55:19 +00:00
|
|
|
AND ' + self.query + '\
|
2010-11-18 14:41:15 +00:00
|
|
|
AND (l.date <= %s)\
|
|
|
|
AND account_account.active ',(tuple(move_state), tuple(self.ACCOUNT_TYPE), self.date_from, self.date_from,))
|
2010-09-07 05:55:19 +00:00
|
|
|
t = self.cr.fetchall()
|
|
|
|
for i in t:
|
2010-09-16 09:56:42 +00:00
|
|
|
totals['Unknown Partner'] = i[0]
|
2010-09-07 05:55:19 +00:00
|
|
|
future_past = {}
|
|
|
|
if self.direction_selection == 'future':
|
2010-09-16 05:10:06 +00:00
|
|
|
self.cr.execute('SELECT SUM(l.debit-l.credit) \
|
|
|
|
FROM account_move_line AS l, account_account, account_move am\
|
|
|
|
WHERE (l.account_id=account_account.id) AND (l.move_id=am.id)\
|
|
|
|
AND (am.state IN %s)\
|
2010-09-07 05:55:19 +00:00
|
|
|
AND (l.partner_id IS NULL)\
|
|
|
|
AND (account_account.type IN %s)\
|
2010-09-16 05:10:06 +00:00
|
|
|
AND (COALESCE(l.date_maturity, l.date) < %s)\
|
|
|
|
AND ((l.reconcile_id IS NULL)\
|
|
|
|
OR (l.reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > %s )))\
|
2010-09-07 05:55:19 +00:00
|
|
|
AND '+ self.query + '\
|
2010-09-16 05:10:06 +00:00
|
|
|
AND account_account.active ', (tuple(move_state), tuple(self.ACCOUNT_TYPE), self.date_from, self.date_from))
|
2010-09-07 05:55:19 +00:00
|
|
|
t = self.cr.fetchall()
|
|
|
|
for i in t:
|
2010-09-16 09:56:42 +00:00
|
|
|
future_past['Unknown Partner'] = i[0]
|
2010-09-07 05:55:19 +00:00
|
|
|
elif self.direction_selection == 'past': # Using elif so people could extend without this breaking
|
2010-09-16 05:10:06 +00:00
|
|
|
self.cr.execute('SELECT SUM(l.debit-l.credit) \
|
|
|
|
FROM account_move_line AS l, account_account, account_move am \
|
|
|
|
WHERE (l.account_id=account_account.id) AND (l.move_id=am.id)\
|
|
|
|
AND (am.state IN %s)\
|
2010-09-07 05:55:19 +00:00
|
|
|
AND (l.partner_id IS NULL)\
|
|
|
|
AND (account_account.type IN %s)\
|
2010-09-16 05:10:06 +00:00
|
|
|
AND (COALESCE(l.date_maturity,l.date) > %s)\
|
|
|
|
AND ((l.reconcile_id IS NULL)\
|
|
|
|
OR (l.reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > %s )))\
|
2010-09-07 05:55:19 +00:00
|
|
|
AND '+ self.query + '\
|
2010-10-11 06:03:40 +00:00
|
|
|
AND account_account.active ', (tuple(move_state), tuple(self.ACCOUNT_TYPE), self.date_from, self.date_from))
|
2010-09-07 05:55:19 +00:00
|
|
|
t = self.cr.fetchall()
|
|
|
|
for i in t:
|
2010-09-16 09:56:42 +00:00
|
|
|
future_past['Unknown Partner'] = i[0]
|
2010-09-07 05:55:19 +00:00
|
|
|
history = []
|
2010-09-15 13:17:50 +00:00
|
|
|
|
2010-09-07 05:55:19 +00:00
|
|
|
for i in range(5):
|
2010-09-16 05:10:06 +00:00
|
|
|
args_list = (tuple(move_state), tuple(self.ACCOUNT_TYPE), self.date_from,)
|
|
|
|
dates_query = '(COALESCE(l.date_maturity,l.date)'
|
|
|
|
if form[str(i)]['start'] and form[str(i)]['stop']:
|
|
|
|
dates_query += ' BETWEEN %s AND %s)'
|
|
|
|
args_list += (form[str(i)]['start'], form[str(i)]['stop'])
|
|
|
|
elif form[str(i)]['start']:
|
|
|
|
dates_query += ' > %s)'
|
|
|
|
args_list += (form[str(i)]['start'],)
|
|
|
|
else:
|
|
|
|
dates_query += ' < %s)'
|
|
|
|
args_list += (form[str(i)]['stop'],)
|
2010-11-18 14:41:15 +00:00
|
|
|
args_list += (self.date_from,)
|
2010-09-16 05:10:06 +00:00
|
|
|
self.cr.execute('SELECT SUM(l.debit-l.credit)\
|
2010-10-11 06:03:40 +00:00
|
|
|
FROM account_move_line AS l, account_account, account_move am \
|
2010-09-16 05:10:06 +00:00
|
|
|
WHERE (l.account_id = account_account.id) AND (l.move_id=am.id)\
|
|
|
|
AND (am.state IN %s)\
|
2010-09-07 05:55:19 +00:00
|
|
|
AND (account_account.type IN %s)\
|
2010-09-16 05:10:06 +00:00
|
|
|
AND (l.partner_id IS NULL)\
|
|
|
|
AND ((l.reconcile_id IS NULL)\
|
|
|
|
OR (l.reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > %s )))\
|
2010-09-07 05:55:19 +00:00
|
|
|
AND '+ self.query + '\
|
2010-09-16 05:10:06 +00:00
|
|
|
AND account_account.active\
|
|
|
|
AND ' + dates_query + '\
|
2010-11-18 14:41:15 +00:00
|
|
|
AND (l.date <= %s)\
|
2010-10-11 06:03:40 +00:00
|
|
|
GROUP BY l.partner_id', args_list)
|
2010-09-07 05:55:19 +00:00
|
|
|
t = self.cr.fetchall()
|
|
|
|
d = {}
|
|
|
|
for i in t:
|
2010-09-16 09:56:42 +00:00
|
|
|
d['Unknown Partner'] = i[0]
|
2010-09-07 05:55:19 +00:00
|
|
|
history.append(d)
|
2010-09-15 10:40:15 +00:00
|
|
|
|
2010-09-07 05:55:19 +00:00
|
|
|
values = {}
|
|
|
|
if self.direction_selection == 'future':
|
|
|
|
before = False
|
2010-09-16 09:56:42 +00:00
|
|
|
if future_past.has_key('Unknown Partner'):
|
|
|
|
before = [ future_past['Unknown Partner'] ]
|
2010-09-07 05:55:19 +00:00
|
|
|
self.total_account[6] = self.total_account[6] + (before and before[0] or 0.0)
|
|
|
|
values['direction'] = before and before[0] or 0.0
|
|
|
|
elif self.direction_selection == 'past':
|
|
|
|
after = False
|
2010-09-16 09:56:42 +00:00
|
|
|
if future_past.has_key('Unknown Partner'):
|
|
|
|
after = [ future_past['Unknown Partner'] ]
|
2010-09-07 05:55:19 +00:00
|
|
|
self.total_account[6] = self.total_account[6] + (after and after[0] or 0.0)
|
2010-09-16 13:06:53 +00:00
|
|
|
values['direction'] = after and after[0] or 0.0
|
2010-09-15 10:40:15 +00:00
|
|
|
|
2010-09-07 05:55:19 +00:00
|
|
|
for i in range(5):
|
|
|
|
during = False
|
2010-09-16 09:56:42 +00:00
|
|
|
if history[i].has_key('Unknown Partner'):
|
|
|
|
during = [ history[i]['Unknown Partner'] ]
|
2010-09-07 05:55:19 +00:00
|
|
|
self.total_account[(i)] = self.total_account[(i)] + (during and during[0] or 0)
|
2010-09-16 13:06:53 +00:00
|
|
|
values[str(i)] = during and during[0] or 0.0
|
2010-09-07 05:55:19 +00:00
|
|
|
|
|
|
|
total = False
|
2010-09-16 09:56:42 +00:00
|
|
|
if totals.has_key( 'Unknown Partner' ):
|
|
|
|
total = [ totals['Unknown Partner'] ]
|
2010-09-07 05:55:19 +00:00
|
|
|
values['total'] = total and total[0] or 0.0
|
|
|
|
## Add for total
|
|
|
|
self.total_account[(i+1)] = self.total_account[(i+1)] + (total and total[0] or 0.0)
|
2010-09-16 09:56:42 +00:00
|
|
|
values['name'] = 'Unknown Partner'
|
2010-09-07 05:55:19 +00:00
|
|
|
|
|
|
|
if values['total']:
|
|
|
|
res.append(values)
|
|
|
|
|
|
|
|
total = 0.0
|
|
|
|
totals = {}
|
|
|
|
for r in res:
|
|
|
|
total += float(r['total'] or 0.0)
|
|
|
|
for i in range(5)+['direction']:
|
|
|
|
totals.setdefault(str(i), 0.0)
|
2010-08-30 10:59:53 +00:00
|
|
|
totals[str(i)] += float(r[str(i)] or 0.0)
|
|
|
|
return res
|
|
|
|
|
|
|
|
def _get_total(self,pos):
|
|
|
|
period = self.total_account[int(pos)]
|
2010-09-15 08:57:12 +00:00
|
|
|
return period or 0.0
|
2010-08-30 10:59:53 +00:00
|
|
|
|
|
|
|
def _get_direction(self,pos):
|
|
|
|
period = self.total_account[int(pos)]
|
2010-09-15 08:57:12 +00:00
|
|
|
return period or 0.0
|
2010-08-30 10:59:53 +00:00
|
|
|
|
|
|
|
def _get_for_period(self,pos):
|
|
|
|
period = self.total_account[int(pos)]
|
2010-09-15 08:57:12 +00:00
|
|
|
return period or 0.0
|
2010-08-30 10:59:53 +00:00
|
|
|
|
|
|
|
def _get_partners(self,data):
|
|
|
|
if data['form']['result_selection'] == 'customer':
|
|
|
|
return 'Receivable Accounts'
|
|
|
|
elif data['form']['result_selection'] == 'supplier':
|
|
|
|
return 'Payable Accounts'
|
|
|
|
elif data['form']['result_selection'] == 'customer_supplier':
|
|
|
|
return 'Receivable and Payable Accounts'
|
|
|
|
return ''
|
2010-08-04 09:07:47 +00:00
|
|
|
|
2008-09-22 13:42:15 +00:00
|
|
|
report_sxw.report_sxw('report.account.aged_trial_balance', 'res.partner',
|
2010-08-30 10:59:53 +00:00
|
|
|
'addons/account/report/account_aged_partner_balance.rml',parser=aged_trial_report, header="internal landscape")
|
2008-10-21 14:02:46 +00:00
|
|
|
|
2008-07-23 14:41:47 +00:00
|
|
|
|
2010-08-24 12:37:11 +00:00
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|