本文介绍了如何通过默认API覆盖odoo中的一对多记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

这是我的创建json,我想在此json中进行哪些更改以覆盖(替换)现有内容? lead_product_ids .,现在它正在追加记录.现在,当更新此代码中的记录而不是0,0时,我得到多个值是多少,请帮忙.

This is my create json, what change I want to make in this json to overwrite(Replace) the existing? lead_product_ids., now it is appending the records. Now i am getting multiple when update the records in this code instead of 0,0 what is the value,Please help.

{
  "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()的文档字符串中找到:

The answer is found in the docstring of the 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字段的不存在记录没有任何意义.

It's (1, id, {'field_1': value_1,'field_2': value_2,}). But you should use write instead of create because in create it doesn't make any sense to change non-existing records of a x2many field.

这篇关于如何通过默认API覆盖odoo中的一对多记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 14:16