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
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project management
- MRP
This question has been flagged
1
Reply
2357
Views
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)
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign up