Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to delete the supplier info from a tree list of products?V8

By
michel Guénard
on 2/22/16, 10:27 AM 334 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)
2

Jusab Sida (jsi)

--Jusab Sida (jsi)--
Tiny ERP Pvt Ltd
http://www.odoo.com
874
| 2 1 5
Gandhinagar, India
--Jusab Sida (jsi)--


Jusab Sida (jsi)
On 2/22/16, 12:37 PM

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)

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

AD LIBITOM, michel Guénard
on 2/22/16, 1:04 PM

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

Jusab Sida (jsi)
on 2/23/16, 12:10 AM

Have you pass active_ids in context?

Jusab Sida (jsi)
on 2/23/16, 12:14 AM

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

AD LIBITOM, michel Guénard
on 2/23/16, 3:38 AM

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

Jusab Sida (jsi)
on 2/23/16, 4:02 AM
0

Pawan

--Pawan--
1267
| 4 3 5
Hyderabad, India
--Pawan--


Pawan
On 2/23/16, 1:10 AM

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!

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.

AD LIBITOM, michel Guénard
on 2/23/16, 3:32 AM

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

Pawan
on 2/23/16, 8:24 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 2/22/16, 10:27 AM
Seen: 334 times
Last updated: 2/23/16, 3:41 AM