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.

1

Add Supplier to Products via Script

By
Michael Aigner
on 9/29/15, 8:17 AM 503 views

What is the best way to add suppliers to all of my products? I have an Excel list with all of my products and skus, which are also already in Odoo, but the link in between is missing. What is the best way to link suppliers with products programmatically?

let me confirm, do you want to add a unique supplier to all your products or you have a list suppliers with their products ?

Baiju
on 9/30/15, 1:01 AM
0
Michael Aigner
On 10/1/15, 3:51 AM

OK guys, here is my solution in PHP:


function _createSupplierRelation($data){

$url = "xxx";

$db = "xxx";

$username = "xxx";

$password = "xxx";

$sku = $data[0];

$supplier_relation = $data[1];

$product_code = $data[2];

//connect

$common = ripcord::client("$url/xmlrpc/2/common");

$uid = $common->authenticate($db, $username, $password, array());

$models = ripcord::client("$url/xmlrpc/2/object");

//get odoo product id

$product = $models->execute_kw($db, $uid, $password,

'product.product', 'search_read',

array(array(array('default_code', '=', $sku)))

)[0];

//create supplier relation

$models->execute_kw($db, $uid, $password,

'product.supplierinfo', 'create',

array(array('name' => $supplier_relation, 'min_qty' => 0, 'delay' => 10, 'product_tmpl_id' => $product['id'], 'product_code' => $product_code))

);

}

0

Pawan

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


Pawan
On 9/30/15, 4:23 AM

Michael Aigner,

Its better if you write a script to read your excel file(that must have product_name, supplier_name, and qty_supplied) and

create a record for each supplier for respective product(for object "product.supplier_info") and tag these records to the corresponding  product.

As there is a one2many for product.supplier_info in product.product, you can simply refer record to it.

Hope it help

Hi Pawan, that's exactly what I'm looking for! You don't have such a script by any chance? Thanks!

Michael Aigner
on 9/30/15, 6:43 AM

No micheal, i don't have any......

Pawan
on 10/1/15, 1:33 AM
0

zbik

--zbik--
5941
| 6 4 7
Lodz, Poland
--zbik--


zbik
On 9/29/15, 8:32 AM

Step 1. Define suppliers and read their IDS

Step 2. Export + Reimport products CSV with added suppliers IDS
 

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: 9/29/15, 8:17 AM
Seen: 503 times
Last updated: 10/1/15, 3:52 AM