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