diff --git a/addons/account/account.py b/addons/account/account.py index bfc16a4c419..e5e29f178a3 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -1398,7 +1398,7 @@ class account_move(osv.osv): if not l[0]: l[2].update({ 'reconcile_id':False, - 'reconcil_partial_id':False, + 'reconcile_partial_id':False, 'analytic_lines':False, 'invoice':False, 'ref':False, @@ -2516,22 +2516,25 @@ class account_account_template(osv.osv): 'nocreate': False, } - def _check_type(self, cr, uid, ids, context=None): - if context is None: - context = {} - accounts = self.browse(cr, uid, ids, context=context) - for account in accounts: - if account.parent_id and account.parent_id.type != 'view': - return False - return True - _check_recursion = check_cycle _constraints = [ (_check_recursion, 'Error!\nYou cannot create recursive account templates.', ['parent_id']), - (_check_type, 'Configuration Error!\nYou cannot define children to an account that has internal type other than "View".', ['type']), - ] + def create(self, cr, uid, vals, context=None): + if 'parent_id' in vals: + parent = self.read(cr, uid, [vals['parent_id']], ['type']) + if parent and parent[0]['type'] != 'view': + raise osv.except_osv(_('Warning!'), _("You may only select a parent account of type 'View'.")) + return super(account_account_template, self).create(cr, uid, vals, context=context) + + def write(self, cr, uid, ids, vals, context=None): + if 'parent_id' in vals: + parent = self.read(cr, uid, [vals['parent_id']], ['type']) + if parent and parent[0]['type'] != 'view': + raise osv.except_osv(_('Warning!'), _("You may only select a parent account of type 'View'.")) + return super(account_account_template, self).write(cr, uid, ids, vals, context=context) + def name_get(self, cr, uid, ids, context=None): if not ids: return [] @@ -2999,6 +3002,7 @@ class wizard_multi_charts_accounts(osv.osv_memory): _columns = { 'company_id':fields.many2one('res.company', 'Company', required=True), + 'currency_id': fields.many2one('res.currency', 'Currency', help="Currency as per company's country."), 'only_one_chart_template': fields.boolean('Only One Chart Template Available'), 'chart_template_id': fields.many2one('account.chart.template', 'Chart Template', required=True), 'bank_accounts_id': fields.one2many('account.bank.accounts.wizard', 'bank_account_id', 'Cash and Banks', required=True), @@ -3009,6 +3013,13 @@ class wizard_multi_charts_accounts(osv.osv_memory): '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'), } + + def onchange_company_id(self, cr, uid, ids, company_id, context=None): + currency_id = False + if company_id: + currency_id = self.pool.get('res.company').browse(cr, uid, company_id, context=context).currency_id.id + return {'value': {'currency_id': currency_id}} + def onchange_tax_rate(self, cr, uid, ids, rate=False, context=None): return {'value': {'purchase_tax_rate': rate or False}} @@ -3039,6 +3050,13 @@ class wizard_multi_charts_accounts(osv.osv_memory): res.update({'bank_accounts_id': [{'acc_name': _('Cash'), 'account_type': 'cash'},{'acc_name': _('Bank'), 'account_type': 'bank'}]}) if 'company_id' in fields: res.update({'company_id': self.pool.get('res.users').browse(cr, uid, [uid], context=context)[0].company_id.id}) + if 'currency_id' in fields: + company_id = res.get('company_id') or False + if company_id: + company_obj = self.pool.get('res.company') + country_id = company_obj.browse(cr, uid, company_id, context=context).country_id.id + currency_id = company_obj.on_change_country(cr, uid, company_id, country_id, context=context)['value']['currency_id'] + res.update({'currency_id': currency_id}) ids = self.pool.get('account.chart.template').search(cr, uid, [('visible', '=', True)], context=context) if ids: @@ -3343,6 +3361,7 @@ class wizard_multi_charts_accounts(osv.osv_memory): ir_values_obj = self.pool.get('ir.values') obj_wizard = self.browse(cr, uid, ids[0]) company_id = obj_wizard.company_id.id + self.pool.get('res.company').write(cr, uid, [company_id], {'currency_id': obj_wizard.currency_id.id}) # If the floats for sale/purchase rates have been filled, create templates from them self._create_tax_templates_from_rates(cr, uid, obj_wizard, company_id, context=context) diff --git a/addons/account/account_bank_view.xml b/addons/account/account_bank_view.xml index 8ceb8a91885..ef793a1bef5 100644 --- a/addons/account/account_bank_view.xml +++ b/addons/account/account_bank_view.xml @@ -15,7 +15,7 @@ - + @@ -28,7 +28,7 @@ - + diff --git a/addons/account/account_installer.xml b/addons/account/account_installer.xml index c92d4eda602..58e824a6250 100644 --- a/addons/account/account_installer.xml +++ b/addons/account/account_installer.xml @@ -14,8 +14,12 @@ +

+ Select a configuration package to setup automatically your + taxes and chart of accounts. +

- + @@ -32,7 +36,7 @@ - Configure your Chart of Accounts + Configure Accounting Data ir.actions.act_window account.installer diff --git a/addons/account/account_invoice.py b/addons/account/account_invoice.py index 15027b7a8f6..bbcb25fefa9 100644 --- a/addons/account/account_invoice.py +++ b/addons/account/account_invoice.py @@ -214,7 +214,7 @@ class account_invoice(osv.osv): \n* The \'Cancelled\' state is used when user cancel invoice.'), 'sent': fields.boolean('Sent', readonly=True, help="It indicates that the invoice has been sent."), 'date_invoice': fields.date('Invoice Date', readonly=True, states={'draft':[('readonly',False)]}, select=True, help="Keep empty to use the current date"), - 'date_due': fields.date('Due Date', states={'paid':[('readonly',True)], 'open':[('readonly',True)], 'close':[('readonly',True)]}, select=True, + 'date_due': fields.date('Due Date', readonly=True, states={'draft':[('readonly',False)]}, select=True, help="If you use payment terms, the due date will be computed automatically at the generation "\ "of accounting entries. If you keep the payment term and the due date empty, it means direct payment. The payment term may compute several due dates, for example 50% now, 50% in one month."), 'partner_id': fields.many2one('res.partner', 'Partner', change_default=True, readonly=True, required=True, states={'draft':[('readonly',False)]}), @@ -253,7 +253,7 @@ class account_invoice(osv.osv): 'currency_id': fields.many2one('res.currency', 'Currency', required=True, readonly=True, states={'draft':[('readonly',False)]}), 'journal_id': fields.many2one('account.journal', 'Journal', required=True, readonly=True, states={'draft':[('readonly',False)]}), 'company_id': fields.many2one('res.company', 'Company', required=True, change_default=True, readonly=True, states={'draft':[('readonly',False)]}), - 'check_total': fields.float('Verification Total', digits_compute=dp.get_precision('Account'), states={'open':[('readonly',True)],'close':[('readonly',True)]}), + 'check_total': fields.float('Verification Total', digits_compute=dp.get_precision('Account'), readonly=True, states={'draft':[('readonly',False)]}), 'reconciled': fields.function(_reconciled, string='Paid/Reconciled', type='boolean', store={ 'account.invoice': (lambda self, cr, uid, ids, c={}: ids, None, 50), # Check if we can remove ? @@ -395,18 +395,23 @@ class account_invoice(osv.osv): template_id = template and template[1] or False res = mod_obj.get_object_reference(cr, uid, 'mail', 'email_compose_message_wizard_form') res_id = res and res[1] or False - ctx = dict(context, active_model='account.invoice', active_id=ids[0]) - ctx.update({'mail.compose.template_id': template_id}) + ctx = dict(context) + ctx.update({ + 'default_model': 'account.invoice', + 'default_res_id': ids[0], + 'default_use_template': True, + 'default_template_id': template_id, + }) return { - 'view_type': 'form', - 'view_mode': 'form', - 'res_model': 'mail.compose.message', - 'views': [(res_id, 'form')], - 'view_id': res_id, - 'type': 'ir.actions.act_window', - 'target': 'new', - 'context': ctx, - 'nodestroy': True, + 'view_type': 'form', + 'view_mode': 'form', + 'res_model': 'mail.compose.message', + 'views': [(res_id, 'form')], + 'view_id': res_id, + 'type': 'ir.actions.act_window', + 'target': 'new', + 'context': ctx, + 'nodestroy': True, } def confirm_paid(self, cr, uid, ids, context=None): @@ -767,17 +772,20 @@ class account_invoice(osv.osv): if not key in tax_key: raise osv.except_osv(_('Warning!'), _('Taxes are missing!\nClick on compute button.')) - def compute_invoice_totals(self, cr, uid, inv, company_currency, ref, invoice_move_lines): + def compute_invoice_totals(self, cr, uid, inv, company_currency, ref, invoice_move_lines, context=None): + if context is None: + context={} total = 0 total_currency = 0 cur_obj = self.pool.get('res.currency') for i in invoice_move_lines: if inv.currency_id.id != company_currency: + context.update({'date': inv.date_invoice or time.strftime('%Y-%m-%d')}) i['currency_id'] = inv.currency_id.id i['amount_currency'] = i['price'] i['price'] = cur_obj.compute(cr, uid, inv.currency_id.id, company_currency, i['price'], - context={'date': inv.date_invoice or time.strftime('%Y-%m-%d')}) + context=context) else: i['amount_currency'] = False i['currency_id'] = False @@ -887,7 +895,7 @@ class account_invoice(osv.osv): # create one move line for the total and possibly adjust the other lines amount total = 0 total_currency = 0 - total, total_currency, iml = self.compute_invoice_totals(cr, uid, inv, company_currency, ref, iml) + total, total_currency, iml = self.compute_invoice_totals(cr, uid, inv, company_currency, ref, iml, context=ctx) acc_id = inv.account_id.id name = inv['name'] or '/' diff --git a/addons/account/account_invoice_view.xml b/addons/account/account_invoice_view.xml index 610485ec3a0..1c4d83106ca 100644 --- a/addons/account/account_invoice_view.xml +++ b/addons/account/account_invoice_view.xml @@ -127,7 +127,7 @@ - + @@ -184,7 +184,7 @@ name="account_id" groups="account.group_account_user"/> - + @@ -271,7 +271,7 @@ - + @@ -332,8 +332,8 @@ -