Odoo的新手,我正尝试用Java创建Web服务,尤其是将数据加载到Odoo中,尤其是加载到模型product.template和technical.sheet中,该模型是我创建的自定义模型。对于一种产品,可以有0或许多技术表,而对于一种技术表-一种产品。在模型technical.sheet中,我创建了一个字段x_product_id,类型为many2one,对象关系为product.tamplate。在product.template中,我创建了相同的字段x_product_id,但类型为one2many,对象关系为technical.sheet,字段关系为x_product_id(technical.sheet)。我已经成功加载了产品和技术说明书,但是当我尝试设置关系字段时,出现了错误。有没有人有一个例子或想法,如何使用Odoo外部API设置one2many,many2one和many2many类型的字段?谢谢!这是一段代码:
for(文章文章:articles.values()){
if(article.getTechSheets().size()>0){
technicalSheetsMap.put(article.getMfsIdentifier(), article.getTechSheets());
}
ArrayList<Integer> techSheetsIds = new ArrayList<>();
for(TechnicalSheet sh: article.getTechSheets()){
techSheetsIds.add(Integer.valueOf(sh.getId()));
}
ArrayList<Integer> arrids = new ArrayList<Integer>();
arrids.add(Integer.valueOf(article.getMfsIdentifier()));
/* Load of the article into model product.tamplate of the odoo database */
final Integer id = (Integer)models.execute("execute_kw", Arrays.asList(
db, uid, password,"product.template", "create",
Arrays.asList(new HashMap() {{
put("is_published", true);
put("active", true);
put("x_standartization_level", article.getStandartizationLevel());
put("id", Integer.valueOf(article.getMfsIdentifier()));
put("default_code", article.getCode());
put("name", article.getLabelEn());
put("x_msf_identifier", article.getMfsIdentifier());
put("display_name", article.getLabelEn());
put("x_label_en", article.getLabelEn());
put("x_oca", article.isOca());
put("x_ocb", article.isOcb());
put("x_ocba", article.isOcba());
put("x_ocg", article.isOcg());
put("x_ocp", article.isOcp());
put("x_cold_chain_group", article.getTermosensitive());
put("x_justification_id", article.getJustificationId());
put("x_transport_un_code_id", article.getTransportUnCodeId());
put("x_picture_content", article.getPictureNb());
put("x_picture_label", article.getPictureLabel());
put("x_controlled_substance", article.getControlledSubstance());
put("x_medical_device_class", article.getMedicalDeviceClass());
put("x_code", article.getCode());
put("x_type", article.getType());
put("x_family_id", article.getFamilyId());
put("x_group_id", article.getGroupId());
put("x_who_id", article.getWhoIds());
put("x_product_id", Integer.valueOf(article.getMfsIdentifier()));
}})
));
for(TechnicalSheet sheet: article.getTechSheets()){
final Integer idsh = (Integer)models.execute("execute_kw", Arrays.asList(
db, uid, password,
"x_product.technical_sheet",
"create",
Arrays.asList(new HashMap(){{
put("id", sheet.getId());
put("x_name", sheet.getLabelEn());
put("x_description", sheet.getDefinition());
put("display_name", sheet.getLabelEn());
put("x_product_id", Integer.valueOf(article.getMfsIdentifier()));
put("x_norms", sheet.getNorms());
put("x_precat", sheet.getPrecat());
}})
));
}
}
要使用相应的值(记录)填充或操纵一个或多个字段,您需要使用special commands。
在下面的示例中,我们添加一个新的订单行(order_line
One2many ::
main.models.execute("execute_kw", Arrays.asList(
main.db, uid, main.password,
"sale.order", "write",
Arrays.asList(
Arrays.asList(20),
new HashMap() {{
put("order_line",
Arrays.asList(
Arrays.asList(0, 0,
new HashMap() {{
put("product_id", 3);
}}
)
)
);
}}
)
));