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 ##############################################################################
22 from osv import fields, osv
24 class account_chart(osv.osv_memory):
28 _name = "account.chart"
29 _description = "Account chart"
31 'fiscalyear': fields.many2one('account.fiscalyear', \
33 help = 'Keep empty for all open fiscal years'),
34 'period_from': fields.many2one('account.period', 'Start period'),
35 'period_to': fields.many2one('account.period', 'End period'),
36 'target_move': fields.selection([('posted', 'All Posted Entries'),
37 ('all', 'All Entries'),
38 ], 'Target Moves', required = True),
41 def onchange_fiscalyear(self, cr, uid, ids, fiscalyear_id=False, context=None):
45 start_period = end_period = False
47 SELECT * FROM (SELECT p.id
49 LEFT JOIN account_fiscalyear f ON (p.fiscalyear_id = f.id)
51 ORDER BY p.date_start ASC
52 LIMIT 1) AS period_start
54 SELECT * FROM (SELECT p.id
56 LEFT JOIN account_fiscalyear f ON (p.fiscalyear_id = f.id)
58 AND p.date_start < NOW()
59 ORDER BY p.date_stop DESC
60 LIMIT 1) AS period_stop''', (fiscalyear_id, fiscalyear_id))
61 periods = [i[0] for i in cr.fetchall()]
62 if periods and len(periods) > 1:
63 start_period = periods[0]
64 end_period = periods[1]
65 res['value'] = {'period_from': start_period, 'period_to': end_period}
68 def account_chart_open_window(self, cr, uid, ids, context=None):
70 Opens chart of Accounts
71 @param cr: the current row, from the database cursor,
72 @param uid: the current user’s ID for security checks,
73 @param ids: List of account chart’s IDs
74 @return: dictionary of Open account chart window on given fiscalyear and all Entries or posted entries
76 mod_obj = self.pool.get('ir.model.data')
77 act_obj = self.pool.get('ir.actions.act_window')
78 period_obj = self.pool.get('account.period')
79 fy_obj = self.pool.get('account.fiscalyear')
82 data = self.read(cr, uid, ids, [], context=context)[0]
83 result = mod_obj.get_object_reference(cr, uid, 'account', 'action_account_tree')
84 id = result and result[1] or False
85 result = act_obj.read(cr, uid, [id], context=context)[0]
86 result['periods'] = []
87 if data['period_from'] and data['period_to']:
88 result['periods'] = period_obj.build_ctx_periods(cr, uid, data['period_from'], data['period_to'])
89 result['context'] = str({'fiscalyear': data['fiscalyear'], 'periods': result['periods'], \
90 'state': data['target_move']})
91 if data['fiscalyear']:
92 result['name'] += ':' + fy_obj.read(cr, uid, [data['fiscalyear']], context=context)[0]['code']
96 'target_move': 'posted'
101 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: