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