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

问题描述 投票:0回答:1

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

这是我的创建json,我想在这个json中做什么改变来覆盖(Replace)现有的? 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
      }
    ]
  }
}
many-to-many odoo one-to-many odoo-10 many-to-one
1个回答
1
投票

答案可以在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字段的不存在记录没有任何意义。

© www.soinside.com 2019 - 2024. All rights reserved.