[CLEAN]: Removed commented codes, unnecessary spaces.
[odoo/odoo.git] / addons / account / installer.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2009 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 import time
23 import datetime
24 from dateutil.relativedelta import relativedelta
25 from os.path import join as opj
26 from operator import itemgetter
27
28 from tools.translate import _
29 from osv import fields, osv
30 import netsvc
31 import tools
32
33 class account_installer(osv.osv_memory):
34     _name = 'account.installer'
35     _inherit = 'res.config.installer'
36
37     def _get_default_accounts(self, cr, uid, context=None):
38         accounts = [{'acc_name':'Current','account_type':'bank'},
39                     {'acc_name':'Deposit','account_type':'bank'},
40                     {'acc_name':'Cash','account_type':'cash'}]
41         return accounts
42
43     def _get_charts(self, cr, uid, context=None):
44         modules = self.pool.get('ir.module.module')
45         ids = modules.search(cr, uid, [('category_id','=','Account Charts')])
46         charts = list(
47             sorted(((m.name, m.shortdesc)
48                     for m in modules.browse(cr, uid, ids)),
49                    key=itemgetter(1)))
50         charts.insert(0,('configurable','Generic Chart Of Account'))
51         return charts
52
53     _columns = {
54         # Accounting
55         'charts':fields.selection(_get_charts, 'Chart of Accounts',
56             required=False,
57             help="Installs localized accounting charts to match as closely as "
58                  "possible the accounting needs of your company based on your "
59                  "country."),
60         'date_start': fields.date('Start Date', required=True),
61         'date_stop': fields.date('End Date', required=True),
62         'period':fields.selection([('month','Monthly'), ('3months','3 Monthly')],
63                                   'Periods', required=True),
64         'bank_accounts_id': fields.one2many('account.bank.accounts.wizard', 'bank_account_id', 'Bank Accounts',required=True),
65         'sale_tax':fields.float('Sale Tax(%)'),
66         'purchase_tax':fields.float('Purchase Tax(%)')
67     }
68     _defaults = {
69         'date_start': lambda *a: time.strftime('%Y-01-01'),
70         'date_stop': lambda *a: time.strftime('%Y-12-31'),
71         'period':lambda *a:'month',
72         'sale_tax':lambda *a:0.0,
73         'purchase_tax':lambda *a:0.0,
74         'bank_accounts_id':_get_default_accounts
75     }
76
77     def on_change_tax(self, cr, uid, id, tax):
78         return{'value':{'purchase_tax':tax}}
79
80     def on_change_start_date(self, cr, uid, id, start_date):
81         if start_date:
82             start_date = datetime.datetime.strptime(start_date, "%Y-%m-%d")
83             end_date = (start_date + relativedelta(months=12)) - relativedelta(days=1)
84             return {'value':{'date_stop':end_date.strftime('%Y-%m-%d')}}
85         return {}
86
87     def generate_configurable_chart(self, cr, uid, ids, context=None):
88         obj_acc = self.pool.get('account.account')
89         obj_acc_tax = self.pool.get('account.tax')
90         obj_journal = self.pool.get('account.journal')
91         obj_sequence = self.pool.get('ir.sequence')
92         obj_acc_template = self.pool.get('account.account.template')
93         obj_fiscal_position_template = self.pool.get('account.fiscal.position.template')
94         obj_fiscal_position = self.pool.get('account.fiscal.position')
95         data_pool = self.pool.get('ir.model.data')
96         mod_obj = self.pool.get('ir.model.data')
97
98         result = mod_obj._get_id(cr, uid, 'account', 'configurable_chart_template')
99         id = mod_obj.read(cr, uid, [result], ['res_id'])[0]['res_id']
100         obj_multi = self.pool.get('account.chart.template').browse(cr, uid, id)
101
102         if context is None:
103             context = {}
104         company_id = self.pool.get('res.users').browse(cr, uid, [uid], context)[0].company_id
105         seq_journal = True
106
107         # Creating Account
108         obj_acc_root = obj_multi.account_root_id
109         tax_code_root_id = obj_multi.tax_code_root_id.id
110
111         #new code
112         acc_template_ref = {}
113         tax_template_ref = {}
114         tax_code_template_ref = {}
115         todo_dict = {}
116
117         #create all the tax code
118         children_tax_code_template = self.pool.get('account.tax.code.template').search(cr, uid, [('parent_id','child_of',[tax_code_root_id])], order='id')
119         children_tax_code_template.sort()
120         for tax_code_template in self.pool.get('account.tax.code.template').browse(cr, uid, children_tax_code_template):
121             vals={
122                 'name': (tax_code_root_id == tax_code_template.id) and company_id.name or tax_code_template.name,
123                 'code': tax_code_template.code,
124                 'info': tax_code_template.info,
125                 'parent_id': tax_code_template.parent_id and ((tax_code_template.parent_id.id in tax_code_template_ref) and tax_code_template_ref[tax_code_template.parent_id.id]) or False,
126                 'company_id': company_id.id,
127                 'sign': tax_code_template.sign,
128             }
129             new_tax_code = self.pool.get('account.tax.code').create(cr, uid, vals)
130             #recording the new tax code to do the mapping
131             tax_code_template_ref[tax_code_template.id] = new_tax_code
132
133         #create all the tax
134         for tax in obj_multi.tax_template_ids:
135             #create it
136             vals_tax = {
137                 'name':tax.name,
138                 'sequence': tax.sequence,
139                 'amount':tax.amount,
140                 'type':tax.type,
141                 'applicable_type': tax.applicable_type,
142                 'domain':tax.domain,
143                 'parent_id': tax.parent_id and ((tax.parent_id.id in tax_template_ref) and tax_template_ref[tax.parent_id.id]) or False,
144                 'child_depend': tax.child_depend,
145                 'python_compute': tax.python_compute,
146                 'python_compute_inv': tax.python_compute_inv,
147                 'python_applicable': tax.python_applicable,
148                 'tax_group':tax.tax_group,
149                 'base_code_id': tax.base_code_id and ((tax.base_code_id.id in tax_code_template_ref) and tax_code_template_ref[tax.base_code_id.id]) or False,
150                 'tax_code_id': tax.tax_code_id and ((tax.tax_code_id.id in tax_code_template_ref) and tax_code_template_ref[tax.tax_code_id.id]) or False,
151                 'base_sign': tax.base_sign,
152                 'tax_sign': tax.tax_sign,
153                 'ref_base_code_id': tax.ref_base_code_id and ((tax.ref_base_code_id.id in tax_code_template_ref) and tax_code_template_ref[tax.ref_base_code_id.id]) or False,
154                 'ref_tax_code_id': tax.ref_tax_code_id and ((tax.ref_tax_code_id.id in tax_code_template_ref) and tax_code_template_ref[tax.ref_tax_code_id.id]) or False,
155                 'ref_base_sign': tax.ref_base_sign,
156                 'ref_tax_sign': tax.ref_tax_sign,
157                 'include_base_amount': tax.include_base_amount,
158                 'description':tax.description,
159                 'company_id': company_id.id,
160                 'type_tax_use': tax.type_tax_use
161             }
162             new_tax = obj_acc_tax.create(cr, uid, vals_tax)
163             #as the accounts have not been created yet, we have to wait before filling these fields
164             todo_dict[new_tax] = {
165                 'account_collected_id': tax.account_collected_id and tax.account_collected_id.id or False,
166                 'account_paid_id': tax.account_paid_id and tax.account_paid_id.id or False,
167             }
168             tax_template_ref[tax.id] = new_tax
169
170         #deactivate the parent_store functionnality on account_account for rapidity purpose
171         self.pool._init = True
172
173         children_acc_template = obj_acc_template.search(cr, uid, [('parent_id','child_of',[obj_acc_root.id]),('nocreate','!=',True)])
174         children_acc_template.sort()
175         for account_template in obj_acc_template.browse(cr, uid, children_acc_template):
176             tax_ids = []
177             for tax in account_template.tax_ids:
178                 tax_ids.append(tax_template_ref[tax.id])
179             #create the account_account
180
181             dig = 6
182             code_main = account_template.code and len(account_template.code) or 0
183             code_acc = account_template.code or ''
184             if code_main>0 and code_main<=dig and account_template.type != 'view':
185                 code_acc=str(code_acc) + (str('0'*(dig-code_main)))
186             vals={
187                 'name': (obj_acc_root.id == account_template.id) and company_id.name or account_template.name,
188                 #'sign': account_template.sign,
189                 'currency_id': account_template.currency_id and account_template.currency_id.id or False,
190                 'code': code_acc,
191                 'type': account_template.type,
192                 'user_type': account_template.user_type and account_template.user_type.id or False,
193                 'reconcile': account_template.reconcile,
194                 'shortcut': account_template.shortcut,
195                 'note': account_template.note,
196                 'parent_id': account_template.parent_id and ((account_template.parent_id.id in acc_template_ref) and acc_template_ref[account_template.parent_id.id]) or False,
197                 'tax_ids': [(6,0,tax_ids)],
198                 'company_id': company_id.id,
199             }
200             new_account = obj_acc.create(cr, uid, vals)
201             acc_template_ref[account_template.id] = new_account
202             if account_template.name == 'Bank Current Account':
203                 view_id_cash = self.pool.get('account.journal.view').search(cr,uid,[('name','=','Bank/Cash Journal View')])[0] #why fixed name here?
204                 view_id_cur = self.pool.get('account.journal.view').search(cr,uid,[('name','=','Bank/Cash Journal (Multi-Currency) View')])[0] #Why Fixed name here?
205                 ref_acc_bank = obj_multi.bank_account_view_id
206
207                 cash_result = mod_obj._get_id(cr, uid, 'account', 'conf_account_type_cash')
208                 cash_type_id = mod_obj.read(cr, uid, [cash_result], ['res_id'])[0]['res_id']
209
210                 bank_result = mod_obj._get_id(cr, uid, 'account', 'conf_account_type_bnk')
211                 bank_type_id = mod_obj.read(cr, uid, [bank_result], ['res_id'])[0]['res_id']
212
213                 check_result = mod_obj._get_id(cr, uid, 'account', 'conf_account_type_chk')
214                 check_type_id = mod_obj.read(cr, uid, [check_result], ['res_id'])[0]['res_id']
215
216                 record = self.browse(cr, uid, ids, context=context)[0]
217                 code_cnt = 1
218                 vals_seq = {
219                         'name': _('Bank Journal '),
220                         'code': 'account.journal',
221                         'prefix': 'BAN/',
222                         'padding': 5
223                         }
224                 seq_id = obj_sequence.create(cr,uid,vals_seq)
225
226                 #create the bank journals
227                 vals_journal = {}
228                 vals_journal['name']= _('Bank Journal ')
229                 vals_journal['code']= _('BNK')
230                 vals_journal['sequence_id'] = seq_id
231                 vals_journal['type'] = 'cash'
232                 if vals.get('currency_id', False):
233                     vals_journal['view_id'] = view_id_cur
234                     vals_journal['currency'] = vals.get('currency_id', False)
235                 else:
236                     vals_journal['view_id'] = view_id_cash
237                 vals_journal['default_credit_account_id'] = new_account
238                 vals_journal['default_debit_account_id'] = new_account
239                 obj_journal.create(cr,uid,vals_journal)
240
241                 for val in record.bank_accounts_id:
242                     seq_prefix = None
243                     seq_padding = 5
244                     if val.account_type == 'cash':
245                         type = cash_type_id
246                         seq_prefix = "CSH/"
247                     elif val.account_type == 'bank':
248                         type = bank_type_id
249                         seq_prefix = "BAN/"
250                     elif val.account_type == 'check':
251                         type = check_type_id
252                         seq_prefix = "CHK/"
253                     else: 
254                         type = check_type_id
255                         seq_padding = None
256                         
257                     vals_bnk = {'name': val.acc_name or '',
258                         'currency_id': val.currency_id.id or False,
259                         'code': str(110400 + code_cnt),
260                         'type': 'other',
261                         'user_type': type,
262                         'parent_id':new_account,
263                         'company_id': company_id.id }
264                     child_bnk_acc = obj_acc.create(cr, uid, vals_bnk)
265                     vals_seq_child = {
266                         'name': _(vals_bnk['name']),
267                         'code': 'account.journal',
268                         'prefix': seq_prefix,
269                         'padding': seq_padding
270                         }
271                     seq_id = obj_sequence.create(cr, uid, vals_seq_child)
272
273                     #create the bank journal
274                     vals_journal = {}
275                     vals_journal['name']= vals_bnk['name'] + ' Journal'
276                     vals_journal['code']= _(vals_bnk['name'][:3])
277                     vals_journal['sequence_id'] = seq_id
278                     vals_journal['type'] = 'cash'
279                     if vals.get('currency_id', False):
280                         vals_journal['view_id'] = view_id_cur
281                         vals_journal['currency'] = vals_bnk.get('currency_id', False)
282                     else:
283                         vals_journal['view_id'] = view_id_cash
284                     vals_journal['default_credit_account_id'] = child_bnk_acc
285                     vals_journal['default_debit_account_id'] = child_bnk_acc
286                     obj_journal.create(cr,uid,vals_journal)
287                     code_cnt += 1
288
289
290         #reactivate the parent_store functionality on account_account
291         self.pool._init = False
292         self.pool.get('account.account')._parent_store_compute(cr)
293
294         for key,value in todo_dict.items():
295             if value['account_collected_id'] or value['account_paid_id']:
296                 obj_acc_tax.write(cr, uid, [key], {
297                     'account_collected_id': acc_template_ref[value['account_collected_id']],
298                     'account_paid_id': acc_template_ref[value['account_paid_id']],
299                 })
300
301         # Creating Journals Sales and Purchase
302         vals_journal={}
303         data_id = mod_obj.search(cr, uid, [('model','=','account.journal.view'), ('name','=','account_sp_journal_view')])
304         data = mod_obj.browse(cr, uid, data_id[0])
305         view_id = data.res_id
306
307         seq_id = obj_sequence.search(cr,uid,[('name','=','Account Journal')])[0]
308
309         if seq_journal:
310             seq_sale = {
311                         'name': 'Sale Journal',
312                         'code': 'account.journal',
313                         'prefix': 'INV/',
314                         'padding': 4
315                         }
316             seq_id_sale = obj_sequence.create(cr, uid, seq_sale)
317             seq_purchase = {
318                         'name': 'Purchase Journal',
319                         'code': 'account.journal',
320                         'prefix': 'VEN/',
321                         'padding': 4
322                         }
323             seq_id_purchase = obj_sequence.create(cr, uid, seq_purchase)
324         else:
325             seq_id_sale = seq_id
326             seq_id_purchase = seq_id
327
328         vals_journal['view_id'] = view_id
329
330         #Sales Journal
331         vals_journal['name'] = _('Sales Journal')
332         vals_journal['type'] = 'sale'
333         vals_journal['code'] = _('SAJ')
334         vals_journal['sequence_id'] = seq_id_sale
335
336         if obj_multi.property_account_receivable:
337             vals_journal['default_credit_account_id'] = acc_template_ref[obj_multi.property_account_income_categ.id]
338             vals_journal['default_debit_account_id'] = acc_template_ref[obj_multi.property_account_income_categ.id]
339
340         obj_journal.create(cr,uid,vals_journal)
341
342         # Purchase Journal
343         vals_journal['name'] = _('Purchase Journal')
344         vals_journal['type'] = 'purchase'
345         vals_journal['code'] = _('EXJ')
346         vals_journal['sequence_id'] = seq_id_purchase
347
348         if obj_multi.property_account_payable:
349             vals_journal['default_credit_account_id'] = acc_template_ref[obj_multi.property_account_expense_categ.id]
350             vals_journal['default_debit_account_id'] = acc_template_ref[obj_multi.property_account_expense_categ.id]
351
352         obj_journal.create(cr,uid,vals_journal)
353         
354         # Creating Journals Sales Refund and Purchase Refund
355         vals_journal={}
356         data_id = mod_obj.search(cr, uid, [('model','=','account.journal.view'), ('name','=','account_sp_refund_journal_view')])
357         data = mod_obj.browse(cr, uid, data_id[0])
358         view_id = data.res_id
359
360         seq_id_sale_refund = seq_id_sale
361         seq_id_purchase_refund = seq_id_purchase
362
363         vals_journal['view_id'] = view_id
364
365         #Sales Refund Journal
366         vals_journal['name'] = _('Sales Refund Journal')
367         vals_journal['type'] = 'sale_refund'
368         vals_journal['code'] = _('SCNJ')
369         vals_journal['sequence_id'] = seq_id_sale_refund
370
371         if obj_multi.property_account_receivable:
372             vals_journal['default_credit_account_id'] = acc_template_ref[obj_multi.property_account_income_categ.id]
373             vals_journal['default_debit_account_id'] = acc_template_ref[obj_multi.property_account_income_categ.id]
374
375         obj_journal.create(cr,uid,vals_journal)
376
377         # Purchase Refund Journal
378         vals_journal['name'] = _('Purchase Refund Journal')
379         vals_journal['type'] = 'purchase_refund'
380         vals_journal['code'] = _('ECNJ')
381         vals_journal['sequence_id'] = seq_id_purchase_refund
382
383         if obj_multi.property_account_payable:
384             vals_journal['default_credit_account_id'] = acc_template_ref[obj_multi.property_account_expense_categ.id]
385             vals_journal['default_debit_account_id'] = acc_template_ref[obj_multi.property_account_expense_categ.id]
386
387         obj_journal.create(cr,uid,vals_journal)
388         
389         # Bank Journals
390         view_id_cash = self.pool.get('account.journal.view').search(cr, uid, [('name','=','Bank/Cash Journal View')])[0] #TOFIX: Why put fixed name ?
391         view_id_cur = self.pool.get('account.journal.view').search(cr, uid, [('name','=','Bank/Cash Journal (Multi-Currency) View')])[0] #TOFIX: why put fixed name?
392         ref_acc_bank = obj_multi.bank_account_view_id
393
394
395         #create the properties
396         property_obj = self.pool.get('ir.property')
397         fields_obj = self.pool.get('ir.model.fields')
398
399         todo_list = [
400             ('property_account_receivable','res.partner','account.account'),
401             ('property_account_payable','res.partner','account.account'),
402             ('property_account_expense_categ','product.category','account.account'),
403             ('property_account_income_categ','product.category','account.account'),
404             ('property_account_expense','product.template','account.account'),
405             ('property_account_income','product.template','account.account'),
406             ('property_reserve_and_surplus_account','res.company','account.account'),
407         ]
408
409         for record in todo_list:
410             r = []
411             r = property_obj.search(cr, uid, [('name','=', record[0] ),('company_id','=',company_id.id)])
412             account = getattr(obj_multi, record[0])
413             field = fields_obj.search(cr, uid, [('name','=',record[0]),('model','=',record[1]),('relation','=',record[2])])
414             vals = {
415                 'name': record[0],
416                 'company_id': company_id.id,
417                 'fields_id': field[0],
418                 'value': account and 'account.account,'+str(acc_template_ref[account.id]) or False,
419             }
420
421             if r:
422                 #the property exist: modify it
423                 property_obj.write(cr, uid, r, vals)
424             else:
425                 #create the property
426                 property_obj.create(cr, uid, vals)
427
428         fp_ids = obj_fiscal_position_template.search(cr, uid,[('chart_template_id', '=', obj_multi.id)])
429
430         if fp_ids:
431             for position in obj_fiscal_position_template.browse(cr, uid, fp_ids):
432
433                 vals_fp = {
434                            'company_id' : company_id.id,
435                            'name' : position.name,
436                            }
437                 new_fp = obj_fiscal_position.create(cr, uid, vals_fp)
438
439                 obj_tax_fp = self.pool.get('account.fiscal.position.tax')
440                 obj_ac_fp = self.pool.get('account.fiscal.position.account')
441
442                 for tax in position.tax_ids:
443                     vals_tax = {
444                                 'tax_src_id' : tax_template_ref[tax.tax_src_id.id],
445                                 'tax_dest_id' : tax.tax_dest_id and tax_template_ref[tax.tax_dest_id.id] or False,
446                                 'position_id' : new_fp,
447                                 }
448                     obj_tax_fp.create(cr, uid, vals_tax)
449
450                 for acc in position.account_ids:
451                     vals_acc = {
452                                 'account_src_id' : acc_template_ref[acc.account_src_id.id],
453                                 'account_dest_id' : acc_template_ref[acc.account_dest_id.id],
454                                 'position_id' : new_fp,
455                                 }
456                     obj_ac_fp.create(cr, uid, vals_acc)
457
458     def execute(self, cr, uid, ids, context=None):
459         if context is None:
460             context = {}
461         data_pool = self.pool.get('ir.model.data')
462         obj_acc = self.pool.get('account.account')
463         super(account_installer, self).execute(cr, uid, ids, context=context)
464         record = self.browse(cr, uid, ids, context=context)[0]
465         company_id = self.pool.get('res.users').browse(cr, uid, [uid], context)[0].company_id
466         for res in self.read(cr, uid, ids):
467             if record.charts == 'configurable':
468                 mod_obj = self.pool.get('ir.model.data')
469                 fp = tools.file_open(opj('account','configurable_account_chart.xml'))
470                 tools.convert_xml_import(cr, 'account', fp, {}, 'init',True, None)
471                 fp.close()
472                 self.generate_configurable_chart(cr, uid, ids, context=context)
473                 obj_tax = self.pool.get('account.tax')
474                 obj_product = self.pool.get('product.product')
475                 ir_values = self.pool.get('ir.values')
476                 s_tax = (res.get('sale_tax',0.0))/100
477                 p_tax = (res.get('purchase_tax',0.0))/100
478                 tax_val = {}
479                 default_tax = []
480
481                 pur_tax_parent = mod_obj._get_id(cr, uid, 'account', 'tax_code_base_purchases')
482                 pur_tax_parent_id = mod_obj.read(cr, uid, [pur_tax_parent], ['res_id'])[0]['res_id']
483
484                 sal_tax_parent = mod_obj._get_id(cr, uid, 'account', 'tax_code_base_sales')
485                 sal_tax_parent_id = mod_obj.read(cr, uid, [sal_tax_parent], ['res_id'])[0]['res_id']
486
487                 if s_tax*100 > 0.0:
488                     vals_tax_code = {
489                         'name': 'TAX%s%%'%(s_tax*100),
490                         'code': 'TAX%s%%'%(s_tax*100),
491                         'company_id': company_id.id,
492                         'sign': 1,
493                         'parent_id':sal_tax_parent_id
494                         }
495                     new_tax_code = self.pool.get('account.tax.code').create(cr, uid, vals_tax_code)
496                     sales_tax = obj_tax.create(cr, uid,
497                                            {'name':'TAX%s%%'%(s_tax*100),
498                                             'description':'TAX%s%%'%(s_tax*100),
499                                             'amount':s_tax,
500                                             'base_code_id':new_tax_code,
501                                             'tax_code_id':new_tax_code,
502                                             'type_tax_use':'sale'
503                                             })
504                     tax_val.update({'taxes_id':[(6,0,[sales_tax])]})
505                     default_tax.append(('taxes_id',sales_tax))
506                 if p_tax*100 > 0.0:
507                     vals_tax_code = {
508                         'name': 'TAX%s%%'%(p_tax*100),
509                         'code': 'TAX%s%%'%(p_tax*100),
510                         'company_id': company_id.id,
511                         'sign': 1,
512                         'parent_id':pur_tax_parent_id
513                         }
514                     new_tax_code = self.pool.get('account.tax.code').create(cr, uid, vals_tax_code)
515                     purchase_tax = obj_tax.create(cr, uid,
516                                             {'name':'TAX%s%%'%(p_tax*100),
517                                              'description':'TAX%s%%'%(p_tax*100),
518                                              'amount':p_tax,
519                                              'base_code_id':new_tax_code,
520                                             'tax_code_id':new_tax_code,
521                                             'type_tax_use':'purchase'
522                                              })
523                     tax_val.update({'supplier_taxes_id':[(6,0,[purchase_tax])]})
524                     default_tax.append(('supplier_taxes_id',purchase_tax))
525                 if len(tax_val):
526                     product_ids = obj_product.search(cr, uid, [])
527                     for product in obj_product.browse(cr, uid, product_ids):
528                         obj_product.write(cr, uid, product.id, tax_val)
529                     for name, value in default_tax:
530                         ir_values.set(cr, uid, key='default', key2=False, name=name, models =[('product.product',False)], value=[value])
531
532             if 'date_start' in res and 'date_stop' in res:
533                 name = code = res['date_start'][:4]
534                 if int(name) != int(res['date_stop'][:4]):
535                     name = res['date_start'][:4] +'-'+ res['date_stop'][:4]
536                     code = res['date_start'][2:4] +'-'+ res['date_stop'][2:4]
537                 res_obj = self.pool.get('account.fiscalyear')
538                 vals = {'name':name,
539                         'code':code,
540                         'date_start':res['date_start'],
541                         'date_stop':res['date_stop'],
542                        }
543                 period_id = res_obj.create(cr, uid, vals, context=context)
544                 if res['period'] == 'month':
545                     res_obj.create_period(cr, uid, [period_id])
546                 elif res['period'] == '3months':
547                     res_obj.create_period3(cr, uid, [period_id])
548         
549 #        #fially inactive the demo chart of accounts
550 #        data_id = data_pool.search(cr, uid, [('model','=','account.account'), ('name','=','chart0')])
551 #        if data_id:
552 #            data = data_pool.browse(cr, uid, data_id[0])
553 #            account_id = data.res_id
554 #            acc_ids = obj_acc._get_children_and_consol(cr, uid, [account_id])
555 #            if acc_ids:
556 #                cr.execute("update account_account set active='f' where id in " + str(tuple(acc_ids)))
557
558     def modules_to_install(self, cr, uid, ids, context=None):
559         modules = super(account_installer, self).modules_to_install(
560             cr, uid, ids, context=context)
561         chart = self.read(cr, uid, ids, ['charts'],
562                           context=context)[0]['charts']
563         self.logger.notifyChannel(
564             'installer', netsvc.LOG_DEBUG,
565             'Installing chart of accounts %s'%chart)
566         return modules | set([chart])
567
568 account_installer()
569
570 class account_bank_accounts_wizard(osv.osv_memory):
571     _name='account.bank.accounts.wizard'
572
573     _columns = {
574         'acc_name': fields.char('Account Name.', size=64, required=True),
575         'bank_account_id': fields.many2one('wizard.multi.charts.accounts', 'Bank Account', required=True),
576         'currency_id': fields.many2one('res.currency', 'Currency'),
577         'account_type': fields.selection([('cash','Cash'),('check','Check'),('bank','Bank')], 'Type', size=32),
578     }
579     _defaults = {
580         'currency_id': lambda self,cr,uid,c: self.pool.get('res.users').browse(cr, uid, uid, c).company_id.currency_id.id,
581         }
582
583 account_bank_accounts_wizard()
584
585 class account_installer_modules(osv.osv_memory):
586     _name = 'account.installer.modules'
587     _inherit = 'res.config.installer'
588     _columns = {
589         # Accounting
590         'account_analytic_plans':fields.boolean('Multiple Analytic Plans',
591             help="Allows invoice lines to impact multiple analytic accounts "
592                  "simultaneously."),
593         'account_payment':fields.boolean('Suppliers Payment Management',
594             help="Streamlines invoice payment and creates hooks to plug "
595                  "automated payment systems in."),
596         'account_followup':fields.boolean('Followups Management',
597             help="Helps you generate reminder letters for unpaid invoices, "
598                  "including multiple levels of reminding and customized "
599                  "per-partner policies."),
600         'account_voucher':fields.boolean('Voucher Management',
601             help="Account Voucher module includes all the basic requirements of "
602                  "Voucher Entries for Bank, Cash, Sales, Purchase, Expanse, Contra, etc... "),
603         'account_voucher_payment':fields.boolean('Voucher and Reconcile Management',
604             help="Extension Account Voucher module includes allows to link payment / receipt "
605                  "entries with voucher, also automatically reconcile during the payment and receipt entries."),
606                  }
607
608 account_installer_modules()
609
610 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: