Launchpad automatic translations update.
[odoo/odoo.git] / addons / account / res_config.py
index 80e8354..aba423d 100644 (file)
@@ -1,8 +1,8 @@
 # -*- coding: utf-8 -*-
 ##############################################################################
 #
-#    OpenERP, Open Source Management Solution
-#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
+#    OpenERP, Open Source Business Applications
+#    Copyright (C) 2004-2012 OpenERP S.A. (<http://openerp.com>).
 #
 #    This program is free software: you can redistribute it and/or modify
 #    it under the terms of the GNU Affero General Public License as
 #
 ##############################################################################
 
-import logging
 import time
 import datetime
 from dateutil.relativedelta import relativedelta
 from operator import itemgetter
 from os.path import join as opj
 
-from tools.translate import _
-from osv import fields, osv
-import netsvc
-import tools
+from openerp.tools import DEFAULT_SERVER_DATE_FORMAT as DF
+from openerp.tools.translate import _
+from openerp.osv import fields, osv
+from openerp import tools
 
-class account_configuration(osv.osv_memory):
-    _name = 'account.installer'
+class account_config_settings(osv.osv_memory):
+    _name = 'account.config.settings'
     _inherit = 'res.config.settings'
-    __logger = logging.getLogger(_name)
-
-    def _get_charts(self, cr, uid, context=None):
-        modules = self.pool.get('ir.module.module')
-        # Looking for the module with the 'Account Charts' category
-        category_name, category_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'base', 'module_category_localization_account_charts')
-        ids = modules.search(cr, uid, [('category_id', '=', category_id)], context=context)
-        charts = list(
-            sorted(((m.name, m.shortdesc)
-                    for m in modules.browse(cr, uid, ids, context=context)),
-                   key=itemgetter(1)))
-        charts.insert(0, ('configurable', 'Generic Chart Of Accounts'))
-        return charts
 
     _columns = {
-            'company_id': fields.many2one('res.company', 'Company',help="Your company."),
-            'currency_id': fields.related('company_id', 'currency_id', type='many2one', relation='res.currency', string='Currency', store=True, help="Currency of your company."),
-            'charts': fields.selection(_get_charts, 'Chart of Accounts',
-                                        required=True,
-                                        help="Installs localized accounting charts to match as closely as "
-                                             "possible the accounting needs of your company based on your "
-                                             "country."),
-            'date_start': fields.date('Start Date', required=True),
-            'date_stop': fields.date('End Date', required=True),
-            'period': fields.selection([('month', 'Monthly'), ('3months','3 Monthly')], 'Periods', required=True),
-            'has_default_company' : fields.boolean('Has Default Company', readonly=True),
-            'chart_template_id': fields.many2one('account.chart.template', 'Chart Template'),
-            'fiscalyear_id': fields.many2one('account.fiscalyear', 'Fiscal Year'),
-            'default_paypal_account': fields.char("Your Paypal Account", size=128, help="Paypal username (usually email) for receiving online payments.", default_model='res.company'),
-            'company_footer': fields.char("Footer of Reports", size=128, readonly=True, help="Footer of reports based on your bank accounts."),
-            'sale_journal_id': fields.many2one('account.journal','Sale Journal'),
-            'customer_invoice_sequence_prefix': fields.related('sale_journal_id', 'sequence_id', 'prefix', type='char', relation='ir.sequence', string='Invoice Sequence'),
-            'customer_invoice_sequence_next': fields.related('sale_journal_id', 'sequence_id', 'number_next', type='integer', relation='ir.sequence', string='Invoice Sequence Next Number'),
-            'sale_refund_journal_id': fields.many2one('account.journal','Sale Refund Journal'),
-            'customer_refund_sequence_prefix': fields.related('sale_refund_journal_id', 'sequence_id', 'prefix', type='char', relation='ir.sequence', string='Refund Sequence'),
-            'customer_refund_sequence_next': fields.related('sale_refund_journal_id', 'sequence_id', 'number_next', type='integer', relation='ir.sequence', string='Refund Sequence Next Number'),
-            'purchase_journal_id': fields.many2one('account.journal','Purchase Journal'),
-            'supplier_invoice_sequence_prefix': fields.related('purchase_journal_id', 'sequence_id', 'prefix', type='char', relation='ir.sequence', string='Supplier Invoice Sequence'),
-            'supplier_invoice_sequence_next': fields.related('purchase_journal_id', 'sequence_id', 'number_next', type='integer', relation='ir.sequence', string='Supplier Invoice Sequence Next Number'),
-            'purchase_refund_journal_id': fields.many2one('account.journal','Purchase Refund Journal'),
-            'supplier_refund_sequence_prefix': fields.related('purchase_refund_journal_id', 'sequence_id', 'prefix', type='char', relation='ir.sequence', string='Supplier Refund Sequence'),
-            'supplier_refund_sequence_next': fields.related('purchase_refund_journal_id', 'sequence_id', 'number_next', type='integer', relation='ir.sequence', string='Supplier Refund Sequence Next Number'),
+        'company_id': fields.many2one('res.company', 'Company', required=True),
+        'has_default_company': fields.boolean('Has default company', readonly=True),
+        'expects_chart_of_accounts': fields.related('company_id', 'expects_chart_of_accounts', type='boolean',
+            string='This company has its own chart of accounts',
+            help="""Check this box if this company is a legal entity."""),
+        'currency_id': fields.related('company_id', 'currency_id', type='many2one', relation='res.currency', required=True,
+            string='Default company currency', help="Main currency of the company."),
+        'paypal_account': fields.related('company_id', 'paypal_account', type='char', size=128,
+            string='Paypal account', help="Paypal account (email) for receiving online payments (credit card, etc.) If you set a paypal account, the customer  will be able to pay your invoices or quotations with a button \"Pay with  Paypal\" in automated emails or through the OpenERP portal."),
+        'company_footer': fields.related('company_id', 'rml_footer', type='text', readonly=True,
+            string='Bank accounts footer preview', help="Bank accounts as printed in the footer of each printed document"),
+
+        'has_chart_of_accounts': fields.boolean('Company has a chart of accounts'),
+        'chart_template_id': fields.many2one('account.chart.template', 'Template', domain="[('visible','=', True)]"),
+        'code_digits': fields.integer('# of Digits', help="No. of digits to use for account code"),
+        'tax_calculation_rounding_method': fields.related('company_id',
+            'tax_calculation_rounding_method', type='selection', selection=[
+            ('round_per_line', 'Round per line'),
+            ('round_globally', 'Round globally'),
+            ], string='Tax calculation rounding method',
+            help="If you select 'Round per line' : for each tax, the tax amount will first be computed and rounded for each PO/SO/invoice line and then these rounded amounts will be summed, leading to the total amount for that tax. If you select 'Round globally': for each tax, the tax amount will be computed for each PO/SO/invoice line, then these amounts will be summed and eventually this total tax amount will be rounded. If you sell with tax included, you should choose 'Round per line' because you certainly want the sum of your tax-included line subtotals to be equal to the total amount with taxes."),
+        'sale_tax': fields.many2one("account.tax.template", "Default sale tax"),
+        'purchase_tax': fields.many2one("account.tax.template", "Default purchase tax"),
+        'sale_tax_rate': fields.float('Sales tax (%)'),
+        'purchase_tax_rate': fields.float('Purchase tax (%)'),
+        'complete_tax_set': fields.boolean('Complete set of taxes', help='This boolean helps you to choose if you want to propose to the user to encode the sales and purchase rates or use the usual m2o fields. This last choice assumes that the set of tax defined for the chosen template is complete'),
 
-            'module_account_check_writing': fields.boolean('Support check writings',
-                                            help="""  This allows you to check writing and printing.
-                                            It installs the account_check_writing module."""),
-            'module_account_accountant': fields.boolean('Accountant Features',
-                                        help="""This allows you to access all the accounting features like the journal items and the chart of accounts.
-                                        It installs the account_accountant module."""),
-            'module_account_asset': fields.boolean('Assets Management',
-                                    help="""This allows you to manages the assets owned by a company or an individual. It will keep track of depreciation's occurred on
-                                    those assets. And it allows to create Move's of the depreciation lines.
-                                    It installs the account_asset module."""),
-            'module_account_budget': fields.boolean('Budgets Management',
-                                    help="""This allows accountants to manage analytic and crossovered budgets.
-                                    Once the Master Budgets and the Budgets are defined (in Accounting/Budgets/),
-                                    the Project Managers can set the planned amount on each Analytic Account.
-                                    It installs the account_budget module."""),
-            'module_account_payment': fields.boolean('Supplier Payment Orders',
-                                    help="""This allows you to create and manage your payment orders, with purposes to
-                                    * serve as base for an easy plug-in of various automated payment mechanisms.
-                                    * provide a more efficient way to manage invoice payment.
-                                    It installs the account_payment module."""),
-            'module_account_voucher': fields.boolean('Manage Customer Payments',
-                                    help="""This includes all the basic requirements of Voucher Entries for Bank, Cash, Sales, Purchase, Expanse, Contra, etc.
-                                    It installs the account_voucher module."""),
-            'module_account_followup': fields.boolean('Customer Follow-Ups',
-                                    help="""This allows to automate letters for unpaid invoices, with multi-level recalls.
-                                    It installs the account_followup module."""),
-            'module_account_analytic_plans': fields.boolean('Support Multiple Analytic Plans',
-                                        help="""This allows to use several analytic plans, according to the general journal.
-                                        It installs the account_analytic_plans module."""),
-            'module_account_analytic_default': fields.boolean('Rules for Analytic Assignation',
-                                            help="""Set default values for your analytic accounts
-                                            Allows to automatically select analytic accounts based on criterias:
-                                            * Product
-                                            * Partner
-                                            * User
-                                            * Company
-                                            * Date.
-                                        It installs the account_analytic_default module."""),
-            'module_account_invoice_layout': fields.boolean('Allow notes and subtotals',
-                                            help="""This provides some features to improve the layout of the invoices.
-                                            It gives you the possibility to:
-                                            * order all the lines of an invoice
-                                            * add titles, comment lines, sub total lines
-                                            * draw horizontal lines and put page breaks.
-                                            It installs the account_invoice_layout module."""),
+        'has_fiscal_year': fields.boolean('Company has a fiscal year'),
+        'date_start': fields.date('Start date', required=True),
+        'date_stop': fields.date('End date', required=True),
+        'period': fields.selection([('month', 'Monthly'), ('3months','3 Monthly')], 'Periods', required=True),
 
-            'group_analytic_account_for_sales': fields.boolean('Analytic Accounting for Sales', group='base.group_user', implied_group='base.group_analytic_account_for_sales',
-                                                               help="Allows you to set analytic account for sale order. It assigns 'Analytic Accounting for Sales' group to all employees."),
-            'group_analytic_account_for_purchase': fields.boolean('Analytic Accounting for Purchase', group='base.group_user', implied_group='base.group_analytic_account_for_purchase',
-                                                                  help="Allows you to set analytic account for purchase order. It assigns 'Analytic Accounting for Purchase' group to all employees."),
-            'group_dates_periods': fields.boolean('Allow dates/periods', group='base.group_user', implied_group='base.group_dates_periods',
-                                                  help="Allows you to keep the period same as your invoice date when you validate the invoice."\
-                                                       "It will add the group 'Allow dates and periods' for all users."),
-            'group_proforma_invoices': fields.boolean('Allow Pro-forma Invoices', group='base.group_user', implied_group='base.group_proforma_invoices',
-                                                      help="Allows you to put invoice in pro-forma state. It assigns 'Allow Pro-forma Invoices' group to all employees."),
+        'sale_journal_id': fields.many2one('account.journal', 'Sale journal'),
+        'sale_sequence_prefix': fields.related('sale_journal_id', 'sequence_id', 'prefix', type='char', string='Invoice sequence'),
+        'sale_sequence_next': fields.related('sale_journal_id', 'sequence_id', 'number_next', type='integer', string='Next invoice number'),
+        'sale_refund_journal_id': fields.many2one('account.journal', 'Sale refund journal'),
+        'sale_refund_sequence_prefix': fields.related('sale_refund_journal_id', 'sequence_id', 'prefix', type='char', string='Credit note sequence'),
+        'sale_refund_sequence_next': fields.related('sale_refund_journal_id', 'sequence_id', 'number_next', type='integer', string='Next credit note number'),
+        'purchase_journal_id': fields.many2one('account.journal', 'Purchase journal'),
+        'purchase_sequence_prefix': fields.related('purchase_journal_id', 'sequence_id', 'prefix', type='char', string='Supplier invoice sequence'),
+        'purchase_sequence_next': fields.related('purchase_journal_id', 'sequence_id', 'number_next', type='integer', string='Next supplier invoice number'),
+        'purchase_refund_journal_id': fields.many2one('account.journal', 'Purchase refund journal'),
+        'purchase_refund_sequence_prefix': fields.related('purchase_refund_journal_id', 'sequence_id', 'prefix', type='char', string='Supplier credit note sequence'),
+        'purchase_refund_sequence_next': fields.related('purchase_refund_journal_id', 'sequence_id', 'number_next', type='integer', string='Next supplier credit note number'),
 
-            'multi_charts_id':fields.many2one('wizard.multi.charts.accounts', 'Multi charts accounts'),
-            'taxes_id':fields.many2one('account.tax.template', 'Default Sale Tax'),
-            'supplier_taxes_id':fields.many2one('account.tax.template', 'Default Purchase Tax'),
-            'sale_tax_rate': fields.float('Sales Tax(%)'),
-            'purchase_tax_rate': fields.float('Purchase Tax(%)'),
-            'complete_tax_set': fields.boolean('Complete Set of Taxes'),
+        'module_account_check_writing': fields.boolean('Pay your suppliers by check',
+            help="""This allows you to check writing and printing.
+                This installs the module account_check_writing."""),
+        'module_account_accountant': fields.boolean('Full accounting features: journals, legal statements, chart of accounts, etc.',
+            help="""If you do not check this box, you will be able to do invoicing & payments, but not accounting (Journal Items, Chart of  Accounts, ...)"""),
+        'module_account_asset': fields.boolean('Assets management',
+            help="""This allows you to manage the assets owned by a company or a person.
+                It keeps track of the depreciation occurred on those assets, and creates account move for those depreciation lines.
+                This installs the module account_asset. If you do not check this box, you will be able to do invoicing & payments,
+                but not accounting (Journal Items, Chart of Accounts, ...)"""),
+        'module_account_budget': fields.boolean('Budget management',
+            help="""This allows accountants to manage analytic and crossovered budgets.
+                Once the master budgets and the budgets are defined,
+                the project managers can set the planned amount on each analytic account.
+                This installs the module account_budget."""),
+        'module_account_payment': fields.boolean('Manage payment orders',
+            help="""This allows you to create and manage your payment orders, with purposes to
+                    * serve as base for an easy plug-in of various automated payment mechanisms, and
+                    * provide a more efficient way to manage invoice payments.
+                This installs the module account_payment."""),
+        'module_account_voucher': fields.boolean('Manage customer payments',
+            help="""This includes all the basic requirements of voucher entries for bank, cash, sales, purchase, expense, contra, etc.
+                This installs the module account_voucher."""),
+        'module_account_followup': fields.boolean('Manage customer payment follow-ups',
+            help="""This allows to automate letters for unpaid invoices, with multi-level recalls.
+                This installs the module account_followup."""),
+        'group_proforma_invoices': fields.boolean('Allow pro-forma invoices',
+            implied_group='account.group_proforma_invoices',
+            help="Allows you to put invoices in pro-forma state."),
+        'default_sale_tax': fields.many2one('account.tax', 'Default sale tax',
+            help="This sale tax will be assigned by default on new products."),
+        'default_purchase_tax': fields.many2one('account.tax', 'Default purchase tax',
+            help="This purchase tax will be assigned by default on new products."),
+        'decimal_precision': fields.integer('Decimal precision on journal entries',
+            help="""As an example, a decimal precision of 2 will allow journal entries  like: 9.99 EUR, whereas a decimal precision of 4 will allow journal  entries like: 0.0231 EUR."""),
+        'group_multi_currency': fields.boolean('Allow multi currencies',
+            implied_group='base.group_multi_currency',
+            help="Allows you multi currency environment"),
+        'group_analytic_accounting': fields.boolean('Analytic accounting',
+            implied_group='analytic.group_analytic_accounting',
+            help="Allows you to use the analytic accounting."),
+        'group_check_supplier_invoice_total': fields.boolean('Check the total of supplier invoices', 
+            implied_group="account.group_supplier_inv_check_total"),
     }
+
     def _default_company(self, cr, uid, context=None):
         user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
-        return user.company_id and user.company_id.id or False
+        return user.company_id.id
 
     def _default_has_default_company(self, cr, uid, context=None):
         count = self.pool.get('res.company').search_count(cr, uid, [], context=context)
         return bool(count == 1)
 
-    _defaults = {
-            'date_start': lambda *a: time.strftime('%Y-01-01'),
-            'date_stop': lambda *a: time.strftime('%Y-12-31'),
-            'period': 'month',
-            'company_id': _default_company,
-            'has_default_company': _default_has_default_company,
-            'charts': 'configurable',
-    }
-
-    def _check_default_tax(self, cr, uid, context=None):
-        ir_values_obj = self.pool.get('ir.values')
-        taxes = {}
-        for tax in ir_values_obj.get(cr, uid, 'default', False, ['product.template']):
-            if tax[1] == 'taxes_id':
-                taxes.update({'taxes_id': tax[2]})
-            if tax[1] == 'supplier_taxes_id':
-                taxes.update({'supplier_taxes_id': tax[2]})
-        return taxes
-
-    def set_tax_defaults(self, cr, uid, ids, context=None):
-        ir_values_obj = self.pool.get('ir.values')
-
-        res = {}
-        wizard = self.browse(cr, uid, ids)[0]
-        if wizard.taxes_id.id:
-            ir_values_obj.set_default(cr, uid, 'product.template', 'taxes_id', wizard.taxes_id.id )
-
-        if wizard.supplier_taxes_id.id:
-            ir_values_obj.set_default(cr, uid, 'product.template', 'supplier_taxes_id', wizard.supplier_taxes_id.id )
-
-        return res
-
-    def default_get(self, cr, uid, fields_list, context=None):
-        ir_values_obj = self.pool.get('ir.values')
-        chart_template_obj = self.pool.get('account.chart.template')
-        fiscalyear_obj = self.pool.get('account.fiscalyear')
-        journal_obj = self.pool.get('account.journal')
-        res = super(account_configuration, self).default_get(cr, uid, fields_list, context=context)
-        taxes = self._check_default_tax(cr, uid, context)
-        chart_template_ids = chart_template_obj.search(cr, uid, [('visible', '=', True)], context=context)
-        fiscalyear_ids = fiscalyear_obj.search(cr, uid, [('date_start','=',time.strftime('%Y-01-01')),('date_stop','=',time.strftime('%Y-12-31'))])
+    def _get_default_fiscalyear_data(self, cr, uid, company_id, context=None):
+        """Compute default period, starting and ending date for fiscalyear
+        - if in a fiscal year, use its period, starting and ending date
+        - if past fiscal year, use its period, and new dates [ending date of the latest +1 day ; ending date of the latest +1 year]
+        - if no fiscal year, use monthly, 1st jan, 31th dec of this year
+        :return: (date_start, date_stop, period) at format DEFAULT_SERVER_DATETIME_FORMAT
+        """
+        fiscalyear_ids = self.pool.get('account.fiscalyear').search(cr, uid,
+                [('date_start', '<=', time.strftime(DF)), ('date_stop', '>=', time.strftime(DF)),
+                 ('company_id', '=', company_id)])
+        if fiscalyear_ids:
+            # is in a current fiscal year, use this one
+            fiscalyear = self.pool.get('account.fiscalyear').browse(cr, uid, fiscalyear_ids[0], context=context)
+            if len(fiscalyear.period_ids) == 5:  # 4 periods of 3 months + opening period
+                period = '3months'
+            else:
+                period = 'month'
+            return (fiscalyear.date_start, fiscalyear.date_stop, period)
+        else:
+            past_fiscalyear_ids = self.pool.get('account.fiscalyear').search(cr, uid,
+                [('date_stop', '<=', time.strftime(DF)), ('company_id', '=', company_id)])
+            if past_fiscalyear_ids:
+                # use the latest fiscal, sorted by (start_date, id)
+                latest_year = self.pool.get('account.fiscalyear').browse(cr, uid, past_fiscalyear_ids[-1], context=context)
+                latest_stop = datetime.datetime.strptime(latest_year.date_stop, DF)
+                if len(latest_year.period_ids) == 5:
+                    period = '3months'
+                else:
+                    period = 'month'
+                return ((latest_stop+datetime.timedelta(days=1)).strftime(DF), latest_stop.replace(year=latest_stop.year+1).strftime(DF), period)
+            else:
+                return (time.strftime('%Y-01-01'), time.strftime('%Y-12-31'), 'month')
 
-        cmp_id = self.pool.get('ir.model.data').get_object(cr, uid, 'base', 'main_company').id
-        company_data = self.pool.get('res.company').browse(cr, uid, cmp_id)
-        res.update({'company_footer': company_data.rml_footer2})
 
-        journal_ids = journal_obj.search(cr, uid, [('company_id', '=', res.get('company_id'))])
-        if journal_ids:
-            for journal in journal_obj.browse(cr, uid, journal_ids, context=context):
-                if journal.type == 'sale':
-                    res.update({'sale_journal_id': journal.id})
-                if journal.type == 'sale_refund':
-                    res.update({'sale_refund_journal_id': journal.id})
-                if journal.type == 'purchase':
-                    res.update({'purchase_journal_id': journal.id})
-                if journal.type == 'purchase_refund':
-                    res.update({'purchase_refund_journal_id': journal.id})
+    _defaults = {
+        'company_id': _default_company,
+        'has_default_company': _default_has_default_company,
+    }
 
-        if chart_template_ids:
-            data = chart_template_obj.browse(cr, uid, chart_template_ids[0], context=context)
-            res.update({'complete_tax_set': data.complete_tax_set})
-            supplier_taxes_id = ir_values_obj.get_default(cr, uid, 'product.template', 'supplier_taxes_id')
-            res.update({'supplier_taxes_id': supplier_taxes_id})
-            taxes_id = ir_values_obj.get_default(cr, uid, 'product.template', 'taxes_id')
-            res.update({'chart_template_id': taxes_id})
-            res.update({'chart_template_id': chart_template_ids[0]})
+    def create(self, cr, uid, values, context=None):
+        id = super(account_config_settings, self).create(cr, uid, values, context)
+        # Hack: to avoid some nasty bug, related fields are not written upon record creation.
+        # Hence we write on those fields here.
+        vals = {}
+        for fname, field in self._columns.iteritems():
+            if isinstance(field, fields.related) and fname in values:
+                vals[fname] = values[fname]
+        self.write(cr, uid, [id], vals, context)
+        return id
 
-        if fiscalyear_ids:
-            res.update({'fiscalyear_id': fiscalyear_ids[0]})
-        if taxes:
-            if chart_template_ids:
-                sale_tax_id = taxes.get('taxes_id')
-                res.update({'taxes_id': isinstance(sale_tax_id,list) and sale_tax_id[0] or sale_tax_id})
-                purchase_tax_id = taxes.get('supplier_taxes_id')
-                res.update({'supplier_taxes_id': isinstance(purchase_tax_id,list) and purchase_tax_id[0] or purchase_tax_id})
-        else:
-            res.update({'sale_tax_rate': 15.0, 'purchase_tax_rate': 15.0})
-        return res
+    def onchange_company_id(self, cr, uid, ids, company_id, context=None):
+        # update related fields
+        values = {}
+        values['currency_id'] = False
+        if company_id:
+            company = self.pool.get('res.company').browse(cr, uid, company_id, context=context)
+            has_chart_of_accounts = company_id not in self.pool.get('account.installer').get_unconfigured_cmp(cr, uid)
+            fiscalyear_count = self.pool.get('account.fiscalyear').search_count(cr, uid,
+                [('date_start', '<=', time.strftime('%Y-%m-%d')), ('date_stop', '>=', time.strftime('%Y-%m-%d')),
+                 ('company_id', '=', company_id)])
+            date_start, date_stop, period = self._get_default_fiscalyear_data(cr, uid, company_id, context=context)
+            values = {
+                'expects_chart_of_accounts': company.expects_chart_of_accounts,
+                'currency_id': company.currency_id.id,
+                'paypal_account': company.paypal_account,
+                'company_footer': company.rml_footer,
+                'has_chart_of_accounts': has_chart_of_accounts,
+                'has_fiscal_year': bool(fiscalyear_count),
+                'chart_template_id': False,
+                'tax_calculation_rounding_method': company.tax_calculation_rounding_method,
+                'date_start': date_start,
+                'date_stop': date_stop,
+                'period': period,
+            }
+            # update journals and sequences
+            for journal_type in ('sale', 'sale_refund', 'purchase', 'purchase_refund'):
+                for suffix in ('_journal_id', '_sequence_prefix', '_sequence_next'):
+                    values[journal_type + suffix] = False
+            journal_obj = self.pool.get('account.journal')
+            journal_ids = journal_obj.search(cr, uid, [('company_id', '=', company_id)])
+            for journal in journal_obj.browse(cr, uid, journal_ids):
+                if journal.type in ('sale', 'sale_refund', 'purchase', 'purchase_refund'):
+                    values.update({
+                        journal.type + '_journal_id': journal.id,
+                        journal.type + '_sequence_prefix': journal.sequence_id.prefix,
+                        journal.type + '_sequence_next': journal.sequence_id.number_next,
+                    })
+            # update taxes
+            ir_values = self.pool.get('ir.values')
+            taxes_id = ir_values.get_default(cr, uid, 'product.product', 'taxes_id', company_id=company_id)
+            supplier_taxes_id = ir_values.get_default(cr, uid, 'product.product', 'supplier_taxes_id', company_id=company_id)
+            values.update({
+                'default_sale_tax': isinstance(taxes_id, list) and taxes_id[0] or taxes_id,
+                'default_purchase_tax': isinstance(supplier_taxes_id, list) and supplier_taxes_id[0] or supplier_taxes_id,
+            })
+        return {'value': values}
 
-    def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
-        ir_values_obj = self.pool.get('ir.values')
-        res = super(account_configuration, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar, submenu)
-        cmp_select = []
-        # display in the widget selection only the companies that haven't been configured yet
-        unconfigured_cmp = self.get_unconfigured_cmp(cr, uid, context=context)
-        for field in res['fields']:
-            if field == 'company_id':
-                res['fields'][field]['domain'] = [('id','in',unconfigured_cmp)]
-                res['fields'][field]['selection'] = [('', '')]
-                if unconfigured_cmp:
-                    cmp_select = [(line.id, line.name) for line in self.pool.get('res.company').browse(cr, uid, unconfigured_cmp)]
-                    res['fields'][field]['selection'] = cmp_select
+    def onchange_chart_template_id(self, cr, uid, ids, chart_template_id, context=None):
+        tax_templ_obj = self.pool.get('account.tax.template')
+        res = {'value': {
+            'complete_tax_set': False, 'sale_tax': False, 'purchase_tax': False,
+            'sale_tax_rate': 15, 'purchase_tax_rate': 15,
+        }}
+        if chart_template_id:
+            # update complete_tax_set, sale_tax and purchase_tax
+            chart_template = self.pool.get('account.chart.template').browse(cr, uid, chart_template_id, context=context)
+            res['value'].update({'complete_tax_set': chart_template.complete_tax_set})
+            if chart_template.complete_tax_set:
+                # default tax is given by the lowest sequence. For same sequence we will take the latest created as it will be the case for tax created while isntalling the generic chart of account
+                sale_tax_ids = tax_templ_obj.search(cr, uid,
+                    [("chart_template_id", "=", chart_template_id), ('type_tax_use', 'in', ('sale','all'))],
+                    order="sequence, id desc")
+                purchase_tax_ids = tax_templ_obj.search(cr, uid,
+                    [("chart_template_id", "=", chart_template_id), ('type_tax_use', 'in', ('purchase','all'))],
+                    order="sequence, id desc")
+                res['value']['sale_tax'] = sale_tax_ids and sale_tax_ids[0] or False
+                res['value']['purchase_tax'] = purchase_tax_ids and purchase_tax_ids[0] or False
+            if chart_template.code_digits:
+                res['value']['code_digits'] = chart_template.code_digits
         return res
 
-    def get_unconfigured_cmp(self, cr, uid, context=None):
-        """ get the list of companies that have not been configured yet
-        but don't care about the demo chart of accounts """
-        cmp_select = []
-        company_ids = self.pool.get('res.company').search(cr, uid, [], context=context)
-        cr.execute("SELECT company_id FROM account_account WHERE active = 't' AND account_account.parent_id IS NULL AND name != %s", ("Chart For Automated Tests",))
-        configured_cmp = [r[0] for r in cr.fetchall()]
-        return list(set(company_ids)-set(configured_cmp))
+    def onchange_tax_rate(self, cr, uid, ids, rate, context=None):
+        return {'value': {'purchase_tax_rate': rate or False}}
 
-    def check_unconfigured_cmp(self, cr, uid, context=None):
-        """ check if there are still unconfigured companies """
-        if not self.get_unconfigured_cmp(cr, uid, context=context):
-            raise osv.except_osv(_('No unconfigured company !'), _("There are currently no company without chart of account. The wizard will therefore not be executed."))
-
-    def on_change_start_date(self, cr, uid, id, start_date=False):
+    def onchange_start_date(self, cr, uid, id, start_date):
         if start_date:
             start_date = datetime.datetime.strptime(start_date, "%Y-%m-%d")
             end_date = (start_date + relativedelta(months=12)) - relativedelta(days=1)
             return {'value': {'date_stop': end_date.strftime('%Y-%m-%d')}}
         return {}
 
-    def on_change_company_id(self, cr, uid, id, company_id=False):
-        company_obj = self.pool.get('res.company')
-        currency_id = company_obj.browse(cr, uid, company_id).currency_id
-        return {'value': {'currency_id': currency_id.id}}
+    def open_company_form(self, cr, uid, ids, context=None):
+        config = self.browse(cr, uid, ids[0], context)
+        return {
+            'type': 'ir.actions.act_window',
+            'name': 'Configure your Company',
+            'res_model': 'res.company',
+            'res_id': config.company_id.id,
+            'view_mode': 'form',
+        }
 
-    def install_chartofaccounts(self, cr, uid, ids, context=None):
-        ir_module = self.pool.get('ir.module.module')
-        multi_chart_obj = self.pool.get('wizard.multi.charts.accounts')
-        chart_template_obj = self.pool.get('account.chart.template')
-        tax_templ_obj = self.pool.get('account.tax.template')
+    def set_default_taxes(self, cr, uid, ids, context=None):
+        """ set default sale and purchase taxes for products """
+        ir_values = self.pool.get('ir.values')
+        config = self.browse(cr, uid, ids[0], context)
+        ir_values.set_default(cr, uid, 'product.product', 'taxes_id',
+            config.default_sale_tax and [config.default_sale_tax.id] or False, company_id=config.company_id.id)
+        ir_values.set_default(cr, uid, 'product.product', 'supplier_taxes_id',
+            config.default_purchase_tax and [config.default_purchase_tax.id] or False, company_id=config.company_id.id)
 
-        data = self.read(cr, uid, ids, context=context)[0]
-        if context is None:
-            context = {}
-        for res in self.read(cr, uid, ids, context=context):
-            chart = res.get('charts')
-            if chart == 'configurable':
-                #load generic chart of account
-                fp = tools.file_open(opj('account', 'configurable_account_chart.xml'))
-                tools.convert_xml_import(cr, 'account', fp, {}, 'init', True, None)
-                fp.close()
-            elif chart.startswith('l10n_'):
-                mod_ids = ir_module.search(cr, uid, [('name','=',chart)])
-                if mod_ids and ir_module.browse(cr, uid, mod_ids[0], context).state == 'uninstalled':
-                    ir_module.button_immediate_install(cr, uid, mod_ids, context)
+    def set_chart_of_accounts(self, cr, uid, ids, context=None):
+        """ install a chart of accounts for the given company (if required) """
+        config = self.browse(cr, uid, ids[0], context)
+        if config.chart_template_id:
+            assert config.expects_chart_of_accounts and not config.has_chart_of_accounts
+            wizard = self.pool.get('wizard.multi.charts.accounts')
+            wizard_id = wizard.create(cr, uid, {
+                'company_id': config.company_id.id,
+                'chart_template_id': config.chart_template_id.id,
+                'code_digits': config.code_digits or 6,
+                'sale_tax': config.sale_tax.id,
+                'purchase_tax': config.purchase_tax.id,
+                'sale_tax_rate': config.sale_tax_rate,
+                'purchase_tax_rate': config.purchase_tax_rate,
+                'complete_tax_set': config.complete_tax_set,
+                'currency_id': config.currency_id.id,
+            }, context)
+            wizard.execute(cr, uid, [wizard_id], context)
 
-        chart_template_ids = chart_template_obj.search(cr, uid, [('visible', '=', True)], context=context)
-        complete_tax_set = chart_template_obj.browse(cr, uid, chart_template_ids[0]).complete_tax_set
-        if not complete_tax_set:
-            code_digits = multi_chart_obj.onchange_chart_template_id(cr, uid, [], chart_template_ids[0], context=context)['value']['code_digits']
-            object_id = multi_chart_obj.create(cr, uid, {'code_digits': code_digits , 'sale_tax_rate':data['sale_tax_rate'], 'purchase_tax_rate': data['purchase_tax_rate']}, context=context)
-            multi_chart_obj.execute(cr, uid, [object_id], context=context)
+    def set_fiscalyear(self, cr, uid, ids, context=None):
+        """ create a fiscal year for the given company (if necessary) """
+        config = self.browse(cr, uid, ids[0], context)
+        if config.has_chart_of_accounts or config.chart_template_id:
+            fiscalyear = self.pool.get('account.fiscalyear')
+            fiscalyear_count = fiscalyear.search_count(cr, uid,
+                [('date_start', '<=', config.date_start), ('date_stop', '>=', config.date_stop),
+                 ('company_id', '=', config.company_id.id)],
+                context=context)
+            if not fiscalyear_count:
+                name = code = config.date_start[:4]
+                if int(name) != int(config.date_stop[:4]):
+                    name = config.date_start[:4] +'-'+ config.date_stop[:4]
+                    code = config.date_start[2:4] +'-'+ config.date_stop[2:4]
+                vals = {
+                    'name': name,
+                    'code': code,
+                    'date_start': config.date_start,
+                    'date_stop': config.date_stop,
+                    'company_id': config.company_id.id,
+                }
+                fiscalyear_id = fiscalyear.create(cr, uid, vals, context=context)
+                if config.period == 'month':
+                    fiscalyear.create_period(cr, uid, [fiscalyear_id])
+                elif config.period == '3months':
+                    fiscalyear.create_period3(cr, uid, [fiscalyear_id])
 
-    def configure_fiscalyear(self, cr, uid, ids, context=None):
-        if context is None:
-            context = {}
-        fy_obj = self.pool.get('account.fiscalyear')
-        for res in self.read(cr, uid, ids, context=context):
-            if 'date_start' in res and 'date_stop' in res:
-                f_ids = fy_obj.search(cr, uid, [('date_start', '<=', res['date_start']), ('date_stop', '>=', res['date_stop']), ('company_id', '=', res['company_id'][0])], context=context)
-                if not f_ids:
-                    name = code = res['date_start'][:4]
-                    if int(name) != int(res['date_stop'][:4]):
-                        name = res['date_start'][:4] +'-'+ res['date_stop'][:4]
-                        code = res['date_start'][2:4] +'-'+ res['date_stop'][2:4]
-                    vals = {
-                        'name': name,
-                        'code': code,
-                        'date_start': res['date_start'],
-                        'date_stop': res['date_stop'],
-                        'company_id': res['company_id'][0]
-                    }
-                    fiscal_id = fy_obj.create(cr, uid, vals, context=context)
-                    if res['period'] == 'month':
-                        fy_obj.create_period(cr, uid, [fiscal_id])
-                    elif res['period'] == '3months':
-                        fy_obj.create_period3(cr, uid, [fiscal_id])
+    def get_default_dp(self, cr, uid, fields, context=None):
+        dp = self.pool.get('ir.model.data').get_object(cr, uid, 'product','decimal_account')
+        return {'decimal_precision': dp.digits}
 
-account_configuration()
+    def set_default_dp(self, cr, uid, ids, context=None):
+        config = self.browse(cr, uid, ids[0], context)
+        dp = self.pool.get('ir.model.data').get_object(cr, uid, 'product','decimal_account')
+        dp.write({'digits': config.decimal_precision})
 
-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
\ No newline at end of file
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: