[FIX] Account : Automatic reonciliation now sorts move lines by maturity date
[odoo/odoo.git] / addons / account / wizard / account_tax_chart.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
6 #
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.
11 #
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.
16 #
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/>.
19 #
20 ##############################################################################
21
22 from osv import fields, osv
23
24 class account_tax_chart(osv.osv_memory):
25     """
26     For Chart of taxes
27     """
28     _name = "account.tax.chart"
29     _description = "Account tax chart"
30     _columns = {
31        'period_id': fields.many2one('account.period', \
32                                     'Period',  \
33                                     ),
34        'target_move': fields.selection([('all', 'All Entries'),
35                                         ('posted', 'All Posted Entries')], 'Target Moves', required=True),
36     }
37
38     def _get_period(self, cr, uid, context=None):
39         """Return default period value"""
40         period_ids = self.pool.get('account.period').find(cr, uid)
41         return period_ids and period_ids[0] or False
42
43     def account_tax_chart_open_window(self, cr, uid, ids, context=None):
44         """
45         Opens chart of Accounts
46         @param cr: the current row, from the database cursor,
47         @param uid: the current user’s ID for security checks,
48         @param ids: List of account chart’s IDs
49         @return: dictionary of Open account chart window on given fiscalyear and all Entries or posted entries
50         """
51         mod_obj = self.pool.get('ir.model.data')
52         act_obj = self.pool.get('ir.actions.act_window')
53         period_obj = self.pool.get('account.period')
54         if context is None:
55             context = {}
56         data = self.read(cr, uid, ids, [], context=context)[0]
57         result = mod_obj._get_id(cr, uid, 'account', 'action_tax_code_tree')
58         id = mod_obj.read(cr, uid, [result], ['res_id'], context=context)[0]['res_id']
59         result = act_obj.read(cr, uid, [id], context=context)[0]
60         if data['period_id']:
61             fiscalyear_id = period_obj.read(cr, uid, [data['period_id']], context=context)[0]['fiscalyear_id'][0]
62             result['context'] = str({'period_id': data['period_id'], \
63                                      'fiscalyear_id': fiscalyear_id, \
64                                         'state': data['target_move']})
65         else:
66             result['context'] = str({'state': data['target_move']})
67
68         if data['period_id']:
69             result['name'] += ':' + self.pool.get('account.period').read(cr, uid, [data['period_id']], context=context)[0]['code']
70         return result
71
72     _defaults = {
73         'period_id': _get_period,
74         'target_move': 'all'
75     }
76
77 account_tax_chart()
78
79 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: