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': lambda *a: time.strftime('%Y-01-01'),
90 'date_stop': lambda *a: time.strftime('%Y-12-31'),
94 'company_id': _default_company,
95 'bank_accounts_id': _get_default_accounts,
96 'charts': _get_default_charts
99 def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
100 res = super(account_installer, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar,submenu=False)
102 unconfigured_cmp = []
104 company_ids = self.pool.get('res.company').search(cr, uid, [], context=context)
105 cr.execute("SELECT company_id FROM account_account WHERE account_account.parent_id IS NULL")
106 for r in cr.fetchall():
107 configured_cmp.append(r[0])
108 unconfigured_cmp = list(set(company_ids)-set(configured_cmp))
110 for line in self.pool.get('res.company').browse(cr, uid, unconfigured_cmp):
111 cmp_select.append((line.id,line.name))
112 for field in res['fields']:
113 if field == 'company_id':
114 res['fields'][field]['domain'] = unconfigured_cmp
115 res['fields'][field]['selection'] = cmp_select
118 def on_change_tax(self, cr, uid, id, tax):
119 return {'value': {'purchase_tax': tax}}
121 def on_change_start_date(self, cr, uid, id, start_date=False):
123 start_date = datetime.datetime.strptime(start_date, "%Y-%m-%d")
124 end_date = (start_date + relativedelta(months=12)) - relativedelta(days=1)
125 return {'value': {'date_stop': end_date.strftime('%Y-%m-%d')}}
128 def generate_configurable_chart(self, cr, uid, ids, context=None):
129 obj_acc = self.pool.get('account.account')
130 obj_acc_tax = self.pool.get('account.tax')
131 obj_journal = self.pool.get('account.journal')
132 obj_acc_tax_code = self.pool.get('account.tax.code')
133 obj_acc_template = self.pool.get('account.account.template')
134 obj_acc_tax_template = self.pool.get('account.tax.code.template')
135 obj_fiscal_position_template = self.pool.get('account.fiscal.position.template')
136 obj_fiscal_position = self.pool.get('account.fiscal.position')
137 analytic_journal_obj = self.pool.get('account.analytic.journal')
138 obj_acc_chart_template = self.pool.get('account.chart.template')
139 obj_acc_journal_view = self.pool.get('account.journal.view')
140 mod_obj = self.pool.get('ir.model.data')
141 obj_sequence = self.pool.get('ir.sequence')
142 property_obj = self.pool.get('ir.property')
143 fields_obj = self.pool.get('ir.model.fields')
144 obj_tax_fp = self.pool.get('account.fiscal.position.tax')
145 obj_ac_fp = self.pool.get('account.fiscal.position.account')
147 result = mod_obj.get_object_reference(cr, uid, 'account', 'configurable_chart_template')
148 id = result and result[1] or False
149 obj_multi = obj_acc_chart_template.browse(cr, uid, id, context=context)
151 record = self.browse(cr, uid, ids, context=context)[0]
155 company_id = self.browse(cr, uid, ids, context=context)[0].company_id
159 obj_acc_root = obj_multi.account_root_id
160 tax_code_root_id = obj_multi.tax_code_root_id.id
163 acc_template_ref = {}
164 tax_template_ref = {}
165 tax_code_template_ref = {}
168 #create all the tax code
169 children_tax_code_template = obj_acc_tax_template.search(cr, uid, [('parent_id', 'child_of', [tax_code_root_id])], order='id')
170 children_tax_code_template.sort()
171 for tax_code_template in obj_acc_tax_template.browse(cr, uid, children_tax_code_template, context=context):
173 'name': (tax_code_root_id == tax_code_template.id) and company_id.name or tax_code_template.name,
174 'code': tax_code_template.code,
175 'info': tax_code_template.info,
176 '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,
177 'company_id': company_id.id,
178 'sign': tax_code_template.sign,
180 new_tax_code = obj_acc_tax_code.create(cr, uid, vals, context=context)
181 #recording the new tax code to do the mapping
182 tax_code_template_ref[tax_code_template.id] = new_tax_code
185 for tax in obj_multi.tax_template_ids:
189 'sequence': tax.sequence,
190 'amount': tax.amount,
192 'applicable_type': tax.applicable_type,
193 'domain': tax.domain,
194 'parent_id': tax.parent_id and ((tax.parent_id.id in tax_template_ref) and tax_template_ref[tax.parent_id.id]) or False,
195 'child_depend': tax.child_depend,
196 'python_compute': tax.python_compute,
197 'python_compute_inv': tax.python_compute_inv,
198 'python_applicable': tax.python_applicable,
199 '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,
200 '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,
201 'base_sign': tax.base_sign,
202 'tax_sign': tax.tax_sign,
203 '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,
204 '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,
205 'ref_base_sign': tax.ref_base_sign,
206 'ref_tax_sign': tax.ref_tax_sign,
207 'include_base_amount': tax.include_base_amount,
208 'description': tax.description,
209 'company_id': company_id.id,
210 'type_tax_use': tax.type_tax_use,
211 'price_include': tax.price_include
213 new_tax = obj_acc_tax.create(cr, uid, vals_tax, context=context)
214 #as the accounts have not been created yet, we have to wait before filling these fields
215 todo_dict[new_tax] = {
216 'account_collected_id': tax.account_collected_id and tax.account_collected_id.id or False,
217 'account_paid_id': tax.account_paid_id and tax.account_paid_id.id or False,
219 tax_template_ref[tax.id] = new_tax
221 #deactivate the parent_store functionnality on account_account for rapidity purpose
222 ctx = context and context.copy() or {}
223 ctx['defer_parent_store_computation'] = True
225 children_acc_template = obj_acc_template.search(cr, uid, [('parent_id', 'child_of', [obj_acc_root.id]), ('nocreate', '!=', True)], context=context)
226 children_acc_template.sort()
227 for account_template in obj_acc_template.browse(cr, uid, children_acc_template, context=context):
229 for tax in account_template.tax_ids:
230 tax_ids.append(tax_template_ref[tax.id])
231 #create the account_account
234 code_main = account_template.code and len(account_template.code) or 0
235 code_acc = account_template.code or ''
236 if code_main > 0 and code_main <= dig and account_template.type != 'view':
237 code_acc = str(code_acc) + (str('0'*(dig-code_main)))
239 'name': (obj_acc_root.id == account_template.id) and company_id.name or account_template.name,
240 #'sign': account_template.sign,
241 'currency_id': account_template.currency_id and account_template.currency_id.id or False,
243 'type': account_template.type,
244 'user_type': account_template.user_type and account_template.user_type.id or False,
245 'reconcile': account_template.reconcile,
246 'shortcut': account_template.shortcut,
247 'note': account_template.note,
248 '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,
249 'tax_ids': [(6, 0, tax_ids)],
250 'company_id': company_id.id,
252 new_account = obj_acc.create(cr, uid, vals, context=ctx)
253 acc_template_ref[account_template.id] = new_account
254 if account_template.name == 'Bank Current Account':
256 'name': 'Bank Accounts',
259 'user_type': account_template.parent_id.user_type and account_template.user_type.id or False,
260 'shortcut': account_template.shortcut,
261 'note': account_template.note,
262 '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,
263 'tax_ids': [(6,0,tax_ids)],
264 'company_id': company_id.id,
266 bank_account = obj_acc.create(cr, uid, b_vals, context=ctx)
268 view_id_cash = obj_acc_journal_view.search(cr, uid, [('name', '=', 'Bank/Cash Journal View')], context=context)[0] #why fixed name here?
269 view_id_cur = obj_acc_journal_view.search(cr, uid, [('name', '=', 'Bank/Cash Journal (Multi-Currency) View')], context=context)[0] #Why Fixed name here?
271 cash_result = mod_obj.get_object_reference(cr, uid, 'account', 'conf_account_type_cash')
272 cash_type_id = cash_result and cash_result[1] or False
274 bank_result = mod_obj.get_object_reference(cr, uid, 'account', 'conf_account_type_bnk')
275 bank_type_id = bank_result and bank_result[1] or False
277 check_result = mod_obj.get_object_reference(cr, uid, 'account', 'conf_account_type_chk')
278 check_type_id = check_result and check_result[1] or False
280 # record = self.browse(cr, uid, ids, context=context)[0]
283 'name': _('Bank Journal '),
284 'code': 'account.journal',
285 'prefix': 'BNK/%(year)s/',
286 'company_id': company_id.id,
289 seq_id = obj_sequence.create(cr, uid, vals_seq, context=context)
291 #create the bank journals
292 analitical_bank_ids = analytic_journal_obj.search(cr, uid, [('type', '=', 'situation')], context=context)
293 analitical_journal_bank = analitical_bank_ids and analitical_bank_ids[0] or False
295 'name': _('Bank Journal '),
297 'sequence_id': seq_id,
299 'company_id': company_id.id,
300 'analytic_journal_id': analitical_journal_bank
302 if vals.get('currency_id', False):
303 vals_journal.update({
304 'view_id': view_id_cur,
305 'currency': vals.get('currency_id', False)
308 vals_journal.update({'view_id': view_id_cash})
309 vals_journal.update({
310 'default_credit_account_id': new_account,
311 'default_debit_account_id': new_account,
313 obj_journal.create(cr, uid, vals_journal, context=context)
315 for val in record.bank_accounts_id:
317 if val.account_type == 'cash':
319 elif val.account_type == 'bank':
321 elif val.account_type == 'check':
328 'name': val.acc_name or '',
329 'currency_id': val.currency_id.id or False,
330 'code': str(110500 + code_cnt),
333 'parent_id': bank_account,
334 'company_id': company_id.id
336 child_bnk_acc = obj_acc.create(cr, uid, vals_bnk, context=ctx)
338 'name': _(vals_bnk['name'] + ' ' + 'Journal'),
339 'code': 'account.journal',
340 'prefix': _((vals_bnk['name'][:3].upper()) + '/%(year)s/'),
341 'padding': seq_padding
343 seq_id = obj_sequence.create(cr, uid, vals_seq_child, context=context)
345 #create the bank journal
348 'name': vals_bnk['name'] + _(' Journal'),
349 'code': _(vals_bnk['name'][:3]).upper(),
350 'sequence_id': seq_id,
352 'company_id': company_id.id
354 if vals.get('currency_id', False):
355 vals_journal.update({
356 'view_id': view_id_cur,
357 'currency': vals_bnk.get('currency_id', False),
360 vals_journal.update({'view_id': view_id_cash})
361 vals_journal.update({
362 'default_credit_account_id': child_bnk_acc,
363 'default_debit_account_id': child_bnk_acc,
364 'analytic_journal_id': analitical_journal_bank
366 obj_journal.create(cr, uid, vals_journal, context=context)
369 #reactivate the parent_store functionality on account_account
370 obj_acc._parent_store_compute(cr)
372 for key, value in todo_dict.items():
373 if value['account_collected_id'] or value['account_paid_id']:
374 obj_acc_tax.write(cr, uid, [key], {
375 'account_collected_id': acc_template_ref[value['account_collected_id']],
376 'account_paid_id': acc_template_ref[value['account_paid_id']],
379 # Creating Journals Sales and Purchase
381 data_id = mod_obj.search(cr, uid, [('model', '=', 'account.journal.view'), ('name', '=', 'account_sp_journal_view')], context=context)
382 data = mod_obj.browse(cr, uid, data_id[0], context=context)
383 view_id = data.res_id
384 seq_id = obj_sequence.search(cr,uid,[('name', '=', 'Account Journal')], context=context)[0]
388 'name': 'Sale Journal',
389 'code': 'account.journal',
390 'prefix': 'SAJ/%(year)s/',
392 'company_id': company_id.id
394 seq_id_sale = obj_sequence.create(cr, uid, seq_sale, context=context)
396 'name': 'Purchase Journal',
397 'code': 'account.journal',
398 'prefix': 'EXJ/%(year)s/',
400 'company_id': company_id.id
402 seq_id_purchase = obj_sequence.create(cr, uid, seq_purchase, context=context)
404 'name': 'Sales Refund Journal',
405 'code': 'account.journal',
406 'prefix': 'SCNJ/%(year)s/',
408 'company_id': company_id.id
410 seq_id_sale_refund = obj_sequence.create(cr, uid, seq_refund_sale, context=context)
411 seq_refund_purchase = {
412 'name': 'Purchase Refund Journal',
413 'code': 'account.journal',
414 'prefix': 'ECNJ/%(year)s/',
416 'company_id': company_id.id
418 seq_id_purchase_refund = obj_sequence.create(cr, uid, seq_refund_purchase, context=context)
421 seq_id_purchase = seq_id
422 seq_id_sale_refund = seq_id
423 seq_id_purchase_refund = seq_id
425 vals_journal['view_id'] = view_id
428 analitical_sale_ids = analytic_journal_obj.search(cr, uid, [('type','=','sale')], context=context)
429 analitical_journal_sale = analitical_sale_ids and analitical_sale_ids[0] or False
431 vals_journal.update({
432 'name': _('Sales Journal'),
435 'sequence_id': seq_id_sale,
436 'analytic_journal_id': analitical_journal_sale,
437 'company_id': company_id.id
440 if obj_multi.property_account_receivable:
441 vals_journal.update({
442 'default_credit_account_id': acc_template_ref[obj_multi.property_account_income_categ.id],
443 'default_debit_account_id': acc_template_ref[obj_multi.property_account_income_categ.id],
445 obj_journal.create(cr, uid, vals_journal, context=context)
448 analitical_purchase_ids = analytic_journal_obj.search(cr, uid, [('type', '=', 'purchase')], context=context)
449 analitical_journal_purchase = analitical_purchase_ids and analitical_purchase_ids[0] or False
451 vals_journal.update({
452 'name': _('Purchase Journal'),
455 'sequence_id': seq_id_purchase,
456 'analytic_journal_id': analitical_journal_purchase,
457 'company_id': company_id.id
460 if obj_multi.property_account_payable:
461 vals_journal.update({
462 'default_credit_account_id': acc_template_ref[obj_multi.property_account_expense_categ.id],
463 'default_debit_account_id': acc_template_ref[obj_multi.property_account_expense_categ.id]
466 obj_journal.create(cr, uid, vals_journal, context=context)
467 # Creating Journals Sales Refund and Purchase Refund
469 data_id = mod_obj.search(cr, uid, [('model', '=', 'account.journal.view'), ('name', '=', 'account_sp_refund_journal_view')], context=context)
470 data = mod_obj.browse(cr, uid, data_id[0], context=context)
471 view_id = data.res_id
473 #Sales Refund Journal
476 'name': _('Sales Refund Journal'),
477 'type': 'sale_refund',
478 'refund_journal': True,
480 'sequence_id': seq_id_sale_refund,
481 'analytic_journal_id': analitical_journal_sale,
482 'company_id': company_id.id
484 if obj_multi.property_account_receivable:
485 vals_journal.update({
486 'default_credit_account_id': acc_template_ref[obj_multi.property_account_income_categ.id],
487 'default_debit_account_id': acc_template_ref[obj_multi.property_account_income_categ.id]
490 obj_journal.create(cr, uid, vals_journal, context=context)
492 # Purchase Refund Journal
495 'name': _('Purchase Refund Journal'),
496 'type': 'purchase_refund',
497 'refund_journal': True,
499 'sequence_id': seq_id_purchase_refund,
500 'analytic_journal_id': analitical_journal_purchase,
501 'company_id': company_id.id
504 if obj_multi.property_account_payable:
505 vals_journal.update({
506 'default_credit_account_id': acc_template_ref[obj_multi.property_account_expense_categ.id],
507 'default_debit_account_id': acc_template_ref[obj_multi.property_account_expense_categ.id]
509 obj_journal.create(cr, uid, vals_journal, context=context)
512 view_id_cash = obj_acc_journal_view.search(cr, uid, [('name', '=', 'Bank/Cash Journal View')], context=context)[0] #TOFIX: Why put fixed name ?
513 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?
515 #create the properties
517 ('property_account_receivable', 'res.partner', 'account.account'),
518 ('property_account_payable', 'res.partner', 'account.account'),
519 ('property_account_expense_categ', 'product.category', 'account.account'),
520 ('property_account_income_categ', 'product.category', 'account.account'),
521 ('property_account_expense', 'product.template', 'account.account'),
522 ('property_account_income', 'product.template', 'account.account'),
523 ('property_reserve_and_surplus_account', 'res.company', 'account.account'),
526 for record in todo_list:
528 r = property_obj.search(cr, uid, [('name', '=', record[0]), ('company_id', '=', company_id.id)], context=context)
529 account = getattr(obj_multi, record[0])
530 field = fields_obj.search(cr, uid, [('name', '=', record[0]), ('model', '=', record[1]), ('relation', '=', record[2])], context=context)
533 'company_id': company_id.id,
534 'fields_id': field[0],
535 'value': account and 'account.account, '+str(acc_template_ref[account.id]) or False,
538 #the property exist: modify it
539 property_obj.write(cr, uid, r, vals, context=context)
542 property_obj.create(cr, uid, vals, context=context)
544 fp_ids = obj_fiscal_position_template.search(cr, uid, [('chart_template_id', '=', obj_multi.id)], context=context)
546 for position in obj_fiscal_position_template.browse(cr, uid, fp_ids, context=context):
548 'company_id': company_id.id,
549 'name': position.name,
551 new_fp = obj_fiscal_position.create(cr, uid, vals_fp, context=context)
552 for tax in position.tax_ids:
554 'tax_src_id': tax_template_ref[tax.tax_src_id.id],
555 'tax_dest_id': tax.tax_dest_id and tax_template_ref[tax.tax_dest_id.id] or False,
556 'position_id': new_fp,
558 obj_tax_fp.create(cr, uid, vals_tax, context=context)
560 for acc in position.account_ids:
562 'account_src_id': acc_template_ref[acc.account_src_id.id],
563 'account_dest_id': acc_template_ref[acc.account_dest_id.id],
564 'position_id': new_fp,
566 obj_ac_fp.create(cr, uid, vals_acc, context=context)
568 def execute(self, cr, uid, ids, context=None):
571 fy_obj = self.pool.get('account.fiscalyear')
572 mod_obj = self.pool.get('ir.model.data')
573 obj_acc = self.pool.get('account.account')
574 obj_tax_code = self.pool.get('account.tax.code')
575 obj_temp_tax_code = self.pool.get('account.tax.code.template')
576 obj_tax = self.pool.get('account.tax')
577 obj_product = self.pool.get('product.product')
578 ir_values = self.pool.get('ir.values')
579 super(account_installer, self).execute(cr, uid, ids, context=context)
580 record = self.browse(cr, uid, ids, context=context)[0]
581 company_id = record.company_id
582 for res in self.read(cr, uid, ids, context=context):
583 if record.charts == 'configurable':
584 fp = tools.file_open(opj('account', 'configurable_account_chart.xml'))
585 tools.convert_xml_import(cr, 'account', fp, {}, 'init', True, None)
587 self.generate_configurable_chart(cr, uid, ids, context=context)
588 s_tax = (res.get('sale_tax', 0.0))/100
589 p_tax = (res.get('purchase_tax', 0.0))/100
593 pur_temp_tax = mod_obj.get_object_reference(cr, uid, 'account', 'tax_code_base_purchases')
594 pur_temp_tax_id = pur_temp_tax and pur_temp_tax[1] or False
596 pur_temp_tax_names = obj_temp_tax_code.read(cr, uid, [pur_temp_tax_id], ['name'], context=context)
597 pur_tax_parent_name = pur_temp_tax_names and pur_temp_tax_names[0]['name'] or False
598 pur_taxcode_parent_id = obj_tax_code.search(cr, uid, [('name', 'ilike', pur_tax_parent_name)], context=context)
599 if pur_taxcode_parent_id:
600 pur_taxcode_parent_id = pur_taxcode_parent_id[0]
602 pur_taxcode_parent_id = False
603 pur_temp_tax_paid = mod_obj.get_object_reference(cr, uid, 'account', 'tax_code_input')
604 pur_temp_tax_paid_id = pur_temp_tax_paid and pur_temp_tax_paid[1] or False
605 pur_temp_tax_paid_names = obj_temp_tax_code.read(cr, uid, [pur_temp_tax_paid_id], ['name'], context=context)
606 pur_tax_paid_parent_name = pur_temp_tax_names and pur_temp_tax_paid_names[0]['name'] or False
607 pur_taxcode_paid_parent_id = obj_tax_code.search(cr, uid, [('name', 'ilike', pur_tax_paid_parent_name)], context=context)
608 if pur_taxcode_paid_parent_id:
609 pur_taxcode_paid_parent_id = pur_taxcode_paid_parent_id[0]
611 pur_taxcode_paid_parent_id = False
613 sale_temp_tax = mod_obj.get_object_reference(cr, uid, 'account', 'tax_code_base_sales')
614 sale_temp_tax_id = sale_temp_tax and sale_temp_tax[1] or False
615 sale_temp_tax_names = obj_temp_tax_code.read(cr, uid, [sale_temp_tax_id], ['name'], context=context)
616 sale_tax_parent_name = sale_temp_tax_names and sale_temp_tax_names[0]['name'] or False
617 sale_taxcode_parent_id = obj_tax_code.search(cr, uid, [('name', 'ilike', sale_tax_parent_name)], context=context)
618 if sale_taxcode_parent_id:
619 sale_taxcode_parent_id = sale_taxcode_parent_id[0]
621 sale_taxcode_parent_id = False
623 sale_temp_tax_paid = mod_obj.get_object_reference(cr, uid, 'account', 'tax_code_output')
624 sale_temp_tax_paid_id = sale_temp_tax_paid and sale_temp_tax_paid[1] or False
625 sale_temp_tax_paid_names = obj_temp_tax_code.read(cr, uid, [sale_temp_tax_paid_id], ['name'], context=context)
626 sale_tax_paid_parent_name = sale_temp_tax_paid_names and sale_temp_tax_paid_names[0]['name'] or False
627 sale_taxcode_paid_parent_id = obj_tax_code.search(cr, uid, [('name', 'ilike', sale_tax_paid_parent_name)], context=context)
628 if sale_taxcode_paid_parent_id:
629 sale_taxcode_paid_parent_id = sale_taxcode_paid_parent_id[0]
631 sale_taxcode_paid_parent_id = False
634 tax_account_ids = obj_acc.search(cr, uid, [('name', '=', 'Tax Received')], context=context)
635 sales_tax_account_id = tax_account_ids and tax_account_ids[0] or False
637 'name': 'TAX%s%%'%(s_tax*100),
638 'code': 'TAX%s%%'%(s_tax*100),
639 'company_id': company_id.id,
641 'parent_id': sale_taxcode_parent_id
643 new_tax_code = obj_tax_code.create(cr, uid, vals_tax_code, context=context)
645 vals_paid_tax_code = {
646 'name': 'TAX Received %s%%'%(s_tax*100),
647 'code': 'TAX Received %s%%'%(s_tax*100),
648 'company_id': company_id.id,
650 'parent_id': sale_taxcode_paid_parent_id
652 new_paid_tax_code = obj_tax_code.create(cr, uid, vals_paid_tax_code, context=context)
654 sales_tax = obj_tax.create(cr, uid,
655 {'name': 'TAX %s%%'%(s_tax*100),
657 'base_code_id': new_tax_code,
658 'tax_code_id': new_paid_tax_code,
659 'type_tax_use': 'sale',
660 'account_collected_id': sales_tax_account_id,
661 'account_paid_id': sales_tax_account_id
663 default_account_ids = obj_acc.search(cr, uid, [('name', '=', 'Product Sales')], context=context)
664 if default_account_ids:
665 obj_acc.write(cr, uid, default_account_ids, {'tax_ids': [(6, 0, [sales_tax])]}, context=context)
666 tax_val.update({'taxes_id': [(6, 0, [sales_tax])]})
667 default_tax.append(('taxes_id', sales_tax))
669 tax_account_ids = obj_acc.search(cr, uid, [('name', '=', 'Tax Paid')], context=context)
670 purchase_tax_account_id = tax_account_ids and tax_account_ids[0] or False
672 'name': 'TAX%s%%'%(p_tax*100),
673 'code': 'TAX%s%%'%(p_tax*100),
674 'company_id': company_id.id,
676 'parent_id': pur_taxcode_parent_id
678 new_tax_code = obj_tax_code.create(cr, uid, vals_tax_code, context=context)
679 vals_paid_tax_code = {
680 'name': 'TAX Paid %s%%'%(p_tax*100),
681 'code': 'TAX Paid %s%%'%(p_tax*100),
682 'company_id': company_id.id,
684 'parent_id': pur_taxcode_paid_parent_id
686 new_paid_tax_code = obj_tax_code.create(cr, uid, vals_paid_tax_code, context=context)
688 purchase_tax = obj_tax.create(cr, uid,
689 {'name': 'TAX%s%%'%(p_tax*100),
690 'description': 'TAX%s%%'%(p_tax*100),
692 'base_code_id': new_tax_code,
693 'tax_code_id': new_paid_tax_code,
694 'type_tax_use': 'purchase',
695 'account_collected_id': purchase_tax_account_id,
696 'account_paid_id': purchase_tax_account_id
698 default_account_ids = obj_acc.search(cr, uid, [('name', '=', 'Expenses')], context=context)
699 if default_account_ids:
700 obj_acc.write(cr, uid, default_account_ids, {'tax_ids': [(6, 0, [purchase_tax])]}, context=context)
701 tax_val.update({'supplier_taxes_id': [(6 ,0, [purchase_tax])]})
702 default_tax.append(('supplier_taxes_id', purchase_tax))
704 product_ids = obj_product.search(cr, uid, [], context=context)
705 for product in obj_product.browse(cr, uid, product_ids, context=context):
706 obj_product.write(cr, uid, product.id, tax_val, context=context)
707 for name, value in default_tax:
708 ir_values.set(cr, uid, key='default', key2=False, name=name, models =[('product.product', False)], value=[value])
710 if 'date_start' in res and 'date_stop' in res:
711 f_ids = fy_obj.search(cr, uid, [('date_start', '<=', res['date_start']), ('date_stop', '>=', res['date_stop']), ('company_id', '=', res['company_id'])], context=context)
713 name = code = res['date_start'][:4]
714 if int(name) != int(res['date_stop'][:4]):
715 name = res['date_start'][:4] +'-'+ res['date_stop'][:4]
716 code = res['date_start'][2:4] +'-'+ res['date_stop'][2:4]
720 'date_start': res['date_start'],
721 'date_stop': res['date_stop'],
722 'company_id': res['company_id']
724 fiscal_id = fy_obj.create(cr, uid, vals, context=context)
725 if res['period'] == 'month':
726 fy_obj.create_period(cr, uid, [fiscal_id])
727 elif res['period'] == '3months':
728 fy_obj.create_period3(cr, uid, [fiscal_id])
731 def modules_to_install(self, cr, uid, ids, context=None):
732 modules = super(account_installer, self).modules_to_install(
733 cr, uid, ids, context=context)
734 chart = self.read(cr, uid, ids, ['charts'],
735 context=context)[0]['charts']
736 self.logger.notifyChannel(
737 'installer', netsvc.LOG_DEBUG,
738 'Installing chart of accounts %s'%chart)
739 return modules | set([chart])
743 class account_bank_accounts_wizard(osv.osv_memory):
744 _name='account.bank.accounts.wizard'
747 'acc_name': fields.char('Account Name.', size=64, required=True),
748 'bank_account_id': fields.many2one('account.installer', 'Bank Account', required=True),
749 'currency_id': fields.many2one('res.currency', 'Secondary Currency', help="Forces all moves for this account to have this secondary currency."),
750 'account_type': fields.selection([('cash','Cash'), ('check','Check'), ('bank','Bank')], 'Account Type', size=32),
753 account_bank_accounts_wizard()
755 class account_installer_modules(osv.osv_memory):
756 _name = 'account.installer.modules'
757 _inherit = 'res.config.installer'
759 'account_analytic_plans': fields.boolean('Multiple Analytic Plans',
760 help="Allows invoice lines to impact multiple analytic accounts "
762 'account_payment': fields.boolean('Suppliers Payment Management',
763 help="Streamlines invoice payment and creates hooks to plug "
764 "automated payment systems in."),
765 'account_followup': fields.boolean('Followups Management',
766 help="Helps you generate reminder letters for unpaid invoices, "
767 "including multiple levels of reminding and customized "
768 "per-partner policies."),
769 'account_voucher': fields.boolean('Voucher Management',
770 help="Account Voucher module includes all the basic requirements of "
771 "Voucher Entries for Bank, Cash, Sales, Purchase, Expenses, Contra, etc... "),
772 'account_anglo_saxon': fields.boolean('Anglo-Saxon Accounting',
773 help="This module will support the Anglo-Saxons accounting methodology by "
774 "changing the accounting logic with stock transactions."),
778 'account_voucher': True,
781 account_installer_modules()
783 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: