Se rendre au contenu
Menu
Cette question a été signalée
2 Réponses
4033 Vues

what I am trying to do is I have three product type (free, restricted and other) that can be sold for certain customers only. So, what I have done is I created product_tag objects which contains product type

class product_tag(osv.osv):

_name="product.tag"

_columns = {

'name': fields.char('Name', size=64, required=True),

'code':fields.integer('Code'),

 product_tag()

and i created many2one relation with product 

'prod_tag':fields.many2one('product.tag', 'Item Tags'),
and  many2many relation with res.partner with inheritance 

class res_partner(osv.osv):

_name='res.partner'

_inherit ='res.partner'

_columns = {

'cutomer_tag':fields.many2many('product.tag', 'rel_itemallowed_tag','item_category','tag_id','Allowed Item Tags'),

}

res_partner()

 this many2many relation helps to update customer's level either to buy one type or multiple product type, so what i want is how can i filter products in sales order by analyzing product tag and customer tag (by filtering product type by customer tag)?

Like if a customer tag is 'free' and  'other' all products those are free and othe type only to be visible in  many2one product filed of sale order form 

Avatar
Ignorer
Meilleure réponse

Hi,


override search function in class product.product :

verify in my code :

self.pool.get('res.partner').browse(cr, uid, context['partner_id'], context=context).cutomer_tag

will return a list of id, else modify my code to get a list of id.


my code (I use search function used in opernerp v8):

def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False):

     context = context or {}

     if context.get('partner_id'):

     # add to domain (variable args in body function),  prod_tag = False and customer tags

         prod_tag_ids = [False] + self.pool.get('res.partner').browse(cr, uid, context['partner_id'], context=context).cutomer_tag or []

         args.append((('prod_tag', 'in', prod_tag_ids)))

     return super(product_product, self).search(cr, uid, args, offset=offset, limit=limit, order=order, context=context, count=count)


Bye

Avatar
Ignorer
Auteur Meilleure réponse

@Cyril Gaspard, Thank you and I am using v7. I managed to override it but I am getting this error "Iteration is not allowed on browse_record(product.tag, 1)" .

Avatar
Ignorer
Publications associées Réponses Vues Activité
2
juin 22
7378
1
nov. 22
102
0
juil. 25
749
1
mai 25
1500
1
mai 25
1652