This question has been flagged
1 Reply
8526 Views

Hey guys,

I try to creat a purchase order via XML-RPC.

This is my code:

gid=125 # Id of supplierp
id= 64 # ID of product
models.execute_kw(db, uid, passwrd, 'purchase.order', 'create',
     [{'partner_id': gid, 'state':'approves', 'location_id':12,    
        'order_line':[(0,False,{'product_id':pid,'product_qty':20.0, 'price_unit':2,0})]
       }])


The problem is, taht I get the following Error:

>>>

xmlrpclib.Fault: <Fault 2: 'The operation cannot be completed, probably due to the following:\n- deletion: you may be trying to delete a record while other records still reference it\n- creation/update: a mandatory field is not correctly set\n\n[object with reference: pricelist_id - pricelist.id]'>

<<<

In the purchase.py file is pricelist_id set as default.

 Does anyone know how to creat a purchase order sucessfull?

Avatar
Discard
Best Answer

Hi Fabian,

Following fields are compulsory to pass with XMLRPC.

models.execute_kw(db, uid, password, 'purchase.order', 'create',[{
'partner_id': 1,
'state':'approved',
'pricelist_id': 2, // this is pricelist id default get by the framework in UI not in XMLRPC.
'name': 'PO00100', // this also need to passed from python code.
'location_id':12,
'order_line':[(0,False,{
'name':'abcd', // this must be description of product.
'date_planned':str(datetime.datetime.now()), // Planned date need to pass.
'product_id':1,
'product_qty':20.0,
'price_unit':2.0
})]
}])


Regards,

Hardik

Avatar
Discard
Author

It's working fine! Thanks a lot.

Author

By any chance, do you now how to set the purchase as shipped? Maybe by using models.exec_workflow?

For that, I think you need to create Incoming shipment with same Procurement Group.

Author

Hey Hardik, if I create a Purchase with your code and click on "Receive Products" is there no linking. I have to create a whole new Transfere. Is there a way to commit the data from the purchase to the Receive Products template?

It is because of product id, The Product we select is "Service" Product. Change the Product with any other and it will appear in the Receive Product too.

On Mon, Feb 1, 2016 at 3:25 PM Fabian <go.public@mailbox.org> wrote:

Hey Hardik, if I create a Purchase with your code and click on "Receive Products" is there no linking. I have to create a whole new Transfere. Is there a way to commit the data from the purchase to the Receive Products template?

--
Fabian

Author

hmm.... really strange on my installation it seems, that odoo do not commit the product_id... I've creted the product 'ball' ( porduct_id:67) but when i create a purchase via api i don't get the Product 'ball' i get every time the 'test Product'. When i read the purchase order via 'purchase_order','read': i get the message: 'product_id': [67, 'test Product']. Futhermore there is no linking with 'receive Product'

May be we need skype meeting for this xmlrpc explanation. My skype id is hardikgiri.goswami