~syleam/+junk/document_csv

« back to all changes in this revision

Viewing changes to object/ir_model.py

  • Committer: Christophe Chauvet
  • Date: 2010-03-09 13:52:33 UTC
  • Revision ID: christophe.chauvet@syleam.fr-20100309135233-zkfm12ll7hnrmzbk
[ADD] When select the field for the model, retrieve the fields in these inherits

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    document_csv module for OpenERP
 
5
#    Copyright (C) 2009 SYLEAM (<http://www.syleam.fr>) Christophe CHAUVET
 
6
#
 
7
#    This file is a part of document_csv
 
8
#
 
9
#    document_csv is free software: you can redistribute it and/or modify
 
10
#    it under the terms of the GNU General Public License as published by
 
11
#    the Free Software Foundation, either version 3 of the License, or
 
12
#    (at your option) any later version.
 
13
#
 
14
#    document_csv is distributed in the hope that it will be useful,
 
15
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
#    GNU General Public License for more details.
 
18
#
 
19
#    You should have received a copy of the GNU General Public License
 
20
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
21
#
 
22
##############################################################################
 
23
 
 
24
from osv import osv
 
25
from osv import fields
 
26
 
 
27
class ir_model_fields(osv.osv):
 
28
    _inherit = 'ir.model.fields'
 
29
 
 
30
    def name_search(self, cr, uid, name, args=None, operator='ilike', context=None, limit=80):
 
31
        """
 
32
        Extend this method to retrieve the model and these inherits
 
33
        """
 
34
        if context.get('import'):
 
35
            model_obj = self.pool.get('ir.model')
 
36
            model = model_obj.read(cr, uid, args[0][2], ['model'])
 
37
            inherits = self.pool.get(model['model'])._inherits
 
38
            if inherits:
 
39
                mod_ids = [args[0][2]]
 
40
                for m in inherits:
 
41
                    mod_id = model_obj.search(cr, uid, [('model','=', m)])
 
42
                    mod_ids.append(mod_id[0])
 
43
                args = [('model_id','in', mod_ids)]
 
44
        return super(ir_model_fields, self).name_search(cr, uid, name, args, operator, context, limit)
 
45
 
 
46
ir_model_fields()
 
47
 
 
48
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: