Skip to Content
Menu
This question has been flagged
5 Replies
3629 Views

I need to create a server action in order to delete every supplier info that are linked to my products.

I tried the following code; which does not work(I am not a developper)

I understand that the link between product and supplier info is a one2many

I would appreciate any help because I have hundreds of products with obsolete or inaccurate supplier info due to mergers of various suppliers.

context = context or {}

for record in self.browse(cr, uid, context.get('active_ids', []), context=context):

    
value = ""

    for val in [product.supplierinfo]:

        if val:

            value += ""
pool.get('product.template').delete(cr, uid, record.id, {product.supplierinfo: value[:-1]}, context=context)
Avatar
Discard
Best Answer

You can use this code in your action....

if context and context['active_ids']:

    pid = self.pool('product.supplierinfo').search(cr, uid, [('product_tmpl_id','in',context['active_ids'])])

    self.pool('product.supplierinfo').unlink(cr, uid, pid)

Avatar
Discard
Author

Thks Jusab; however the result is ValueError: "name 'active_ids' is not defined" while evaluating Any idea to solve this error?

can you try again??? i have updated my answer

Have you pass active_ids in context?

Author

Hello Jusab Just works as expected; This server action removes the links to suppliers from the product form. (tested with 2 suppliers info) Many thanks

Enjoy!!!!!!!!! :)

Best Answer

Micheal,

for record in self.browse(cr, uid, context.get('active_ids', []), context=context):
 #self is product.template object & active_ids are the records selected from tree view...    
    supp_to_remove = []    
    for supp in record.supplierinfo:        
        supp_to_remove.append((3, supp.id))    
    record.write({'supplierinfo':supp_to_remove})

Hope this helps!

Avatar
Discard
Author

Thanks Pavan for the code; Igot the error: ValueError: "'product.template' object has no attribute 'supplierinfo'" while evaluating The server action I created is using the product template model.

you can use "record.seller_ids" inspite of 'record.supplierinfo',
and at end
record.write({'seller_ids':supp_to_remove})

Related Posts Replies Views Activity
4
Jul 16
2191
1
Jun 15
5291
1
Mar 15
9947
1
Mar 15
2532
0
Mar 15
3229