~unifield-team/unifield-wm/us-826

« back to all changes in this revision

Viewing changes to object_query/query.py

  • Committer: Quentin THEURET
  • Date: 2011-07-31 19:40:10 UTC
  • mto: This revision was merged to the branch mainline in revision 233.
  • Revision ID: qt@tempo-consulting.fr-20110731194010-62un6g3gytslfbwy
UF-376 [IMP] Filtered field.function on list of fields

Show diffs side-by-side

added added

removed removed

Lines of Context:
88
88
        '''
89
89
        Change the value of model_id when the object changes
90
90
        '''
91
 
        res = {'model_ids': []}
 
91
        res = {'model_ids': [], 'selection_ids': [(5,object_id)],
 
92
               'group_by_ids': [],'result_ids': []}
92
93
        
93
94
        obj = self.pool.get('object.query.object')
94
95
        model_obj = self.pool.get('ir.model')
130
131
            for group in query.group_by_ids:
131
132
                search_group += "<filter context=\"{'group_by': '%s'}\" string='%s' domain=\"[]\" />" % (group.name, group.field_description)
132
133
                search_group += "\n"
133
 
                if group not in tree_field_ids:
 
134
                if group.id not in tree_field_ids:
134
135
                    tree_fields += "<field name='%s' invisible=\"1\" />" % (group.name)
 
136
                    tree_fields += "\n"
135
137
 
136
138
                
137
139
            search_arch = '''<search string='%s'>
222
224
    
223
225
    def _search_model_search(self, cr, uid, obj, name, args, context={}):
224
226
        '''
 
227
        Return the domain according to the filter
225
228
        '''
226
229
        if not args:
227
230
            return []
240
243
        
241
244
        return [('id', 'in', res_ids)]
242
245
    
 
246
    def _is_function(self, cr, uid, ids, field_name, args, context={}):
 
247
        '''
 
248
        Determines if the field is a function or not
 
249
        '''
 
250
        res = {}
 
251
        
 
252
        for field in self.browse(cr, uid, ids, context=context):
 
253
            res[field.id] = False
 
254
            if self.pool.get(field.model_id.model)._columns[field.name]._properties:
 
255
                res[field.id] = True
 
256
                
 
257
        return res
 
258
                
 
259
        
 
260
    def _search_function(self, cr, uid, obj, name, args, context={}):
 
261
        '''
 
262
        Return all fields which are a function field
 
263
        '''
 
264
        if not args:
 
265
            return []
 
266
        
 
267
        for a in args:
 
268
            if a[0] == 'is_function':
 
269
                field_ids = []
 
270
                all_fields_ids = []
 
271
                model_ids = context.get('model_ids', [(6,0,[])])[0][2]
 
272
                
 
273
                if not model_ids:
 
274
                    model_ids = self.pool.get('ir.model').search(cr, uid, [], context=context)
 
275
                    
 
276
                for obj in self.pool.get('ir.model').browse(cr, uid, model_ids, context=context):
 
277
                    for field in obj.field_id:
 
278
                        all_fields_ids.append(field.id)
 
279
                        if self.pool.get(obj.model)._columns[field.name]._properties:
 
280
                            field_ids.append(field.id)
 
281
                
 
282
                if (a[1] == '=' and a[2] == False) or (a[1] == '!=' and a[2] == True):
 
283
                    return [('id', 'not in', field_ids)]
 
284
                else:
 
285
                    return [('id', 'in', field_ids)]
 
286
            
 
287
        
 
288
        return []
 
289
        
 
290
    
243
291
    _columns = {
244
292
        'model_search_id': fields.function(_get_model_search,
245
293
                                           fnct_search=_search_model_search,
246
294
                                           method=True,
247
295
                                           type='many2one', relation='ir.model',
248
296
                                           string='Model'),
 
297
        'is_function': fields.function(_is_function, 
 
298
                                       fnct_search=_search_function, 
 
299
                                       method=True,
 
300
                                       type='boolean', string='Is function ?'),
249
301
    }
250
302
    
 
303
    def fields_view_get(self, cr, uid, view_id=None, view_type='form', context={}, toolbar=False, submenu=False):
 
304
        '''
 
305
        Call the view on context if there is.
 
306
        '''
 
307
        if view_type == 'tree' and context and 'special_tree_id' in context:
 
308
            view_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'object_query', context.get('special_tree_id'))[1]
 
309
        if view_type == 'search' and context and 'special_search_id' in context:
 
310
            view_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'object_query', context.get('special_search_id'))[1]
 
311
            
 
312
        return super(ir_fields, self).fields_view_get(cr, uid, 
 
313
                                                      view_id=view_id,
 
314
                                                      view_type=view_type,
 
315
                                                      context=context,
 
316
                                                      toolbar=toolbar,
 
317
                                                      submenu=submenu)
 
318
        
 
319
    
251
320
ir_fields()
252
321
 
253
322
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
 
 
b'\\ No newline at end of file'