コンテンツへスキップ
Odoo メニュー
  • サインイン
  • 無料で15日試す
  • アプリ
    財務
    • 会計
    • 請求
    • 経費
    • スプレッドシート(BI)
    • ドキュメント管理
    • 署名
    販売
    • CRM
    • 販売
    • POS店舗
    • POSレストラン
    • サブスクリプション
    • レンタル
    ウェブサイト
    • ウェブサイトビルダー
    • eコマース
    • ブログ
    • フォーラム
    • ライブチャット
    • eラーニング
    サプライチェーン
    • 在庫
    • 製造
    • 製品ライフサイクル管理 (PLM)
    • 購買
    • 整備
    • 品質
    人事業務
    • 従業員管理
    • 採用
    • 休暇管理
    • 人事評価
    • リファラル
    • フリート
    マーケティング
    • ソーシャルマーケティング
    • メールマーケティング
    • SMSマーケティング
    • イベント
    • マーケティングオートメーション
    • アンケート調査
    サービス
    • プロジェクト管理
    • タイムシート
    • フィールドサービス
    • ヘルプデスク
    • 計画
    • アポイントメント
    生産性向上ツール
    • ディスカッション
    • 承認
    • IoT
    • VoIP
    • ナレッジ
    • WhatsApp
    サードパーティアプリ Odooスタジオ Odooクラウドプラットホーム
  • インダストリー(業種別ソリューション)
    小売
    • 書店
    • アパレルショップ
    • 家具専門店
    • 食料品店
    • 金物店
    • 玩具店
    飲食・ホスピタリティ業界
    • バー・パブ
    • レストラン
    • ファストフード
    • ゲストハウス
    • 飲料販売代理店
    • ホテル
    不動産
    • 不動産会社
    • 建築事務所
    • 建設
    • 不動産管理
    • 造園
    • 住宅所有者組合
    コンサルティング
    • 会計事務所
    • Odooパートナー
    • マーケティングエージェンシー
    • 法律事務所
    • 人材派遣
    • 監査・認証
    製造
    • テキスタイル
    • 金属
    • 家具
    • 飲食
    • 醸造所
    • コーポレートギフト
    ヘルス & フィットネス
    • スポーツクラブ
    • 眼鏡店
    • フィットネスセンター
    • ウェルネス専門家
    • 薬局
    • ヘアサロン
    業種
    • 便利屋
    • IT ハードウェア・サポート
    • 太陽エネルギーシステム
    • 靴メーカー
    • クリーニングサービス
    • 空調設備サービス
    その他
    • 非営利団体
    • 環境機関
    • ビルボードレンタル
    • 写真
    • 自転車リース
    • ソフトウェアリセラー
    すべての業種を見る
  • コミュニティ
    学ぶ
    • チュートリアル
    • ドキュメンテーション
    • 認定
    • トレーニング
    • ブログ
    • ポッドキャスト
    教育サポート
    • 教育プログラム
    • Scale Up! ビジネスゲーム
    • Odooオフィス訪問
    ソフトを入手
    • ダウンロード
    • エディションを比較
    • リリース
    コラボレーション
    • Github
    • フォーラム
    • イベント
    • 翻訳
    • パートナーになる
    • パートナー様向けサービス
    • 会計事務所を登録
    サービス利用
    • パートナー一覧
    • 会計事務所一覧
    • 今すぐ相談する
    • 導入支援サービス
    • お客様一覧
    • サポート
    • アップグレード
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    製品デモを利用する
  • 料金
  • ヘルプ

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • 会計
  • 在庫
  • PoS
  • プロジェクト
  • MRP
All apps
コミュニティで交流するには登録する必要があります。
全てのポスト 人々 バッジ
タグ (全て表示)
odoo accounting v14 pos v15
このフォーラムについて
コミュニティで交流するには登録する必要があります。
全てのポスト 人々 バッジ
タグ (全て表示)
odoo accounting v14 pos v15
このフォーラムについて
ヘルプ

How to set a related field with a one 2many, many2one and many2many field, using Odoo API(XMLRPC)?

購読

この投稿に活動があった際に通知を受け取ります

この質問にフラグが付けられました
many2oneone2manyapixmlrpcmany2many
1 返信
6219 ビュー
アバター
Simeon Damyanov

Hi guys, new to Odoo, i'm trying to create a web service in Java, loading data into Odoo, in particular, into the models product.template and technical.sheet, a custom model that i created. For one product there can be 0 or many technical sheets and for one technical sheet - one product.

In the model technical.sheet i created a field x_product_id, the type - many2one and the object relation – product.tamplate. In product.template i create the same field, x_product_id, but the type is one2many, the object relation - technical.sheet and the field relation x_product_id(technical.sheet).

I’ve succeded to load the products and the technical sheets but when I try to set the relational fields, I get errors.

 Does anybody have an example or an idea how to set  fields of type one2many, many2one and many2many,  using Odoo external API?

Thanks!

This is the piece of code:

 

for(Article article: 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());

                                                                           }})

                                         ));

                                

                            }

                   

                           

                           

                           

                           

                          

                    }

 

1
アバター
破棄
アバター
Simeon Damyanov
著作者 最善の回答

An answer to my question. This piece of code worked for me, i created list of articles(product.template), each article is related to zero or many technical sheet, relation one2many.


HashMap<String, Article> articles = (HashMap<String, Article>)globalMap.get("articles");

             
              String username = "****";
              String password = "****";
              String db = "****";
              String url ="****";

              try{

              final XmlRpcClient authClient = new XmlRpcClient();
              final XmlRpcClientConfigImpl authStartConfig = new XmlRpcClientConfigImpl();
              authStartConfig.setServerURL(new URL(String.format("%s/xmlrpc/2/common", url)));
                     
              List configList = new ArrayList();
              Map paramMap = new HashMap();

              configList.add(db);
              configList.add(username);
              configList.add(password);
              configList.add(paramMap);

              int uid = (int)authClient.execute(authStartConfig, "authenticate", configList);

              final XmlRpcClient models = new XmlRpcClient() {{
                          setConfig(new XmlRpcClientConfigImpl() {{
                              setServerURL(new URL(String.format("%s/xmlrpc/2/object", url)));
                          }});
              }};

              /* Loop all the articles */
              for(Article article: 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 articles into model product.template 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());
                                                            
                                                             /* Set Technical Sheets*/
                                                             if(article.getTechSheets().size()>0){
                                                               put("x_product_id",
                                                                   Arrays.asList(
                                                                        Arrays.asList(
                                                                           0,
                                                                           0,
                                                                           new HashMap(){{
                                                                                          for(TechnicalSheet sheet: article.getTechSheets()){
                                                                                              put("id", sheet.getId());
                                                                                                put("x_name", sheet.getLabelEn());
                                                                                                put("x_description", sheet.getDefinition());
                                                                                                put("display_name", sheet.getLabelEn());
                                                                                                put("x_product_id", article.getMfsIdentifier());
                                                                                                put("x_norms", sheet.getNorms());
                                                                                                put("x_precat", sheet.getPrecat());
                                                                                            }
                                                                                            }}
                                                                                            )));
                                                           }}})
                                                            
                      ));
                    
              }
              
              }catch(MalformedURLException e){
                  System.out.print("MalformedURLException: "+e.toString()+" "+e.getStackTrace());
              }
              catch(XmlRpcException e){
                  System.out.print("XmlRpcException: "+e.toString()+" "+e.getStackTrace());
              } 

0
アバター
破棄
ディスカッションを楽しんでいますか?読むだけでなく、参加しましょう!

今すぐアカウントを作成して、限定機能を利用したり、素晴らしいコミュニティと交流しましょう!

登録
関連投稿 返信 ビュー 活動
Cannot update Many2one field that is linked to a One2many field via XML-RPC or else "another model requires the record being deleted" error yields. 解決済
many2one one2many xmlrpc
アバター
1
7月 23
4622
Prevent selecting the same value in one2many field in odoo 解決済
many2one one2many many2many
アバター
アバター
アバター
アバター
3
4月 20
11650
fetch related models via web API
one2many api xmlrpc
アバター
0
8月 16
4695
Odoo V12 : ORM with One2many or Many2one
many2one one2many many2many odooV12
アバター
アバター
2
5月 19
4781
Many2One inside One2Many domain filter from Many2Many
many2one one2many many2many osv.osv
アバター
0
5月 16
5297
コミュニティ
  • チュートリアル
  • ドキュメンテーション
  • フォーラム
オープンソース
  • ダウンロード
  • Github
  • Runbot
  • 翻訳
サービス
  • Odoo.shホスティング
  • サポート
  • アップグレード
  • カスタム開発
  • 教育プログラム
  • 会計事務所一覧
  • パートナー一覧
  • パートナーになる
企業情報
  • 会社概要
  • ブランドアセット
  • お問い合わせ
  • 採用情報
  • イベント
  • ポッドキャスト
  • ブログ
  • お客様一覧
  • リーガル情報 • プライバシーポリシー
  • セキュリティ
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo(オドゥー)は、CRM、eコマース、会計、在庫管理、POS、プロジェクト管理など、企業のさまざまな業務を一つのシステムで管理できる、ベルギー発のオープンソースのERPソフトウェアです。

高機能で使いやすく、完全に統合されたERPとして、ユニークな価値を提供しています。

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now