插入一个To to many和many To one fields

时间:2017-11-21 13:20:01

标签: android odoo-10 odoo-mobile

我正在使用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);
}

2 个答案:

答案 0 :(得分: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

更多理解:

insert into many2many odoo

答案 1 :(得分: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);