Reviewers: ,


Please review this at http://codereview.tryton.org/582002/

Affected files:
  M CHANGELOG
  M trytond/ir/model.py
  M trytond/ir/view/model_form.xml
  M trytond/ir/view/model_list.xml


Index: CHANGELOG
===================================================================

--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,5 @@
+* Add global search
+
 Version 2.6.0 - 2012-10-22
 * Bug fixes (see mercurial logs for details)
 * Add pre-validation

Index: trytond/ir/model.py
===================================================================

--- a/trytond/ir/model.py
+++ b/trytond/ir/model.py
@@ -39,6 +39,7 @@
         depends=['module'])
     module = fields.Char('Module',
        help="Module in which this model is defined", readonly=True)
+    global_search_p = fields.Boolean('Global Search')
     fields = fields.One2Many('ir.model.field', 'model', 'Fields',
        required=True)

@@ -58,6 +59,7 @@
         cls._order.insert(0, ('model', 'ASC'))
         cls.__rpc__.update({
                 'list_models': RPC(),
+                'global_search': RPC(),
                 })

     @classmethod
@@ -106,6 +108,31 @@
         # Restart the cache of models_get
         Property._models_get_cache.clear()

+    @classmethod
+    def global_search(cls, text):
+        """
+        Search on models for text
+        Returns a list of tuple (model, id, rec_name)
+        """
+        pool = Pool()
+        ModelAccess = pool.get('ir.model.access')
+
+        result = []
+        models = cls.search([('global_search_p', '=', True)])
+        access = ModelAccess.get_access([m.model for m in models])
+        for model in models:
+            if not access[model.model]['read']:
+                continue
+            Model = pool.get(model.model)
+            records = Model.search([
+                    # TODO improve matching
+                    ('rec_name', 'ilike', '%%%s%%' % text),
+                    ])
+            for record in records:
+                result.append((model.model, model.rec_name,
+                        record.id, record.rec_name))
+        return result
+

 class ModelField(ModelSQL, ModelView):
     "Model field"

Index: trytond/ir/view/model_form.xml
===================================================================

--- a/trytond/ir/view/model_form.xml
+++ b/trytond/ir/view/model_form.xml
@@ -8,6 +8,8 @@
     <field name="model"/>
     <label name="module"/>
     <field name="module"/>
+    <label name="global_search_p"/>
+    <field name="global_search_p"/>
     <separator name="info" colspan="6"/>
     <field name="info" colspan="6"/>
     <field name="fields" colspan="6" readonly="1"/>

Index: trytond/ir/view/model_list.xml
===================================================================

--- a/trytond/ir/view/model_list.xml
+++ b/trytond/ir/view/model_list.xml
@@ -5,5 +5,6 @@
     <field name="name"/>
     <field name="model"/>
     <field name="info"/>
+    <field name="global_search_p"/>
     <field name="module"/>
 </tree>



--
[email protected] mailing list

Reply via email to