Skip to Content
Menú
This question has been flagged
1 Respondre
3393 Vistes

Hello,


Im working on some processes that allow an external application author products and their related boms.

I have manufacturing, inventry and variants on as options, in case that makes a difference.


I already have my head around doing CRUD operations via the jsonrpc, i have spent a bunch of time tracing fields to models and this is what i think needs to occur.


product.template ( product.product ) > mrp.bom > a mrp.bom.line per component. 

Do i need to go back to each parent to update it with information, or as long as i add the correct parent id to its respected field the back end will do any additonal links required?


Does using the odoorpc simplify this ?


Appreciate any help anyone can provide here.

Cheers
kym


Avatar
Descartar
Best Answer

To create a bill of materials (BOM) using JSON-RPC in Odoo, you will need to follow a similar sequence of steps as outlined above. Here is a more detailed description of the process:


Connect to the JSON-RPC server: You will need to use the jsonrpc module to establish a connection to the JSON-RPC server. You can do this by calling the jsonrpc.ServerProxy function and passing it the URL of the server, as well as any authentication information that is required.


Send an RPC request to create the BOM: Once you have established a connection to the server, you can use the execute_kw method to send an RPC request to create the BOM. This method takes three arguments: the database name, the user id, and the password. You will also need to pass a fourth argument that is a dictionary containing the details of the BOM that you want to create, such as the name and the items that should be included.


Receive an RPC response: The server will respond to your request with an RPC response, which will include the ID of the newly created BOM.


Verify the results: After you have received the RPC response, you can use the read method to retrieve the details of the newly created BOM and verify that it was created as expected.


Close the connection: Once you have finished interacting with the JSON-RPC server, you should close the connection by calling the close method.


Here is an example of how you might create a BOM using JSON-RPC in Odoo:


Copy code

import jsonrpc


# Connect to the JSON-RPC server

server = jsonrpc.ServerProxy('http://localhost:8069/jsonrpc')


# Authenticate and create the BOM

uid = 1

password = 'admin'

database = 'mydatabase'

product_tmpl_id = 5

bom_id = server.execute_kw(database, uid, password, 'mrp.bom', 'create', [{

    'product_tmpl_id': product_tmpl_id,

    'product_qty': 1,

    'type': 'phantom',

    'bom_line_ids': [

        (0, 0, {'product_id': 2, 'product_qty': 1}),

        (0, 0, {'product_id': 3, 'product_qty': 2}),

    ],

}])


# Verify the results

bom = server.execute_kw(database, uid, password, 'mrp.bom', 'read', [bom_id])

print(bom)


# Close the connection

server.close()

Avatar
Descartar
Autor

Ah fantastic,
That is good to know that i can create the bom lines in the 'mrp.bom' directly, saves a bit of hassle.

thanks for your help.

Related Posts Respostes Vistes Activitat
3
de jul. 23
3083
3
de febr. 23
5365
3
de nov. 24
2889
1
de febr. 24
1748
2
de maig 23
3221