This question has been flagged
2973 Views

Hallo, I am querying an Odoo9 via XML-RPC in PHP, to fetch a model and an o2m related model.

In the result, I get only the id of the related records.

Is there any way to retrieve some other fields (eg. name), in a single operation?

These are the models I am using:

class product_price_category(models.Model):
    _name="product.price.variant"
    name=fields.Char()
class product_price(models.Model):
    _name="product.price"
    name=fields.Many2one("product.price.variant")
    price=fields.Float(digits_compute=dp.get_precision('Product Price'))
    product_id=fields.Many2one("product.product")
class product(models.Model):
    _inherit="product.product"
    price_variant_ids=fields.One2many("product.price", inverse_name="product_id")

Here, each product has one or more "price variants" (I am not following the standard Odoo variant pricing system), eg.: "Small"=4€, "Large"=8.50 €...

actual result while querying product.product:

Array
(
[1] => Array
(
[name] => ProdTest2
[price_variant_ids] => Array
(
[0] => 2
[1] => 3
)
[categ_id] => Array
(
[0] => 6
[1] => Categ6
)
)
)

In this case, the fetched product has 2 variants.

I would like to obtain a more complete array like this, containing more data about the variants:

Array
(
  [1] => Array
(
[name] => ProdTest2
[price_variant_ids] => Array
(
[0] => Array
                        (
                            [id] => 2
                            [name] => Small
                            [price] => 4.00
                        )
[1] => Array
                        (
                            [id] => 3
                            [name] => Large
                            [price] => 8.50
                        )
)
[categ_id] => Array
(
[0] => 6
[1] => Categ6
)
)
)
Avatar
Discard

hi, can you paste some code ?