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
1=== modified file 'account/installer.py'
2--- account/installer.py 2011-07-14 13:03:52 +0000
3+++ account/installer.py 2011-11-29 07:53:27 +0000
4@@ -107,12 +107,12 @@
5 configured_cmp = [r[0] for r in cr.fetchall()]
6 unconfigured_cmp = list(set(company_ids)-set(configured_cmp))
7 for field in res['fields']:
8- if field == 'company_id':
9- res['fields'][field]['domain'] = [('id','in',unconfigured_cmp)]
10- res['fields'][field]['selection'] = [('', '')]
11- if unconfigured_cmp:
12- cmp_select = [(line.id, line.name) for line in self.pool.get('res.company').browse(cr, uid, unconfigured_cmp)]
13- res['fields'][field]['selection'] = cmp_select
14+ if field == 'company_id':
15+ res['fields'][field]['domain'] = [('id','in',unconfigured_cmp)]
16+ res['fields'][field]['selection'] = [('', '')]
17+ if unconfigured_cmp:
18+ cmp_select = [(line.id, line.name) for line in self.pool.get('res.company').browse(cr, uid, unconfigured_cmp)]
19+ res['fields'][field]['selection'] = cmp_select
20 return res
21
22 def on_change_tax(self, cr, uid, id, tax):
23@@ -136,7 +136,6 @@
24 obj_fiscal_position = self.pool.get('account.fiscal.position')
25 analytic_journal_obj = self.pool.get('account.analytic.journal')
26 obj_acc_chart_template = self.pool.get('account.chart.template')
27- obj_acc_journal_view = self.pool.get('account.journal.view')
28 mod_obj = self.pool.get('ir.model.data')
29 obj_sequence = self.pool.get('ir.sequence')
30 property_obj = self.pool.get('ir.property')
31@@ -265,8 +264,11 @@
32 }
33 bank_account = obj_acc.create(cr, uid, b_vals, context=ctx)
34
35- view_id_cash = obj_acc_journal_view.search(cr, uid, [('name', '=', 'Bank/Cash Journal View')], context=context)[0] #why fixed name here?
36- view_id_cur = obj_acc_journal_view.search(cr, uid, [('name', '=', 'Bank/Cash Journal (Multi-Currency) View')], context=context)[0] #Why Fixed name here?
37+ view_cash_result = mod_obj.get_object_reference(cr, uid, 'account', 'account_journal_bank_view')
38+ view_cash_id = view_cash_result and view_cash_result[1] or False
39+
40+ view_multi_result = mod_obj.get_object_reference(cr, uid, 'account', 'account_journal_bank_view_multi')
41+ view_multi_id = view_multi_result and view_multi_result[1] or False
42
43 cash_result = mod_obj.get_object_reference(cr, uid, 'account', 'conf_account_type_cash')
44 cash_type_id = cash_result and cash_result[1] or False
45@@ -301,11 +303,11 @@
46 }
47 if vals.get('currency_id', False):
48 vals_journal.update({
49- 'view_id': view_id_cur,
50+ 'view_id': view_multi_id,
51 'currency': vals.get('currency_id', False)
52 })
53 else:
54- vals_journal.update({'view_id': view_id_cash})
55+ vals_journal.update({'view_id': view_cash_id})
56 vals_journal.update({
57 'default_credit_account_id': new_account,
58 'default_debit_account_id': new_account,
59@@ -353,11 +355,11 @@
60 }
61 if vals.get('currency_id', False):
62 vals_journal.update({
63- 'view_id': view_id_cur,
64+ 'view_id': view_multi_id,
65 'currency': vals_bnk.get('currency_id', False),
66 })
67 else:
68- vals_journal.update({'view_id': view_id_cash})
69+ vals_journal.update({'view_id': view_cash_id})
70 vals_journal.update({
71 'default_credit_account_id': child_bnk_acc,
72 'default_debit_account_id': child_bnk_acc,
73@@ -508,10 +510,6 @@
74 })
75 obj_journal.create(cr, uid, vals_journal, context=context)
76
77- # Bank Journals
78- view_id_cash = obj_acc_journal_view.search(cr, uid, [('name', '=', 'Bank/Cash Journal View')], context=context)[0] #TOFIX: Why put fixed name ?
79- 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?
80-
81 #create the properties
82 todo_list = [
83 ('property_account_receivable', 'res.partner', 'account.account'),