【问题标题】:how to overwrite a one to many records in odoo through default API如何通过默认API覆盖odoo中的一对多记录
【发布时间】:2019-03-05 15:36:33
【问题描述】:

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

这是我创建的 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
      }
    ]
  }
}

【问题讨论】:

    标签: many-to-many odoo one-to-many odoo-10 many-to-one


    【解决方案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 字段的不存在记录没有任何意义。

    【讨论】:

      猜你喜欢
      • 2020-12-02
      • 1970-01-01
      • 2019-07-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-17
      相关资源
      最近更新 更多