Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Validacions
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Immobiliari
    • Agència immobiliària
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consultoria
    • Empresa comptable
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Mobles
    • Menjar
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Sistemes d'energia solar
    • Shoe Maker
    • Serveis de neteja
    • Instal·lacions HVAC
    Altres
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda

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

  • CRM
  • e-Commerce
  • Comptabilitat
  • Inventari
  • PoS
  • Projectes
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

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

Subscriure's

Get notified when there's activity on this post

This question has been flagged
many2oneone2manyapixmlrpcmany2many
1 Respondre
6208 Vistes
Avatar
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
Avatar
Descartar
Avatar
Simeon Damyanov
Autor Best Answer

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
Avatar
Descartar
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Registrar-se
Related Posts Respostes Vistes Activitat
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. Solved
many2one one2many xmlrpc
Avatar
1
de jul. 23
4615
Prevent selecting the same value in one2many field in odoo Solved
many2one one2many many2many
Avatar
Avatar
Avatar
Avatar
3
d’abr. 20
11645
fetch related models via web API
one2many api xmlrpc
Avatar
0
d’ag. 16
4689
Odoo V12 : ORM with One2many or Many2one
many2one one2many many2many odooV12
Avatar
Avatar
2
de maig 19
4779
Many2One inside One2Many domain filter from Many2Many
many2one one2many many2many osv.osv
Avatar
0
de maig 16
5292
Community
  • Tutorials
  • Documentació
  • Fòrum
Codi obert
  • Descarregar
  • GitHub
  • Runbot
  • Traduccions
Serveis
  • Allotjament a Odoo.sh
  • Suport
  • Actualització
  • Desenvolupaments personalitzats
  • Educació
  • Troba un comptable
  • Troba un partner
  • Converteix-te en partner
Sobre nosaltres
  • La nostra empresa
  • Actius de marca
  • Contacta amb nosaltres
  • Llocs de treball
  • Esdeveniments
  • Pòdcast
  • Blog
  • Clients
  • Informació legal • Privacitat
  • Seguretat
الْعَرَبيّة 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 és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

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