1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
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.
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.
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/>.
20 ##############################################################################
24 from dateutil.relativedelta import relativedelta
25 from os.path import join as opj
26 from operator import itemgetter
28 from tools.translate import _
29 from osv import fields, osv
33 class account_installer(osv.osv_memory):
34 _name = 'account.installer'
35 _inherit = 'res.config.installer'
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'}]
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')], context=context)
47 sorted(((m.name, m.shortdesc)
48 for m in modules.browse(cr, uid, ids)),
50 charts.insert(0, ('configurable', 'Generic Chart Of Account'))
55 'charts': fields.selection(_get_charts, 'Chart of Accounts',
57 help="Installs localized accounting charts to match as closely as "
58 "possible the accounting needs of your company based on your "
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')], 'Periods', required=True),
63 'bank_accounts_id': fields.one2many('account.bank.accounts.wizard', 'bank_account_id', 'Your Bank and Cash Accounts'),
64 'sale_tax': fields.float('Sale Tax(%)'),
65 'purchase_tax': fields.float('Purchase Tax(%)'),
66 'company_id': fields.many2one('res.company', 'Company'),
69 def _default_company(self, cr, uid, context=None):
70 user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
71 return user.company_id and user.company_id.id or False
73 def _get_default_charts(self, cr, uid, context=None):
75 company_id = self._default_company(cr, uid, context=context)
76 company = self.pool.get('res.company').browse(cr, uid, company_id, context=context)
77 address_id = self.pool.get('res.partner').address_get(cr, uid, [company.partner_id.id])
78 if address_id['default']:
79 address = self.pool.get('res.partner.address').browse(cr, uid, address_id['default'], context=context)
80 code = address.country_id.code
81 module_name = (code and 'l10n_' + code.lower()) or False
83 module_id = self.pool.get('ir.module.module').search(cr, uid, [('name', '=', module_name)], context=context)
89 'date_start': time.strftime('%Y-01-01'),
90 'date_stop': time.strftime('%Y-12-31'),
94 'company_id': _default_company,
95 'bank_accounts_id': _get_default_accounts,
96 'charts': _get_default_charts
99 def on_change_tax(self, cr, uid, id, tax):
100 return {'value': {'purchase_tax': tax}}
102 def on_change_start_date(self, cr, uid, id, start_date=False):
104 start_date = datetime.datetime.strptime(start_date, "%Y-%m-%d")
105 end_date = (start_date + relativedelta(months=12)) - relativedelta(days=1)
106 return {'value': {'date_stop': end_date.strftime('%Y-%m-%d')}}
109 def generate_configurable_chart(self, cr, uid, ids, context=None):
110 obj_acc = self.pool.get('account.account')
111 obj_acc_tax = self.pool.get('account.tax')
112 obj_journal = self.pool.get('account.journal')
113 obj_acc_tax_code = self.pool.get('account.tax.code')
114 obj_acc_template = self.pool.get('account.account.template')
115 obj_acc_tax_template = self.pool.get('account.tax.code.template')
116 obj_fiscal_position_template = self.pool.get('account.fiscal.position.template')
117 obj_fiscal_position = self.pool.get('account.fiscal.position')
118 analytic_journal_obj = self.pool.get('account.analytic.journal')
119 obj_acc_chart_template = self.pool.get('account.chart.template')
120 obj_acc_journal_view = self.pool.get('account.journal.view')
121 mod_obj = self.pool.get('ir.model.data')
122 obj_sequence = self.pool.get('ir.sequence')
123 property_obj = self.pool.get('ir.property')
124 fields_obj = self.pool.get('ir.model.fields')
125 obj_tax_fp = self.pool.get('account.fiscal.position.tax')
126 obj_ac_fp = self.pool.get('account.fiscal.position.account')
128 result = mod_obj.get_object_reference(cr, uid, 'account', 'configurable_chart_template')
129 id = result and result[1] or False
130 obj_multi = obj_acc_chart_template.browse(cr, uid, id, context=context)
132 record = self.browse(cr, uid, ids, context=context)[0]
136 company_id = self.browse(cr, uid, ids, context=context)[0].company_id
140 obj_acc_root = obj_multi.account_root_id
141 tax_code_root_id = obj_multi.tax_code_root_id.id
144 acc_template_ref = {}
145 tax_template_ref = {}
146 tax_code_template_ref = {}
149 #create all the tax code
150 children_tax_code_template = obj_acc_tax_template.search(cr, uid, [('parent_id', 'child_of', [tax_code_root_id])], order='id')
151 children_tax_code_template.sort()
152 for tax_code_template in obj_acc_tax_template.browse(cr, uid, children_tax_code_template, context=context):
154 'name': (tax_code_root_id == tax_code_template.id) and company_id.name or tax_code_template.name,
155 'code': tax_code_template.code,
156 'info': tax_code_template.info,
157 '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,
158 'company_id': company_id.id,
159 'sign': tax_code_template.sign,
161 new_tax_code = obj_acc_tax_code.create(cr, uid, vals, context=context)
162 #recording the new tax code to do the mapping
163 tax_code_template_ref[tax_code_template.id] = new_tax_code
166 for tax in obj_multi.tax_template_ids:
170 'sequence': tax.sequence,
171 'amount': tax.amount,
173 'applicable_type': tax.applicable_type,
174 'domain': tax.domain,
175 'parent_id': tax.parent_id and ((tax.parent_id.id in tax_template_ref) and tax_template_ref[tax.parent_id.id]) or False,
176 'child_depend': tax.child_depend,
177 'python_compute': tax.python_compute,
178 'python_compute_inv': tax.python_compute_inv,
179 'python_applicable': tax.python_applicable,
180 '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,
181 '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,
182 'base_sign': tax.base_sign,
183 'tax_sign': tax.tax_sign,
184 '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,
185 '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,
186 'ref_base_sign': tax.ref_base_sign,
187 'ref_tax_sign': tax.ref_tax_sign,
188 'include_base_amount': tax.include_base_amount,
189 'description': tax.description,
190 'company_id': company_id.id,
191 'type_tax_use': tax.type_tax_use
193 new_tax = obj_acc_tax.create(cr, uid, vals_tax, context=context)
194 #as the accounts have not been created yet, we have to wait before filling these fields
195 todo_dict[new_tax] = {
196 'account_collected_id': tax.account_collected_id and tax.account_collected_id.id or False,
197 'account_paid_id': tax.account_paid_id and tax.account_paid_id.id or False,
199 tax_template_ref[tax.id] = new_tax
201 #deactivate the parent_store functionnality on account_account for rapidity purpose
202 self.pool._init = True
204 children_acc_template = obj_acc_template.search(cr, uid, [('parent_id', 'child_of', [obj_acc_root.id]), ('nocreate', '!=', True)], context=context)
205 children_acc_template.sort()
206 for account_template in obj_acc_template.browse(cr, uid, children_acc_template, context=context):
208 for tax in account_template.tax_ids:
209 tax_ids.append(tax_template_ref[tax.id])
210 #create the account_account
213 code_main = account_template.code and len(account_template.code) or 0
214 code_acc = account_template.code or ''
215 if code_main > 0 and code_main <= dig and account_template.type != 'view':
216 code_acc = str(code_acc) + (str('0'*(dig-code_main)))
218 'name': (obj_acc_root.id == account_template.id) and company_id.name or account_template.name,
219 #'sign': account_template.sign,
220 'currency_id': account_template.currency_id and account_template.currency_id.id or False,
222 'type': account_template.type,
223 'user_type': account_template.user_type and account_template.user_type.id or False,
224 'reconcile': account_template.reconcile,
225 'shortcut': account_template.shortcut,
226 'note': account_template.note,
227 '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,
228 'tax_ids': [(6, 0, tax_ids)],
229 'company_id': company_id.id,
231 new_account = obj_acc.create(cr, uid, vals, context=context)
232 acc_template_ref[account_template.id] = new_account
233 if account_template.name == 'Bank Current Account':
235 'name': 'Bank Accounts',
238 'user_type': account_template.parent_id.user_type and account_template.user_type.id or False,
239 'shortcut': account_template.shortcut,
240 'note': account_template.note,
241 '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,
242 'tax_ids': [(6,0,tax_ids)],
243 'company_id': company_id.id,
245 bank_account = obj_acc.create(cr, uid, b_vals, context=context)
248 view_id_cash = obj_acc_journal_view.search(cr, uid, [('name', '=', 'Bank/Cash Journal View')], context=context)[0] #why fixed name here?
249 view_id_cur = obj_acc_journal_view.search(cr, uid, [('name', '=', 'Bank/Cash Journal (Multi-Currency) View')], context=context)[0] #Why Fixed name here?
251 cash_result = mod_obj.get_object_reference(cr, uid, 'account', 'conf_account_type_cash')
252 cash_type_id = cash_result and cash_result[1] or False
254 bank_result = mod_obj.get_object_reference(cr, uid, 'account', 'conf_account_type_bnk')
255 bank_type_id = bank_result and bank_result[1] or False
257 check_result = mod_obj.get_object_reference(cr, uid, 'account', 'conf_account_type_chk')
258 check_type_id = check_result and check_result[1] or False
260 # record = self.browse(cr, uid, ids, context=context)[0]
263 'name': _('Bank Journal '),
264 'code': 'account.journal',
265 'prefix': 'BNK/%(year)s/',
266 'company_id': company_id.id,
269 seq_id = obj_sequence.create(cr, uid, vals_seq, context=context)
271 #create the bank journals
272 analitical_bank_ids = analytic_journal_obj.search(cr, uid, [('type', '=', 'situation')], context=context)
273 analitical_journal_bank = analitical_bank_ids and analitical_bank_ids[0] or False
275 'name': _('Bank Journal '),
277 'sequence_id': seq_id,
279 'company_id': company_id.id,
280 'analytic_journal_id': analitical_journal_bank
282 if vals.get('currency_id', False):
283 vals_journal.update({
284 'view_id': view_id_cur,
285 'currency': vals.get('currency_id', False)
288 vals_journal.update({'view_id': view_id_cash})
289 vals_journal.update({
290 'default_credit_account_id': new_account,
291 'default_debit_account_id': new_account,
293 obj_journal.create(cr, uid, vals_journal, context=context)
295 for val in record.bank_accounts_id:
297 if val.account_type == 'cash':
299 elif val.account_type == 'bank':
301 elif val.account_type == 'check':
308 'name': val.acc_name or '',
309 'currency_id': val.currency_id.id or False,
310 'code': str(110500 + code_cnt),
313 'parent_id': bank_account,
314 'company_id': company_id.id
316 child_bnk_acc = obj_acc.create(cr, uid, vals_bnk, context=context)
318 'name': _(vals_bnk['name'] + ' ' + 'Journal'),
319 'code': 'account.journal',
320 'prefix': _((vals_bnk['name'][:3].upper()) + '/%(year)s/'),
321 'padding': seq_padding
323 seq_id = obj_sequence.create(cr, uid, vals_seq_child, context=context)
325 #create the bank journal
328 'name': vals_bnk['name'] + _(' Journal'),
329 'code': _(vals_bnk['name'][:3]).upper(),
330 'sequence_id': seq_id,
332 'company_id': company_id.id
334 if vals.get('currency_id', False):
335 vals_journal.update({
336 'view_id': view_id_cur,
337 'currency': vals_bnk.get('currency_id', False),
340 vals_journal.update({'view_id': view_id_cash})
341 vals_journal.update({
342 'default_credit_account_id': child_bnk_acc,
343 'default_debit_account_id': child_bnk_acc,
344 'analytic_journal_id': analitical_journal_bank
346 obj_journal.create(cr, uid, vals_journal, context=context)
349 #reactivate the parent_store functionality on account_account
350 self.pool._init = False
351 obj_acc._parent_store_compute(cr)
353 for key, value in todo_dict.items():
354 if value['account_collected_id'] or value['account_paid_id']:
355 obj_acc_tax.write(cr, uid, [key], {
356 'account_collected_id': acc_template_ref[value['account_collected_id']],
357 'account_paid_id': acc_template_ref[value['account_paid_id']],
360 # Creating Journals Sales and Purchase
362 data_id = mod_obj.search(cr, uid, [('model', '=', 'account.journal.view'), ('name', '=', 'account_sp_journal_view')], context=context)
363 data = mod_obj.browse(cr, uid, data_id[0], context=context)
364 view_id = data.res_id
365 seq_id = obj_sequence.search(cr,uid,[('name', '=', 'Account Journal')], context=context)[0]
369 'name': 'Sale Journal',
370 'code': 'account.journal',
371 'prefix': 'SAJ/%(year)s/',
373 'company_id': company_id.id
375 seq_id_sale = obj_sequence.create(cr, uid, seq_sale, context=context)
377 'name': 'Purchase Journal',
378 'code': 'account.journal',
379 'prefix': 'EXJ/%(year)s/',
381 'company_id': company_id.id
383 seq_id_purchase = obj_sequence.create(cr, uid, seq_purchase, context=context)
385 'name': 'Sales Refund Journal',
386 'code': 'account.journal',
387 'prefix': 'SCNJ/%(year)s/',
389 'company_id': company_id.id
391 seq_id_sale_refund = obj_sequence.create(cr, uid, seq_refund_sale, context=context)
392 seq_refund_purchase = {
393 'name': 'Purchase Refund Journal',
394 'code': 'account.journal',
395 'prefix': 'ECNJ/%(year)s/',
397 'company_id': company_id.id
399 seq_id_purchase_refund = obj_sequence.create(cr, uid, seq_refund_purchase, context=context)
402 seq_id_purchase = seq_id
403 seq_id_sale_refund = seq_id
404 seq_id_purchase_refund = seq_id
406 vals_journal['view_id'] = view_id
409 analitical_sale_ids = analytic_journal_obj.search(cr, uid, [('type','=','sale')], context=context)
410 analitical_journal_sale = analitical_sale_ids and analitical_sale_ids[0] or False
412 vals_journal.update({
413 'name': _('Sales Journal'),
416 'sequence_id': seq_id_sale,
417 'analytic_journal_id': analitical_journal_sale,
418 'company_id': company_id.id
421 if obj_multi.property_account_receivable:
422 vals_journal.update({
423 'default_credit_account_id': acc_template_ref[obj_multi.property_account_income_categ.id],
424 'default_debit_account_id': acc_template_ref[obj_multi.property_account_income_categ.id],
426 obj_journal.create(cr, uid, vals_journal, context=context)
429 analitical_purchase_ids = analytic_journal_obj.search(cr, uid, [('type', '=', 'purchase')], context=context)
430 analitical_journal_purchase = analitical_purchase_ids and analitical_purchase_ids[0] or False
432 vals_journal.update({
433 'name': _('Purchase Journal'),
436 'sequence_id': seq_id_purchase,
437 'analytic_journal_id': analitical_journal_purchase,
438 'company_id': company_id.id
441 if obj_multi.property_account_payable:
442 vals_journal.update({
443 'default_credit_account_id': acc_template_ref[obj_multi.property_account_expense_categ.id],
444 'default_debit_account_id': acc_template_ref[obj_multi.property_account_expense_categ.id]
447 obj_journal.create(cr, uid, vals_journal, context=context)
448 # Creating Journals Sales Refund and Purchase Refund
450 data_id = mod_obj.search(cr, uid, [('model', '=', 'account.journal.view'), ('name', '=', 'account_sp_refund_journal_view')], context=context)
451 data = mod_obj.browse(cr, uid, data_id[0], context=context)
452 view_id = data.res_id
454 #Sales Refund Journal
457 'name': _('Sales Refund Journal'),
458 'type': 'sale_refund',
459 'refund_journal': True,
461 'sequence_id': seq_id_sale_refund,
462 'analytic_journal_id': analitical_journal_sale,
463 'company_id': company_id.id
465 if obj_multi.property_account_receivable:
466 vals_journal.update({
467 'default_credit_account_id': acc_template_ref[obj_multi.property_account_income_categ.id],
468 'default_debit_account_id': acc_template_ref[obj_multi.property_account_income_categ.id]
471 obj_journal.create(cr, uid, vals_journal, context=context)
473 # Purchase Refund Journal
476 'name': _('Purchase Refund Journal'),
477 'type': 'purchase_refund',
478 'refund_journal': True,
480 'sequence_id': seq_id_purchase_refund,
481 'analytic_journal_id': analitical_journal_purchase,
482 'company_id': company_id.id
485 if obj_multi.property_account_payable:
486 vals_journal.update({
487 'default_credit_account_id': acc_template_ref[obj_multi.property_account_expense_categ.id],
488 'default_debit_account_id': acc_template_ref[obj_multi.property_account_expense_categ.id]
490 obj_journal.create(cr, uid, vals_journal, context=context)
493 view_id_cash = obj_acc_journal_view.search(cr, uid, [('name', '=', 'Bank/Cash Journal View')], context=context)[0] #TOFIX: Why put fixed name ?
494 view_id_cur = obj_acc_journal_view.search(cr, uid, [('name', '=', 'Bank/Cash Journal (Multi-Currency) View')], context=context)[0] #TOFIX: why put fixed name?
496 #create the properties
498 ('property_account_receivable', 'res.partner', 'account.account'),
499 ('property_account_payable', 'res.partner', 'account.account'),
500 ('property_account_expense_categ', 'product.category', 'account.account'),
501 ('property_account_income_categ', 'product.category', 'account.account'),
502 ('property_account_expense', 'product.template', 'account.account'),
503 ('property_account_income', 'product.template', 'account.account'),
504 ('property_reserve_and_surplus_account', 'res.company', 'account.account'),
507 for record in todo_list:
509 r = property_obj.search(cr, uid, [('name', '=', record[0]), ('company_id', '=', company_id.id)], context=context)
510 account = getattr(obj_multi, record[0])
511 field = fields_obj.search(cr, uid, [('name', '=', record[0]), ('model', '=', record[1]), ('relation', '=', record[2])], context=context)
514 'company_id': company_id.id,
515 'fields_id': field[0],
516 'value': account and 'account.account, '+str(acc_template_ref[account.id]) or False,
519 #the property exist: modify it
520 property_obj.write(cr, uid, r, vals, context=context)
523 property_obj.create(cr, uid, vals, context=context)
525 fp_ids = obj_fiscal_position_template.search(cr, uid, [('chart_template_id', '=', obj_multi.id)], context=context)
527 for position in obj_fiscal_position_template.browse(cr, uid, fp_ids, context=context):
529 'company_id': company_id.id,
530 'name': position.name,
532 new_fp = obj_fiscal_position.create(cr, uid, vals_fp, context=context)
533 for tax in position.tax_ids:
535 'tax_src_id': tax_template_ref[tax.tax_src_id.id],
536 'tax_dest_id': tax.tax_dest_id and tax_template_ref[tax.tax_dest_id.id] or False,
537 'position_id': new_fp,
539 obj_tax_fp.create(cr, uid, vals_tax, context=context)
541 for acc in position.account_ids:
543 'account_src_id': acc_template_ref[acc.account_src_id.id],
544 'account_dest_id': acc_template_ref[acc.account_dest_id.id],
545 'position_id': new_fp,
547 obj_ac_fp.create(cr, uid, vals_acc, context=context)
549 def execute(self, cr, uid, ids, context=None):
552 fy_obj = self.pool.get('account.fiscalyear')
553 mod_obj = self.pool.get('ir.model.data')
554 obj_acc = self.pool.get('account.account')
555 obj_tax_code = self.pool.get('account.tax.code')
556 obj_temp_tax_code = self.pool.get('account.tax.code.template')
557 obj_tax = self.pool.get('account.tax')
558 obj_product = self.pool.get('product.product')
559 ir_values = self.pool.get('ir.values')
560 super(account_installer, self).execute(cr, uid, ids, context=context)
561 record = self.browse(cr, uid, ids, context=context)[0]
562 company_id = record.company_id
563 for res in self.read(cr, uid, ids, context=context):
564 if record.charts == 'configurable':
565 fp = tools.file_open(opj('account', 'configurable_account_chart.xml'))
566 tools.convert_xml_import(cr, 'account', fp, {}, 'init', True, None)
568 self.generate_configurable_chart(cr, uid, ids, context=context)
569 s_tax = (res.get('sale_tax', 0.0))/100
570 p_tax = (res.get('purchase_tax', 0.0))/100
574 pur_temp_tax = mod_obj.get_object_reference(cr, uid, 'account', 'tax_code_base_purchases')
575 pur_temp_tax_id = pur_temp_tax and pur_temp_tax[1] or False
577 pur_temp_tax_names = obj_temp_tax_code.read(cr, uid, [pur_temp_tax_id], ['name'], context=context)
578 pur_tax_parent_name = pur_temp_tax_names and pur_temp_tax_names[0]['name'] or False
579 pur_taxcode_parent_id = obj_tax_code.search(cr, uid, [('name', 'ilike', pur_tax_parent_name)], context=context)
580 if pur_taxcode_parent_id:
581 pur_taxcode_parent_id = pur_taxcode_parent_id[0]
583 pur_taxcode_parent_id = False
584 pur_temp_tax_paid = mod_obj.get_object_reference(cr, uid, 'account', 'tax_code_input')
585 pur_temp_tax_paid_id = pur_temp_tax_paid and pur_temp_tax_paid[1] or False
586 pur_temp_tax_paid_names = obj_temp_tax_code.read(cr, uid, [pur_temp_tax_paid_id], ['name'], context=context)
587 pur_tax_paid_parent_name = pur_temp_tax_names and pur_temp_tax_paid_names[0]['name'] or False
588 pur_taxcode_paid_parent_id = obj_tax_code.search(cr, uid, [('name', 'ilike', pur_tax_paid_parent_name)], context=context)
589 if pur_taxcode_paid_parent_id:
590 pur_taxcode_paid_parent_id = pur_taxcode_paid_parent_id[0]
592 pur_taxcode_paid_parent_id = False
594 sale_temp_tax = mod_obj.get_object_reference(cr, uid, 'account', 'tax_code_base_sales')
595 sale_temp_tax_id = sale_temp_tax and sale_temp_tax[1] or False
596 sale_temp_tax_names = obj_temp_tax_code.read(cr, uid, [sale_temp_tax_id], ['name'], context=context)
597 sale_tax_parent_name = sale_temp_tax_names and sale_temp_tax_names[0]['name'] or False
598 sale_taxcode_parent_id = obj_tax_code.search(cr, uid, [('name', 'ilike', sale_tax_parent_name)], context=context)
599 if sale_taxcode_parent_id:
600 sale_taxcode_parent_id = sale_taxcode_parent_id[0]
602 sale_taxcode_parent_id = False
604 sale_temp_tax_paid = mod_obj.get_object_reference(cr, uid, 'account', 'tax_code_output')
605 sale_temp_tax_paid_id = sale_temp_tax_paid and sale_temp_tax_paid[1] or False
606 sale_temp_tax_paid_names = obj_temp_tax_code.read(cr, uid, [sale_temp_tax_paid_id], ['name'], context=context)
607 sale_tax_paid_parent_name = sale_temp_tax_paid_names and sale_temp_tax_paid_names[0]['name'] or False
608 sale_taxcode_paid_parent_id = obj_tax_code.search(cr, uid, [('name', 'ilike', sale_tax_paid_parent_name)], context=context)
609 if sale_taxcode_paid_parent_id:
610 sale_taxcode_paid_parent_id = sale_taxcode_paid_parent_id[0]
612 sale_taxcode_paid_parent_id = False
615 tax_account_ids = obj_acc.search(cr, uid, [('name', '=', 'Tax Received')], context=context)
616 sales_tax_account_id = tax_account_ids and tax_account_ids[0] or False
618 'name': 'TAX%s%%'%(s_tax*100),
619 'code': 'TAX%s%%'%(s_tax*100),
620 'company_id': company_id.id,
622 'parent_id': sale_taxcode_parent_id
624 new_tax_code = obj_tax_code.create(cr, uid, vals_tax_code, context=context)
626 vals_paid_tax_code = {
627 'name': 'TAX Received %s%%'%(s_tax*100),
628 'code': 'TAX Received %s%%'%(s_tax*100),
629 'company_id': company_id.id,
631 'parent_id': sale_taxcode_paid_parent_id
633 new_paid_tax_code = obj_tax_code.create(cr, uid, vals_paid_tax_code, context=context)
635 sales_tax = obj_tax.create(cr, uid,
636 {'name': 'TAX %s%%'%(s_tax*100),
638 'base_code_id': new_tax_code,
639 'tax_code_id': new_paid_tax_code,
640 'type_tax_use': 'sale',
641 'account_collected_id': sales_tax_account_id,
642 'account_paid_id': sales_tax_account_id
644 default_account_ids = obj_acc.search(cr, uid, [('name', '=', 'Product Sales')], context=context)
645 if default_account_ids:
646 obj_acc.write(cr, uid, default_account_ids, {'tax_ids': [(6, 0, [sales_tax])]}, context=context)
647 tax_val.update({'taxes_id': [(6, 0, [sales_tax])]})
648 default_tax.append(('taxes_id', sales_tax))
650 tax_account_ids = obj_acc.search(cr, uid, [('name', '=', 'Tax Paid')], context=context)
651 purchase_tax_account_id = tax_account_ids and tax_account_ids[0] or False
653 'name': 'TAX%s%%'%(p_tax*100),
654 'code': 'TAX%s%%'%(p_tax*100),
655 'company_id': company_id.id,
657 'parent_id': pur_taxcode_parent_id
659 new_tax_code = obj_tax_code.create(cr, uid, vals_tax_code, context=context)
660 vals_paid_tax_code = {
661 'name': 'TAX Paid %s%%'%(p_tax*100),
662 'code': 'TAX Paid %s%%'%(p_tax*100),
663 'company_id': company_id.id,
665 'parent_id': pur_taxcode_paid_parent_id
667 new_paid_tax_code = obj_tax_code.create(cr, uid, vals_paid_tax_code, context=context)
669 purchase_tax = obj_tax.create(cr, uid,
670 {'name': 'TAX%s%%'%(p_tax*100),
671 'description': 'TAX%s%%'%(p_tax*100),
673 'base_code_id': new_tax_code,
674 'tax_code_id': new_paid_tax_code,
675 'type_tax_use': 'purchase',
676 'account_collected_id': purchase_tax_account_id,
677 'account_paid_id': purchase_tax_account_id
679 default_account_ids = obj_acc.search(cr, uid, [('name', '=', 'Expenses')], context=context)
680 if default_account_ids:
681 obj_acc.write(cr, uid, default_account_ids, {'tax_ids': [(6, 0, [purchase_tax])]}, context=context)
682 tax_val.update({'supplier_taxes_id': [(6 ,0, [purchase_tax])]})
683 default_tax.append(('supplier_taxes_id', purchase_tax))
685 product_ids = obj_product.search(cr, uid, [], context=context)
686 for product in obj_product.browse(cr, uid, product_ids, context=context):
687 obj_product.write(cr, uid, product.id, tax_val, context=context)
688 for name, value in default_tax:
689 ir_values.set(cr, uid, key='default', key2=False, name=name, models =[('product.product', False)], value=[value])
691 if 'date_start' in res and 'date_stop' in res:
692 f_ids = fy_obj.search(cr, uid, [('date_start', '<=', res['date_start']), ('date_stop', '>=', res['date_stop']), ('company_id', '=', res['company_id'])], context=context)
694 name = code = res['date_start'][:4]
695 if int(name) != int(res['date_stop'][:4]):
696 name = res['date_start'][:4] +'-'+ res['date_stop'][:4]
697 code = res['date_start'][2:4] +'-'+ res['date_stop'][2:4]
701 'date_start': res['date_start'],
702 'date_stop': res['date_stop'],
703 'company_id': res['company_id']
705 fiscal_id = fy_obj.create(cr, uid, vals, context=context)
706 if res['period'] == 'month':
707 fy_obj.create_period(cr, uid, [fiscal_id])
708 elif res['period'] == '3months':
709 fy_obj.create_period3(cr, uid, [fiscal_id])
712 def modules_to_install(self, cr, uid, ids, context=None):
713 modules = super(account_installer, self).modules_to_install(
714 cr, uid, ids, context=context)
715 chart = self.read(cr, uid, ids, ['charts'],
716 context=context)[0]['charts']
717 self.logger.notifyChannel(
718 'installer', netsvc.LOG_DEBUG,
719 'Installing chart of accounts %s'%chart)
720 return modules | set([chart])
724 class account_bank_accounts_wizard(osv.osv_memory):
725 _name='account.bank.accounts.wizard'
728 'acc_name': fields.char('Account Name.', size=64, required=True),
729 'bank_account_id': fields.many2one('account.installer', 'Bank Account', required=True),
730 'currency_id': fields.many2one('res.currency', 'Secondary Currency', help="Forces all moves for this account to have this secondary currency."),
731 'account_type': fields.selection([('cash','Cash'), ('check','Check'), ('bank','Bank')], 'Account Type', size=32),
734 account_bank_accounts_wizard()
736 class account_installer_modules(osv.osv_memory):
737 _name = 'account.installer.modules'
738 _inherit = 'res.config.installer'
740 'account_analytic_plans': fields.boolean('Multiple Analytic Plans',
741 help="Allows invoice lines to impact multiple analytic accounts "
743 'account_payment': fields.boolean('Suppliers Payment Management',
744 help="Streamlines invoice payment and creates hooks to plug "
745 "automated payment systems in."),
746 'account_followup': fields.boolean('Followups Management',
747 help="Helps you generate reminder letters for unpaid invoices, "
748 "including multiple levels of reminding and customized "
749 "per-partner policies."),
750 'account_voucher': fields.boolean('Voucher Management',
751 help="Account Voucher module includes all the basic requirements of "
752 "Voucher Entries for Bank, Cash, Sales, Purchase, Expenses, Contra, etc... "),
753 'account_anglo_saxon': fields.boolean('Anglo-Saxon Accounting',
754 help="This module will support the Anglo-Saxons accounting methodology by "
755 "changing the accounting logic with stock transactions."),
759 'account_voucher': True,
762 account_installer_modules()
764 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: