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 openerp.osv import fields, osv
26 from openerp.tools.translate import _
29 class account_aged_trial_balance(osv.osv_memory):
30 _inherit = 'account.common.partner.report'
31 _name = 'account.aged.trial.balance'
32 _description = 'Account Aged Trial balance Report'
35 'period_length':fields.integer('Period Length (days)', required=True),
36 'direction_selection': fields.selection([('past','Past'),
38 'Analysis Direction', required=True),
39 'journal_ids': fields.many2many('account.journal', 'account_aged_trial_balance_journal_rel', 'account_id', 'journal_id', 'Journals', required=True),
43 'date_from': lambda *a: time.strftime('%Y-%m-%d'),
44 'direction_selection': 'past',
47 def _print_report(self, cr, uid, ids, data, context=None):
52 data = self.pre_print_report(cr, uid, ids, data, context=context)
53 data['form'].update(self.read(cr, uid, ids, ['period_length', 'direction_selection'])[0])
55 period_length = data['form']['period_length']
57 raise osv.except_osv(_('User Error!'), _('You must set a period length greater than 0.'))
58 if not data['form']['date_from']:
59 raise osv.except_osv(_('User Error!'), _('You must set a start date.'))
61 start = datetime.strptime(data['form']['date_from'], "%Y-%m-%d")
63 if data['form']['direction_selection'] == 'past':
64 for i in range(5)[::-1]:
65 stop = start - relativedelta(days=period_length)
67 'name': (i!=0 and (str((5-(i+1)) * period_length) + '-' + str((5-i) * period_length)) or ('+'+str(4 * period_length))),
68 'stop': start.strftime('%Y-%m-%d'),
69 'start': (i!=0 and stop.strftime('%Y-%m-%d') or False),
71 start = stop - relativedelta(days=1)
74 stop = start + relativedelta(days=period_length)
76 'name': (i!=4 and str((i) * period_length)+'-' + str((i+1) * period_length) or ('+'+str(4 * period_length))),
77 'start': start.strftime('%Y-%m-%d'),
78 'stop': (i!=4 and stop.strftime('%Y-%m-%d') or False),
80 start = stop + relativedelta(days=1)
81 data['form'].update(res)
82 if data.get('form',False):
83 data['ids']=[data['form'].get('chart_account_id',False)]
84 return self.pool['report'].get_action(cr, uid, ids, 'account.report_agedpartnerbalance', data=data, context=context)
86 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: