Hello,
I have some problems to make a filter on research product by product categories.
So firstly I have created a new class on my python folder "product_product.py".
class product_product_category(osv.osv):
_inherit = 'product.category'
# Retourne tous les ids enfant d'une catégorie
def _compute_child(self, category):
ids = [category.id]
for child in category.child_ids:
ids.extend(self._compute_child(child))
return ids
# Retourne les ids de tous les enregistrements de product.product.category dont le champ complete_name doit être recalculé
def _get_child_ids(self, cr, uid, ids, context=None):
return_ids = []
for category in self.browse(cr, uid, ids, context=context):
return_ids.extend(self._compute_child(category))
return return_ids
# Ici on redéfini la fonction du champ complete_name
def _name_get_fnc2(self, cr, uid, ids, prop, unknow_none, context=None):
product = self._name_get_fnc(cr, uid, ids, prop, unknow_none, context=context)
return product
_order = 'complete_name asc'
_columns = {
# Size = 1002 pour permettre 15 niveaux (15*64 + 14*3)
'complete_name': fields.function(_name_get_fnc2, type="char", string='Full Name', size=1002,
store = {
'product.product.category':(_get_child_ids,None,20),
}),
}
secoundly i have created two records on my xml folder "product_view.xml"
<record model="ir.ui.view" id="product_search_form_view">
<field name="name">product.product.search.form</field>
<field name="model">product.product</field>
<field name="arch" type="xml">
<search string="Recherche catégorie">
<field name="name" />
<filter name="mothercateg" string="Categories mères" context="{'group_by': 'parent_id'}"/>
<filter name="filtre_categ_010" string="010 test" domain="[('complete_name', 'like','010 test')]" />
<filter name="filtre_categ_011" string="011 test" domain="[('complete_name', 'like','011 test')]" />
<filter name="filtre_categ_020" string="020 test" domain="[('complete_name', 'like','020 test')]" />
<filter name="filtre_categ_030" string="030 test" domain="[('complete_name', 'like','030 test')]" />
<filter name="filtre_categ_040" string="040 test" domain="[('complete_name', 'like','040 test')]" />
<filter name="filtre_categ_050" string="050 test" domain="[('complete_name', 'like','050 test')]" />
<filter name="filtre_categ_070" string="070 test" domain="[('complete_name', 'like','070 test')]" />
<filter name="filtre_categ_075" string="075 test" domain="[('complete_name', 'like','075 test')]" />
<filter name="filtre_categ_080" string="080 test" domain="[('complete_name', 'like','080 test')]" />
<filter name="filtre_categ_090" string="090 test" domain="[('complete_name', 'like','090 test')]" />
<filter name="filtre_categ_100" string="100 test" domain="[('complete_name', 'like','100 test')]" />
<filter name="filtre_categ_120" string="120 test" domain="[('complete_name', 'like','120 test')]" />
</search>
</field>
</record>
<record model="ir.ui.view" id="product_product_tree_view">
<field name="name">product.product.tree</field>
<field name="model">product.product</field>
<field name="inherit_id" ref="product.product_product_tree_view"/>
<field name="type">tree</field>
<field name="arch" type="xml" >
<field name="name" position="replace">
<field name="name"/>
</field>
</field>
</record>
Then I have upload and instal my new module "product_product", despite of that, when i try to make a research with my product there aren't my new filters :/.
Does anybody know the answer please?
Can we maybe replace "product.search.form" by "product.category.search"? If it's possible how can i do that?