← Back to team overview

openerp-dev-web team mailing list archive

lp:~openerp-dev/openobject-addons/trunk-automated_rules-domain_filter-uco into lp:~openerp-dev/openobject-addons/trunk-automated_rules

 

Ujjvala Collins (OpenERP) has proposed merging lp:~openerp-dev/openobject-addons/trunk-automated_rules-domain_filter-uco into lp:~openerp-dev/openobject-addons/trunk-automated_rules.

Requested reviews:
  Bhumika (OpenERP) (sbh-openerp)

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-automated_rules-domain_filter-uco/+merge/51271

base_action_rule:
-----------------
* [REF] Code optimization.
* [IMP] Override search method of ir.filters to search filters for current object on rule.
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-automated_rules-domain_filter-uco/+merge/51271
Your team OpenERP R&D Team is subscribed to branch lp:~openerp-dev/openobject-addons/trunk-automated_rules.
=== modified file 'base_action_rule/base_action_rule.py'
--- base_action_rule/base_action_rule.py	2011-02-25 09:27:12 +0000
+++ base_action_rule/base_action_rule.py	2011-02-25 10:08:26 +0000
@@ -30,6 +30,23 @@
     """Method to covert string to datetime object"""
     return datetime.strptime(date_field[:19], '%Y-%m-%d %H:%M:%S')
 
+class ir_filters(osv.osv):
+    _inherit = "ir.filters"
+    
+    def search(self, cr, user, args, offset=0, limit=None, order=None, context=None, count=False):
+        ids = super(ir_filters, self).search(cr, user, args, offset=offset, limit=limit, order=order, context=context, count=count)
+        if context == None:
+            context = {}
+        action_obj = self.pool.get('base.action.rule')
+        if context.get('record_id'):
+            record_id = context.get('record_id')
+            model = action_obj.browse(cr, user, record_id, context=context).model_id.name
+            filter_ids = map(lambda x: x.id, [filter for filter in self.browse(cr, user, ids, context=context) if filter.model_id == model])
+            return filter_ids
+        return ids
+    
+ir_filters()
+
 class action_rule_state(osv.osv):
     """
     Object to store the sates of the object to firing action on state filed 
@@ -120,8 +137,7 @@
                 if state_field:
                     selection = state_field.get('state', {}).get('selection',[])
                     for select in selection:
-                        vals={}
-                        vals.update({'name':select[1], 'key':select[0], 'model_id':current_model.id})
+                        vals = {'name':select[1], 'key':select[0], 'model_id':current_model.id}
                         search_domain = [('name','=',select[1]), ('key','=',select[0]), ('model_id','=',current_model.id)]
                         state_exists = action_state_pool.search(cr, uid, search_domain, context=context)
                         if not state_exists:

=== modified file 'base_action_rule/base_action_rule_view.xml'
--- base_action_rule/base_action_rule_view.xml	2011-02-25 09:53:35 +0000
+++ base_action_rule/base_action_rule_view.xml	2011-02-25 10:08:26 +0000
@@ -57,7 +57,7 @@
                                 <group col="2" colspan="2" >
                                     <separator colspan="4" string="Filters"/>
                                     <group col="4" colspan="4">
-                                        <field name="filter_id" colspan="2"/>
+                                        <field name="filter_id" colspan="2" context="{'record_id': active_id}"/>
                                         <button name="btn_create_filter" type="object" string="Create _Filter" 
                                                 icon="terp-document-new" help="To create filter go to on search viewmake your filter and save it, that lead to the search (and list) view of the object."/>
                                     </group>