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 openerp.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 _get_fiscalyear(self, cr, uid, context=None):
42 """Return default Fiscalyear value"""
43 return self.pool.get('account.fiscalyear').find(cr, uid, context=context)
45 def onchange_fiscalyear(self, cr, uid, ids, fiscalyear_id=False, context=None):
48 start_period = end_period = False
50 SELECT * FROM (SELECT p.id
52 LEFT JOIN account_fiscalyear f ON (p.fiscalyear_id = f.id)
54 ORDER BY p.date_start ASC
55 LIMIT 1) AS period_start
57 SELECT * FROM (SELECT p.id
59 LEFT JOIN account_fiscalyear f ON (p.fiscalyear_id = f.id)
61 AND p.date_start < NOW()
62 ORDER BY p.date_stop DESC
63 LIMIT 1) AS period_stop''', (fiscalyear_id, fiscalyear_id))
64 periods = [i[0] for i in cr.fetchall()]
65 if periods and len(periods) > 1:
66 start_period = periods[0]
67 end_period = periods[1]
68 res['value'] = {'period_from': start_period, 'period_to': end_period}
70 res['value'] = {'period_from': False, 'period_to': False}
73 def account_chart_open_window(self, cr, uid, ids, context=None):
75 Opens chart of Accounts
76 @param cr: the current row, from the database cursor,
77 @param uid: the current user’s ID for security checks,
78 @param ids: List of account chart’s IDs
79 @return: dictionary of Open account chart window on given fiscalyear and all Entries or posted entries
81 mod_obj = self.pool.get('ir.model.data')
82 act_obj = self.pool.get('ir.actions.act_window')
83 period_obj = self.pool.get('account.period')
84 fy_obj = self.pool.get('account.fiscalyear')
87 data = self.read(cr, uid, ids, [], context=context)[0]
88 result = mod_obj.get_object_reference(cr, uid, 'account', 'action_account_tree')
89 id = result and result[1] or False
90 result = act_obj.read(cr, uid, [id], context=context)[0]
91 fiscalyear_id = data.get('fiscalyear', False) and data['fiscalyear'][0] or False
92 result['periods'] = []
93 if data['period_from'] and data['period_to']:
94 period_from = data.get('period_from', False) and data['period_from'][0] or False
95 period_to = data.get('period_to', False) and data['period_to'][0] or False
96 result['periods'] = period_obj.build_ctx_periods(cr, uid, period_from, period_to)
97 result['context'] = str({'fiscalyear': fiscalyear_id, 'periods': result['periods'], \
98 'state': data['target_move']})
100 result['name'] += ':' + fy_obj.read(cr, uid, [fiscalyear_id], context=context)[0]['code']
104 'target_move': 'posted',
105 'fiscalyear': _get_fiscalyear,
110 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: