Hello!
I need to integrate Odoo with an online store (not Odoo)
In online store products have multiple prices for different groups of buyers.
It was decided to create in Odoo a few pricelist for these groups of buyers.
To make it work in Odoo, you need to each product to add information about the price list and the price.
This can be done in manual mode through the edit form of the product in Odoo on the Sales tab, it works.
But it should be done programmatically on the side of the Internet-shop using XML-RPC.
I have defined the following algorithm for generating the necessary records for the product:
Initial data:
- known product id = 196
- known id of the pricelist which I need to attach, id = 1
- to the product manually attached 1 price list (for example), id = 4
- XML-RPC client - ripcord ($models = ripcord::client("$url/xmlrpc/2/object");)
- PHP
Process:
1. Get current product data:
$productData = $models->execute_kw(
$db,
$uid,
$password,
'product.template', 'read',
[
[
196
]
],
[
'fields'=>[
'name',
'list_price',
'weight',
'item_ids', // this field contains information about the attached price lists
]
]
);
print_r($productData);
========================== OUT
Array
(
[0] => Array
(
[item_ids] => Array
(
[0] => 6 //We see that now the product contains information about the price list(id=4) I added manually. the record id in the price list = 6
)
[list_price] => 1200
[id] => 196
[weight] => 3
[name] => t-short
)
)
=========================
it's ok
2. Create new record in the price list
$priceListItemId = $models->execute_kw(
$db,
$uid,
$password,
'product.pricelist.item',
'create',
[
[
'name'=>$productData[0]["name"],
'pricelist_id'=>1,
'fixed_price'=>900,
'product_id'=>$productData[0]["id"],
//'applied_on'=>'1_product',
]
]
);
var_dump($priceListItemId);
======================== OUT
int(57)
========================
This is id for the new pricelist item
3. Check the generated pricelist item
$pricelistItemData = $models->execute_kw(
$db,
$uid,
$password,
'product.pricelist.item', 'read',
[
[
$priceListItemId
]
],
[
]
);
print_r($pricelistItemData);
======================== OUT
Array
(
[0] => Array
(
[fixed_price] => 900
[create_date] => 2017-10-03 09:15:45
[price_discount] => 0
[sequence] => 5
[price_max_margin] => 0
[date_end] =>
[write_uid] => Array
(
[0] => 1
[1] => Administrator
)
[currency_id] => Array
(
[0] => 3
[1] => USD
)
[applied_on] => 3_global
[min_quantity] => 1
[id] => 57
[create_uid] => Array
(
[0] => 1
[1] => Administrator
)
[percent_price] => 0
[__last_update] => 2017-10-03 09:15:45
[date_start] =>
[company_id] =>
[name] => t-short
[product_tmpl_id] =>
[pricelist_id] => Array
(
[0] => 1
[1] => Public Pricelist (USD)
)
[price_min_margin] => 0
[price] => 900.0 USD
[compute_price] => fixed
[base] => list_price
[write_date] => 2017-10-03 09:15:45
[display_name] => t-short
[categ_id] =>
[price_surcharge] => 0
[price_round] => 0
[product_id] => Array
(
[0] => 196
[1] => [03-00620] t-short
)
[base_pricelist_id] =>
)
)
=================================
Looks good and it can be expected that when i request product data 196, data for the price list will already be attached. Try...
4. Check the product data
$productData = $models->execute_kw(
$db,
$uid,
$password,
'product.template', 'read',
[
[
196
]
],
[
'fields'=>[
'name',
'list_price',
'weight',
'item_ids', // this field contains information about the attached price lists
]
]
);
print_r($productData);
========================== OUT
Array
(
[0] => Array
(
[item_ids] => Array
(
[0] => 6 //It is seen that there is nothing new. I would like to see here [0]=>6 [1]=>57 , but the miracle did not happen
)
[list_price] => 1200
[id] => 196
[weight] => 3
[name] => t-short
)
)
=========================
It is obvious that the data on the price list is still not attached to the object product.
But I can try to do it explicitly. Try...
5. Add the id of the pricelist item in the product object
$result =$models->execute_kw( //
$db,
$uid,
$password,
'product.template',
'write',
[
[
196
],
[
'item_ids'=> [
'item_ids'=>[6,57]
'item_ids'=>57 // was tried - the result is the same (true)
]
]
]
);
var_dump($result);
======================= OUT
bool(true)
=======================
Great! True - I think it worked. But whether this is so. Check..
6. Check the product data
$productData = $models->execute_kw(
$db,
$uid,
$password,
'product.template', 'read',
[
[
196
]
],
[
'fields'=>[
'name',
'list_price',
'weight',
'item_ids', // this field contains information about the attached price lists
]
]
);
print_r($productData);
========================== OUT
Array
(
[0] => Array
(
[item_ids] => Array
(
[0] => 6 //No change
)
[list_price] => 1200
[id] => 196
[weight] => 3
[name] => t-short
)
)
=========================
It is obvious that the data on the price list is still not attached to the object of the product.
THE END
QUESTION: How to attach pricelist item to the product?
Thanks for any response