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

« back to all changes in this revision

Viewing changes to account/installer.py

  • Committer: olt at tinyerp
  • Date: 2011-11-28 14:07:51 UTC
  • Revision ID: olt@tinyerp.com-20111128140751-a6zi5m97y8i4vxt4
[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

Show diffs side-by-side

added added

removed removed

Lines of Context:
107
107
        configured_cmp = [r[0] for r in cr.fetchall()]
108
108
        unconfigured_cmp = list(set(company_ids)-set(configured_cmp))
109
109
        for field in res['fields']:
110
 
           if field == 'company_id':
111
 
               res['fields'][field]['domain'] = [('id','in',unconfigured_cmp)]
112
 
               res['fields'][field]['selection'] = [('', '')]
113
 
               if 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_select
 
110
            if field == 'company_id':
 
111
                res['fields'][field]['domain'] = [('id','in',unconfigured_cmp)]
 
112
                res['fields'][field]['selection'] = [('', '')]
 
113
                if 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_select
116
116
        return res
117
117
 
118
118
    def on_change_tax(self, cr, uid, id, tax):
136
136
        obj_fiscal_position = self.pool.get('account.fiscal.position')
137
137
        analytic_journal_obj = self.pool.get('account.analytic.journal')
138
138
        obj_acc_chart_template = self.pool.get('account.chart.template')
139
 
        obj_acc_journal_view = self.pool.get('account.journal.view')
140
139
        mod_obj = self.pool.get('ir.model.data')
141
140
        obj_sequence = self.pool.get('ir.sequence')
142
141
        property_obj = self.pool.get('ir.property')
265
264
                }
266
265
                bank_account = obj_acc.create(cr, uid, b_vals, context=ctx)
267
266
 
268
 
                view_id_cash = obj_acc_journal_view.search(cr, uid, [('name', '=', 'Bank/Cash Journal View')], context=context)[0] #why fixed name here?
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?
 
267
                view_cash_result = mod_obj.get_object_reference(cr, uid, 'account', 'account_journal_bank_view')
 
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
270
272
 
271
273
                cash_result = mod_obj.get_object_reference(cr, uid, 'account', 'conf_account_type_cash')
272
274
                cash_type_id = cash_result and cash_result[1] or False
301
303
                }
302
304
                if vals.get('currency_id', False):
303
305
                    vals_journal.update({
304
 
                        'view_id': view_id_cur,
 
306
                        'view_id': view_multi_id,
305
307
                        'currency': vals.get('currency_id', False)
306
308
                    })
307
309
                else:
308
 
                    vals_journal.update({'view_id': view_id_cash})
 
310
                    vals_journal.update({'view_id': view_cash_id})
309
311
                vals_journal.update({
310
312
                    'default_credit_account_id': new_account,
311
313
                    'default_debit_account_id': new_account,
353
355
                    }
354
356
                    if vals.get('currency_id', False):
355
357
                        vals_journal.update({
356
 
                                'view_id': view_id_cur,
 
358
                                'view_id': view_multi_id,
357
359
                                'currency': vals_bnk.get('currency_id', False),
358
360
                        })
359
361
                    else:
360
 
                        vals_journal.update({'view_id': view_id_cash})
 
362
                        vals_journal.update({'view_id': view_cash_id})
361
363
                    vals_journal.update({
362
364
                        'default_credit_account_id': child_bnk_acc,
363
365
                        'default_debit_account_id': child_bnk_acc,
508
510
            })
509
511
        obj_journal.create(cr, uid, vals_journal, context=context)
510
512
 
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
513
        #create the properties
516
514
        todo_list = [
517
515
            ('property_account_receivable', 'res.partner', 'account.account'),