跳至内容
菜单
此问题已终结
3 回复
1996 查看

Hello,

I'm trying to add a new LogNote to my Order Delivery via JSON-RPC but I can't seem to get it. Can anyone show me how to do it?

The following is the raw request made by the platform which I'm using as reference:

{"id":12,
"jsonrpc":"2.0",
"method":"call",
"params":{
	​"context":{
		​"mail_post_autofollow":false,
		​"temporary_id":523.01},
		​"post_data":{
			​"body":"Test",
			​"attachment_ids":[],
			​"attachment_tokens":[],
			​"message_type":"comment",
			​"partner_ids":[],
			​"subtype_xmlid":"mail.mt_note",
			​"partner_emails":[]},
	​"thread_id":32,
	​"thread_model":"stock.picking"}
}


Best regards,
形象
丢弃
最佳答案

Hi,
Refer the code to add lognotes in stock.picking

notes = '%s' % '' + str(request.jsonrequest['inventoryMode']) + " - " + str(
request.jsonrequest['inventoryState']) + '' + '
'
+ ' Market: ' + str(
request.jsonrequest['location']) + '
'
+ ' Device date time: ' + str(
request.jsonrequest['deviceDateTime']) + '
'
+ str(request.jsonrequest['description'])

log_note = request.env['mail.message'].sudo().create({
'res_id': market.id,
'body': notes,
'model': 'stock.picking',
'email_from': request.jsonrequest['email'],
'attachment_ids': data,
})


Hope it helps you

形象
丢弃
最佳答案

you can use the message_post method of the stock.picking model. Here's an example of how you can construct the JSON-RPC request:
{

"id": 12,

"jsonrpc": "2.0",

"method": "call",

"params": {

"model": "stock.picking",

"method": "message_post",

"args": [

32, // thread_id

"Test", // body (your log note content)

false, // subtype_xmlid (mail.mt_note) - You can set to false to use the default value

false, // parent_id (you can set it to false)

false, // attachment_ids (you can set it to false or an empty list [])

false, // partner_ids (you can set it to false or an empty list [])

false, // attachment_tokens (you can set it to false or an empty list [])

false // partner_emails (you can set it to false or an empty list [])

],

"kwargs": {

"context": {

"mail_post_autofollow": false,

"temporary_id": "523.01"

}

}

}

}


Explanation of parameters:

  • model: The model name ("stock.picking" in this case).
  • method: The method name ("message_post" to add a new LogNote).
  • args: A list of arguments for the method. Here, you pass the thread_id of the Order Delivery, the log note content ("Test" in this case), and other optional parameters (you can set them to false or an empty list []).
  • kwargs: Additional keyword arguments. Here, you pass the context, which can include some context variables like mail_post_autofollow and temporary_id.

You can make this JSON-RPC request to the Odoo server using your preferred HTTP client library, such as requests in Python or axios in JavaScript. Make sure to replace 32 in the args with the actual thread_id of your Order Delivery. After sending the request, a new LogNote with the specified content will be added to the Order Delivery.

形象
丢弃
最佳答案

Try to call message_post of the stock.picking​ model with the values of the post_data that shows on the example request you have

形象
丢弃
相关帖文 回复 查看 活动
1
1月 23
2658
3
2月 23
4454
3
11月 24
2157
1
2月 24
1139
2
5月 23
2327