1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
23 from datetime import datetime
24 from dateutil.relativedelta import relativedelta
25 from osv import osv, fields
26 from tools.translate import _
28 class account_aged_trial_balance(osv.osv_memory):
29 _inherit = 'account.common.partner.report'
30 _name = 'account.aged.trial.balance'
31 _description = 'Account Aged Trial balance Report'
34 'period_length':fields.integer('Period Length (days)', required=True),
35 'direction_selection': fields.selection([('past','Past'),
37 'Analysis Direction', required=True),
38 'journal_ids': fields.many2many('account.journal', 'account_aged_trial_balance_journal_rel', 'account_id', 'journal_id', 'Journals', required=True),
42 'date_from': lambda *a: time.strftime('%Y-%m-%d'),
43 'direction_selection': 'past',
46 def _print_report(self, cr, uid, ids, data, context=None):
51 data = self.pre_print_report(cr, uid, ids, data, context=context)
52 data['form'].update(self.read(cr, uid, ids, ['period_length', 'direction_selection'])[0])
54 period_length = data['form']['period_length']
56 raise osv.except_osv(_('User Error!'), _('You must set a period length greater than 0.'))
57 if not data['form']['date_from']:
58 raise osv.except_osv(_('User Error!'), _('You must set a start date.'))
60 start = datetime.strptime(data['form']['date_from'], "%Y-%m-%d")
62 if data['form']['direction_selection'] == 'past':
63 for i in range(5)[::-1]:
64 stop = start - relativedelta(days=period_length)
66 'name': (i!=0 and (str((5-(i+1)) * period_length) + '-' + str((5-i) * period_length)) or ('+'+str(4 * period_length))),
67 'stop': start.strftime('%Y-%m-%d'),
68 'start': (i!=0 and stop.strftime('%Y-%m-%d') or False),
70 start = stop - relativedelta(days=1)
73 stop = start + relativedelta(days=period_length)
75 'name': (i!=4 and str((i) * period_length)+'-' + str((i+1) * period_length) or ('+'+str(4 * period_length))),
76 'start': start.strftime('%Y-%m-%d'),
77 'stop': (i!=4 and stop.strftime('%Y-%m-%d') or False),
79 start = stop + relativedelta(days=1)
80 data['form'].update(res)
81 if data.get('form',False):
82 data['ids']=[data['form'].get('chart_account_id',False)]
84 'type': 'ir.actions.report.xml',
85 'report_name': 'account.aged_trial_balance',
89 account_aged_trial_balance()
91 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: