Merge lp:~openerp/openobject-addons/6.0-search-account-journal-view-using-xml_id-instead-of-name-olt into lp:openobject-addons/6.0

Proposed by Olivier Laurent (Open ERP)
Status: Needs review
Proposed branch: lp:~openerp/openobject-addons/6.0-search-account-journal-view-using-xml_id-instead-of-name-olt
Merge into: lp:openobject-addons/6.0
Diff against target: 83 lines (+15/-17)
1 file modified
account/installer.py (+15/-17)
To merge this branch: bzr merge lp:~openerp/openobject-addons/6.0-search-account-journal-view-using-xml_id-instead-of-name-olt
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+83734@code.launchpad.net

Description of the change

account/installer.py
--------------------

Journal view searches were using the name and so resulted in a crash if this name was changed by the user.

It now uses the journal view xml_id instead of its name.

To post a comment you must log in.

Unmerged revisions

4859. By Olivier Laurent (Open ERP)

[FIX] account: installer.py: search using xml_id instead of 'name' (customer can change the journal view name resulting in a crash)
[FIX] account: installer.py: fixed wrong indentation

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'account/installer.py'
--- account/installer.py 2011-07-14 13:03:52 +0000
+++ account/installer.py 2011-11-29 07:53:27 +0000
@@ -107,12 +107,12 @@
107 configured_cmp = [r[0] for r in cr.fetchall()]107 configured_cmp = [r[0] for r in cr.fetchall()]
108 unconfigured_cmp = list(set(company_ids)-set(configured_cmp))108 unconfigured_cmp = list(set(company_ids)-set(configured_cmp))
109 for field in res['fields']:109 for field in res['fields']:
110 if field == 'company_id':110 if field == 'company_id':
111 res['fields'][field]['domain'] = [('id','in',unconfigured_cmp)]111 res['fields'][field]['domain'] = [('id','in',unconfigured_cmp)]
112 res['fields'][field]['selection'] = [('', '')]112 res['fields'][field]['selection'] = [('', '')]
113 if unconfigured_cmp:113 if unconfigured_cmp:
114 cmp_select = [(line.id, line.name) for line in self.pool.get('res.company').browse(cr, uid, unconfigured_cmp)]114 cmp_select = [(line.id, line.name) for line in self.pool.get('res.company').browse(cr, uid, unconfigured_cmp)]
115 res['fields'][field]['selection'] = cmp_select115 res['fields'][field]['selection'] = cmp_select
116 return res116 return res
117117
118 def on_change_tax(self, cr, uid, id, tax):118 def on_change_tax(self, cr, uid, id, tax):
@@ -136,7 +136,6 @@
136 obj_fiscal_position = self.pool.get('account.fiscal.position')136 obj_fiscal_position = self.pool.get('account.fiscal.position')
137 analytic_journal_obj = self.pool.get('account.analytic.journal')137 analytic_journal_obj = self.pool.get('account.analytic.journal')
138 obj_acc_chart_template = self.pool.get('account.chart.template')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')139 mod_obj = self.pool.get('ir.model.data')
141 obj_sequence = self.pool.get('ir.sequence')140 obj_sequence = self.pool.get('ir.sequence')
142 property_obj = self.pool.get('ir.property')141 property_obj = self.pool.get('ir.property')
@@ -265,8 +264,11 @@
265 }264 }
266 bank_account = obj_acc.create(cr, uid, b_vals, context=ctx)265 bank_account = obj_acc.create(cr, uid, b_vals, context=ctx)
267266
268 view_id_cash = obj_acc_journal_view.search(cr, uid, [('name', '=', 'Bank/Cash Journal View')], context=context)[0] #why fixed name here?267 view_cash_result = mod_obj.get_object_reference(cr, uid, 'account', 'account_journal_bank_view')
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?268 view_cash_id = view_cash_result and view_cash_result[1] or False
269
270 view_multi_result = mod_obj.get_object_reference(cr, uid, 'account', 'account_journal_bank_view_multi')
271 view_multi_id = view_multi_result and view_multi_result[1] or False
270272
271 cash_result = mod_obj.get_object_reference(cr, uid, 'account', 'conf_account_type_cash')273 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 False274 cash_type_id = cash_result and cash_result[1] or False
@@ -301,11 +303,11 @@
301 }303 }
302 if vals.get('currency_id', False):304 if vals.get('currency_id', False):
303 vals_journal.update({305 vals_journal.update({
304 'view_id': view_id_cur,306 'view_id': view_multi_id,
305 'currency': vals.get('currency_id', False)307 'currency': vals.get('currency_id', False)
306 })308 })
307 else:309 else:
308 vals_journal.update({'view_id': view_id_cash})310 vals_journal.update({'view_id': view_cash_id})
309 vals_journal.update({311 vals_journal.update({
310 'default_credit_account_id': new_account,312 'default_credit_account_id': new_account,
311 'default_debit_account_id': new_account,313 'default_debit_account_id': new_account,
@@ -353,11 +355,11 @@
353 }355 }
354 if vals.get('currency_id', False):356 if vals.get('currency_id', False):
355 vals_journal.update({357 vals_journal.update({
356 'view_id': view_id_cur,358 'view_id': view_multi_id,
357 'currency': vals_bnk.get('currency_id', False),359 'currency': vals_bnk.get('currency_id', False),
358 })360 })
359 else:361 else:
360 vals_journal.update({'view_id': view_id_cash})362 vals_journal.update({'view_id': view_cash_id})
361 vals_journal.update({363 vals_journal.update({
362 'default_credit_account_id': child_bnk_acc,364 'default_credit_account_id': child_bnk_acc,
363 'default_debit_account_id': child_bnk_acc,365 'default_debit_account_id': child_bnk_acc,
@@ -508,10 +510,6 @@
508 })510 })
509 obj_journal.create(cr, uid, vals_journal, context=context)511 obj_journal.create(cr, uid, vals_journal, context=context)
510512
511 # Bank Journals
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?
514
515 #create the properties513 #create the properties
516 todo_list = [514 todo_list = [
517 ('property_account_receivable', 'res.partner', 'account.account'),515 ('property_account_receivable', 'res.partner', 'account.account'),