[FIX] Corrected small problems for validation in swiss accounting
[odoo/odoo.git] / addons / l10n_ch / wizard / config.py
1 # -*- encoding: utf-8 -*-
2 #  config.py
3 #
4 #  Created by Nicolas Bessi on 12.02.09.
5 #  Copyright (c) 2010 CamptoCamp. All rights reserved.
6 #
7
8 # WARNING: This program as such is intended to be used by professional
9 # programmers who take the whole responsability of assessing all potential
10 # consequences resulting from its eventual inadequacies and bugs
11 # End users who are looking for a ready-to-use solution with commercial
12 # garantees and support are strongly adviced to contract a Free Software
13 # Service Company
14 # This program is Free Software; you can redistribute it and/or
15 # modify it under the terms of the GNU General Public License
16 # as published by the Free Software Foundation; either version 2
17 # of the License, or (at your option) any later version.
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 # GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write to the Free Software
24 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25 #
26 #
27 #  Created by Nicolas Bessi on 12.02.09.
28 #  Copyright (c) 2010 CamptoCamp. All rights reserved.
29 #
30 from osv import fields, osv
31
32
33 class TaxTemplate(osv.osv):
34     """Creat account.journal.todo class in order 
35         to add configuration wizzard"""
36
37     _name = "account.tax.template.todo"
38     
39     def _get_tax(self, cursor, uid, ctx):
40         """will find the standardtaxes"""
41         if not self.__dict__.has_key('_inner_steps') :
42             self._inner_steps = 0
43         ids = self.pool.get('account.tax.template').search( cursor, uid, [])
44         if self._inner_steps == 'done' :
45             return False
46         return ids[self._inner_steps]
47         
48
49     def _get_collected(self, cursor, uid, ctx):
50         """will find the tax tempaltes for collected"""
51         if not self.__dict__.has_key('_inner_steps') :
52             self._inner_steps = 0
53         if self._inner_steps == 'done' :
54             return False
55         ids = self.pool.get('account.tax.template').search(cursor, uid, [])
56         resid = self.pool.get('account.tax.template').browse(
57             cursor,
58             uid,
59             ids[self._inner_steps]
60         ).account_collected_id.id
61         
62         return resid
63         
64     def _get_paid(self, cursor, uid, ctx):
65         """will find the payment tax"""
66         if not self.__dict__.has_key('_inner_steps') :
67             self._inner_steps = 0
68         if self._inner_steps == 'done' :
69             return False
70         ids = self.pool.get('account.tax.template').search(cursor, uid, [])
71         resid = self.pool.get('account.tax.template').browse(
72             cursor,
73             uid,
74             ids[self._inner_steps]
75         ).account_paid_id.id
76         
77         return resid
78     
79         
80     _columns = {
81         'name': fields.many2one(
82             'account.tax.template',
83             'Tax to set',
84              readonly=True,
85              help="The tax template you are currently editing"
86         ),
87         'account_collected_id':fields.many2one(
88                                                 'account.account.template', 
89                                                 'Invoice Tax Account',
90                                                 help="You can set \
91                                                 here the invoice tax account"
92                                               ),
93         'account_paid_id':fields.many2one(
94                                             'account.account.template', 
95                                             'Refund Tax Account',
96                                             help="You can set \
97                                             here the refund tax account"
98                                           ),
99
100     }
101
102     _defaults = {
103         'name': _get_tax,
104         'account_collected_id':_get_collected,
105         'account_paid_id':_get_paid,
106         }
107     
108     def on_change_collected(self, cursor, uid, wizid, tax, account) :
109         if account :
110             self.pool.get('account.tax.template').write(
111                                             cursor,
112                                             uid, 
113                                             tax,
114                                             vals={
115                                                 'account_collected_id': account,
116                                             }
117                                         )
118     
119         
120         
121         return {}
122         
123     def on_change_paid(self, cursor, uid, wizid, tax, account) :
124         if account :
125             self.pool.get('account.tax.template').write(
126                                             cursor,
127                                             uid, 
128                                             tax,
129                                             vals={
130                                                 'account_paid_id': account,
131                                             }
132                                     )
133         return {}
134
135
136
137     def action_cancel(self, cursor, uid, ids, context=None):
138         return {
139                 'view_type': 'form',
140                 "view_mode": 'form',
141                 'res_model': 'ir.actions.configuration.wizard',
142                 'type': 'ir.actions.act_window',
143                 'target':'new',
144         }
145     
146     def action_new(self, cursor, uid, ids, context=None):
147         jids = self.pool.get('account.tax.template').search(cursor, uid, [])
148         if self._inner_steps < len(jids)-1 :
149             self._inner_steps += 1
150         else :
151             self._inner_steps = 'done'
152         return {
153                 'view_type': 'form',
154                 "view_mode": 'form',
155                 'res_model': 'account.tax.template.todo',
156                 'view_id':self.pool.get('ir.ui.view').search(
157                         cursor,
158                         uid,
159                         [('name','=','view_account_journal_form_todo')]
160                     ),
161                 'type': 'ir.actions.act_window',
162                 'target':'new',
163                }
164         
165
166 TaxTemplate()
167
168 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: