【发布时间】:2020-04-16 18:04:11
【问题描述】:
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());
}})
));
}
}
【问题讨论】:
-
嗨,欢迎来到 SO,你能通过很好地格式化帖子顶部来更新你的帖子吗?没有段落没有换行符,这不太可能有人会完整地阅读它
标签: api web-services odoo xml-rpc