diff --git a/addons/account/account.py b/addons/account/account.py index 57356f7d3ef..d4e31167c43 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -2338,6 +2338,16 @@ class account_model(osv.osv): return move_ids + def onchange_journal_id(self, cr, uid, ids, journal_id, context=None): + company_id = False + + if journal_id: + journal = self.pool.get('account.journal').browse(cr, uid, journal_id, context=context) + if journal.company_id.id: + company_id = journal.company_id.id + + return {'value': {'company_id': company_id}} + account_model() class account_model_line(osv.osv): @@ -2516,22 +2526,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 [] @@ -3010,9 +3023,9 @@ 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 + 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}} diff --git a/addons/account/account_bank.py b/addons/account/account_bank.py index ef146128a67..e44d2acd163 100644 --- a/addons/account/account_bank.py +++ b/addons/account/account_bank.py @@ -43,11 +43,15 @@ class bank(osv.osv): "Return the name to use when creating a bank journal" return (bank.bank_name or '') + ' ' + bank.acc_number - def _prepare_name_get(self, cr, uid, bank_type_obj, bank_obj, context=None): - """Add ability to have %(currency_name)s in the format_layout of - res.partner.bank.type""" - bank_obj._data[bank_obj.id]['currency_name'] = bank_obj.currency_id and bank_obj.currency_id.name or '' - return super(bank, self)._prepare_name_get(cr, uid, bank_type_obj, bank_obj, context=context) + def _prepare_name_get(self, cr, uid, bank_dicts, context=None): + """Add ability to have %(currency_name)s in the format_layout of res.partner.bank.type""" + currency_ids = list(set(data['currency_id'][0] for data in bank_dicts if data['currency_id'])) + currencies = self.pool.get('res.currency').browse(cr, uid, currency_ids, context=context) + currency_name = dict((currency.id, currency.name) for currency in currencies) + + for data in bank_dicts: + data['currency_name'] = data['currency_id'] and currency_name[data['currency_id'][0]] or '' + return super(bank, self)._prepare_name_get(cr, uid, bank_dicts, context=context) def post_write(self, cr, uid, ids, context={}): if isinstance(ids, (int, long)): 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 42d42e7ec1b..bbcb25fefa9 100644 --- a/addons/account/account_invoice.py +++ b/addons/account/account_invoice.py @@ -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_view.xml b/addons/account/account_view.xml index 5a3fd6b748a..d1b19910365 100644 --- a/addons/account/account_view.xml +++ b/addons/account/account_view.xml @@ -112,7 +112,7 @@ @@ -181,7 +181,7 @@