insert into one To many and many To one fields

拥有回忆 提交于 2020-01-15 10:34:29

问题


I am using android odoo-mobile framework and this is how i am inserting a record online with the help of createRecord() now I want to insert record in manyTomany and oneTomany field in odoo database.I dont know how to insert it online.please help me. Thanks!

this is how i am inserting/creating a new record online.

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);
}

回答1:


relation fields accept list of commands:

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

to insert list of ids in a many2many

   [(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

For more understanding:

insert into many2many odoo




回答2:


This is the code that is worked for me.

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);


来源:https://stackoverflow.com/questions/47414114/insert-into-one-to-many-and-many-to-one-fields

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!