I work on account_analytic_default
module on OEv7.0. And I try to add a new field that valid the rule if the product category match or if this is a child of the rule category.
I have a form with a product_category field. It's a many2one field to product.category objects. this is the function that get the better rule for this invoice line.
domain = []
if product_id:
domain += ['|', ('product_id', '=', product_id)]
domain += [('product_id','=', False)]
if partner_id:
domain += ['|', ('partner_id', '=', partner_id)]
domain += [('partner_id', '=', False)]
if user_id:
domain += ['|',('user_id', '=', user_id)]
domain += [('user_id','=', False)]
if date:
domain += ['|', ('date_start', '<=', date), ('date_start', '=', False)]
domain += ['|', ('date_stop', '>=', date), ('date_stop', '=', False)]
best_index = -1
res = False
for rec in self.browse(cr, uid, self.search(cr, uid, domain, context=context), context=context):
index = 0
if rec.product_id: index += 1
if rec.partner_id: index += 1
if rec.user_id: index += 1
if rec.date_start: index += 1
if rec.date_stop: index += 1
if index > best_index:
res = rec
best_index = index
return res
I think about a piece of code like that:
if product_categ_id:
domain += ['|', ('product_categ_id', 'parent_of', product_categ_id)]
domain += [('product_categ_id','=', False)]
Or course I'll created a new field product_categ_id and the value of domain will be the product category.
But 'parent_of' doesn't exist and I don't know how to do something like this.
edit: I've seen something like domain=[('product.categ_id','in',[list of child of something])]