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

web serviece and M2M field

By
Samer Al-Sarhan
on 2/14/16, 8:33 AM 347 views

Hello All, how can i read the value of many2many field with the webservices API,, I am trying to read the product vaient from the product.procduct

0

Jérémy Kersten (jke)

--Jérémy Kersten (jke)--
2983
| 3 2 5
Jodoigne, Belgium
--Jérémy Kersten (jke)--

Jérémy is a member of the core R&D team since september 2013. He developed several projects for OpenERP version 8 including the eCommerce, the Google Calendar synchronization and the new product variants/configurator. Now, he manages Odoo website and themes for saas.

Jérémy Kersten (jke)
On 2/14/16, 9:55 AM

Hello


Take a look on this example, it should help you.

Product.template -> product.product (one2many) -> product.attribute.value (many2many)


models = xmlrpclib.ServerProxy('{}/xmlrpc/2/object'.format(url))
prods = models.execute_kw(
db, uid, password,
'product.template', 'search_read',
[[['categ_id', '=', 6]]],
dict(fields=['name', 'product_variant_ids'], limit=7)
)
for prod in prods:
print "%(name)s [%(id)s] - %%d variants " % prod % len(prod.get('product_variant_ids'))
variants = models.execute_kw(
db, uid, password,
'product.product', 'read',
[prod.get('product_variant_ids')],
dict(fields=['name', 'lst_price', 'attribute_value_ids'])
)
for variant in variants:
print "\t %(name)s - %(lst_price)s" % variant
atts = models.execute_kw(
db, uid, password,
'product.attribute.value', 'read',
[variant.get('attribute_value_ids')],
dict(fields=['name', 'attribute_id', 'price_extra'])
)
for att in atts:
print "\t\t %%s: %(name)s (+ %(price_extra)s) " % att % att.get('attribute_id')[1]

Output from runbot 131156-9-0-ee42be.runbot9.odoo.com:


Apple In-Ear Headphones [10] - 1 variants
Apple In-Ear Headphones - 79.0
Apple Wireless Keyboard [12] - 1 variants
Apple Wireless Keyboard - 47.0
Bose Mini Bluetooth Speaker [7] - 1 variants
Bose Mini Bluetooth Speaker - 247.0
iMac [11] - 1 variants
iMac - 1799.0
iPod [14] - 2 variants
iPod - 16.5
Memory: 16 GB (+ 0.0)
iPod - 22.9
Memory: 32 GB (+ 0.0)
iPad Mini [9] - 1 variants
iPad Mini - 320.0
iPad Retina Display [6] - 3 variants
iPad Retina Display - 750.0
Memory: 16 GB (+ 0.0)
Color: White (+ 0.0)
Wi-Fi: 2.4 GHz (+ 0.0)
iPad Retina Display - 750.0
Memory: 16 GB (+ 0.0)
Color: Black (+ 0.0)
Wi-Fi: 2.4 GHz (+ 0.0)
iPad Retina Display - 800.4
Memory: 32 GB (+ 0.0)
Color: White (+ 0.0)
Wi-Fi: 2.4 GHz (+ 0.0)
30m RJ45 wire [55] - 1 variants
30m RJ45 wire - 250.0

thank you Dear.Jérémy Kersten you make very clear and easy (y)

Samer Al-Sarhan
on 2/14/16, 10:04 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/14/16, 8:33 AM
Seen: 347 times
Last updated: 2/14/16, 9:55 AM