1

我正在使用 android odoo-mobile 框架,这就是我在网上插入记录的方式,createRecord()现在我想在 odoo 数据库的 manyTomany 和 oneTomany 字段中插入记录。我不知道如何在线插入。请帮助我。谢谢!

这就是我在线插入/创建新记录的方式。

protected OdooResult doInBackground(Void... voids)
 {
     ORecordValues values = new ORecordValues();
     values.put("partner_id", Integer.parseInt(resPartnerArrayList.get(idc).get_id()));
     String UTCDate = toUTCTime(binding.qOrderDate.getText().toString())
      values.put("date_order", UTCDate);
      if(!expDate.isEmpty())
      {
         values.put("validity_date",binding.qExpirationDate.getText().toString());
      }
      if(!paymentTerms.isEmpty())
      {
         values.put("payment_term_id", Integer.parseInt
                                (paymentTermArrayList.get(idP).get_id()));
      }               
      if(!binding.qUntaxedAmount.getText().toString().isEmpty())
      {
         values.put("amount_untaxed",binding.qUntaxedAmount.getText().toString());
      }
      if(!binding.qTotal.getText().toString().isEmpty())
      {
         values.put("amount_total", binding.qTotal.getText().toString());
      }
      if(!binding.qTaxes.getText().toString().isEmpty())
      {
         values.put("amount_tax", binding.qTaxes.getText().toString());
      }
  return odoo.createRecord("sale.order", values);
}
4

2 回答 2

2

关系字段接受命令列表:

    [(cammond_valeu, value, value), ........] 

在 many2many 中插入 id 列表

   [(6, 0, [id1, id2, id3])] # this remove old record and replace them by this new ids
   [(4,id,0), (4, id2, 0), ....] # this add the list of ids to m2m without removing the old record
   [(0, 0, {'field_name': value, 'field_name2': value}), ...] # this create an new record from the dictionary and add it to old record

更多了解:

插入many2many odoo

于 2017-11-22T21:11:52.737 回答
1

这是对我有用的代码。

ORecordValues orderlineValues = new ORecordValues();
List<Integer> tax_id = new ArrayList<>();
for (int j = 0; j < finalOrderlineData.get(i).getTaxes().size(); j++)
{
    tax_id.add(Integer.parseInt(finalOrderlineData.get(i).getTaxes().get(j)));
}
List<Object> m2mRecords = new ArrayList<>();
m2mRecords.add(6);
m2mRecords.add(false);
m2mRecords.add(tax_id);
List<Object> manyToManyRecord = new ArrayList<>();
manyToManyRecord.add(m2mRecords);
orderlineValues.put("tax_id", manyToManyRecord);
于 2017-11-23T09:39:38.380 回答