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

(Odoo 17)

I have the sale.order​ id of an existing order. I want to append some items to it using the external web services API.

I can't seem to get the payload correct.

This is as close as I've gotten.

payload = [
    {
        'order_id': 1071,
        'product_id': 44623,
        'name': 'TEST LINE: Product Description',
        'product_uom': 1,
        'product_uom_qty': 1.0
     }
]
so_lines = models.execute_kw(db, uid, password,
                             'sale.order.line', 'create',
                             payload
                             )

When I run this, I get this error message.

xmlrpc.client.Fault: Fault 2: 'Record does not exist or has been deleted.\n(Record: product.product(44623,), User: 377)'

I know for certain that the product matching that ID exists because I just searched for it.

payload = [
  [
    [
      "id",
      "=",
      "44623"
    ]
  ]
]
product = models.execute_kw(db, uid, password,
                            'product.template', 'search',
                            payload)

And I get results the same ID back.

Can someone tell me what I'm lacking? Can I create sale.order.line​ items with create​ or do I have to use update​ for a sale.order​?

形象
丢弃
编写者

@Cybrosys, Thanks for the answer. (I'm unable to comment on your answer.) I updated my question with the actual error code (with bad chars stripped). When I try your code verbatim, I get the same result.

编写者

Does something need to be true about a product before I can add it as a line item on a sale order?

编写者

If I add the product in the web app, when I retrieve the `sale.order.line` data, the `product_id` doesn't match what I retrieved from `product.template`. Is there a different model that sale.order.line items link to?

最佳答案

Hi,

You can create the values like

payload = {
    'order_id': 1071,
    'product_id': 44623,
    'name': 'TEST LINE: Product Description',
    'product_uom': 1,
    'product_uom_qty': 1.0
}

so_line_id = models.execute_kw(db, uid, password,
                               'sale.order.line', 'create',
                               [payload]
                               )

the payload is a dictionary, not a list of dictionaries.If you need to update an existing sale order instead of creating a new one, you can use the write method instead of create.
so_line_id = models.execute_kw(db, uid, password,
                               'sale.order.line', 'write',
                               [[sale_order_line_id], payload]
                               )


Hope it helps

形象
丢弃
相关帖文 回复 查看 活动
2
12月 24
20979
0
9月 24
953
3
8月 24
1973
0
2月 24
1291
0
2月 24
917