如何通过默认 API 覆盖 odoo 中的一对多记录

how to overwrite a one to many records in odoo through default API

如何通过odoo覆盖odoo中的一对多记录API?

这是我创建的 json,我想在这个 json 中做些什么来覆盖(替换)现有的? lead_product_ids.,现在正在追加记录。现在我在这段代码中更新记录时得到多个而不是 0,0 值是多少, 请帮忙

{
  "jsonrpc": "2.0",
  "params": {
    "model": "crm.lead",
    "method": "create",
    "args": [
      {
        "type": "opportunity",
        "name": "Fgtrdhjkkmmmmmmmm1290",
        "pro_info": "Fggggggg hhhhhh jkkkkkkknjj hjkll",
        "tag_ids": [

           6,
              0,
              [
                43,42
              ]
        ],
        "purposes_id": 3,
        "lead_product_ids": [
          ***0,
          0,***
          {
            "product_uom": 21,
            "product_id": 148,
            "description": "",
            "qty": 1,
            "price_unit": 2448,
            "expected_price": 2448,
            "discount": 0,
            "tax_id": [
              6,
              0,
              [
                22
              ]
            ],
            "price_subtotal": 2741.760009765625
          }
        ],
        "partner_id": 1592,
        "religion": 2,
        "age_bucket": "40_45",
        "phone": "5695324877",
        "mobile": "5695324878",
        "locations_id": 157,
        "district_id": 157,
        "state_id": 593
      }
    ]
  }
}

答案在 Model.write() 的文档字符串中找到:

    """
      ...
      This format is a list of triplets executed sequentially, where each
      triplet is a command to execute on the set of records. Not all
      commands apply in all situations. Possible commands are:

      ``(0, _, values)``
          adds a new record created from the provided ``value`` dict.
      ``(1, id, values)``
          updates an existing record of id ``id`` with the values in
          ``values``. Can not be used in :meth:`~.create`.
      ``(2, id, _)``
          removes the record of id ``id`` from the set, then deletes it
          (from the database). Can not be used in :meth:`~.create`.
      ``(3, id, _)``
          removes the record of id ``id`` from the set, but does not
          delete it. Can not be used on
          :class:`~odoo.fields.One2many`. Can not be used in
          :meth:`~.create`.
      ``(4, id, _)``
          adds an existing record of id ``id`` to the set. Can not be
          used on :class:`~odoo.fields.One2many`.
      ``(5, _, _)``
          removes all records from the set, equivalent to using the
          command ``3`` on every record explicitly. Can not be used on
          :class:`~odoo.fields.One2many`. Can not be used in
          :meth:`~.create`.
      ``(6, _, ids)``
          replaces all existing records in the set by the ``ids`` list,
          equivalent to using the command ``5`` followed by a command
          ``4`` for each ``id`` in ``ids``.

      .. note:: Values marked as ``_`` in the list above are ignored and
                can be anything, generally ``0`` or ``False``.
    """

(1, id, {'field_1': value_1,'field_2': value_2,})。但是您应该使用 write 而不是 create 因为在 create 中更改 x2many 字段的不存在记录没有任何意义。