Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

How do you create and update One2Many and Many2Many records with Python 3?

Here is a code snippet that will create a new Partner, a new Contact, then update the Contact.

import xmlrpc.client

#connection details
server_url = 'http://localhost:8069'
db = 'database_name'
login = 'admin'
password = 'admin'

#endpoints
common_ep = xmlrpc.client.ServerProxy(server_url+'/xmlrpc/2/common')
object_ep = xmlrpc.client.ServerProxy(server_url+'/xmlrpc/2/object')

#login
uid = common_ep.authenticate(db, login, password,{})

#define new Partner
new_partner = {
  'name': 'Joe Smith',
  'ref': '12345',
}
 
#create New Partner 
new_partner_id = object_ep.execute_kw(db, uid, password, 'res.partner', 'create', [new_partner])

#define New Contact
new_contact = {
  'name': 'Jane Smith',
  'ref': '54321',
  'parent_id': new_partner_id,
}

#create New Contact, under New Partner
new_contact_id = object_ep.execute_kw(db, uid, password, 'res.partner', 'create', [new_contact])

#define update for New Contact

updated_information = {
  'phone': '555 123 1234',
}

#find New Contact
existing_contact_id = object_ep.execute_kw(db, uid, password, 'res.partner', 'search', [[['ref','=','54321']]])

object_ep.execute_kw(db, uid, password, 'res.partner', 'write', [existing_contact_id, updated_information])
Comment

PREVIOUS NEXT
Code Example
Python :: how to increase and decrease volume of speakers using python 
Python :: python folium add minimap to map 
Python :: arweave python 
Python :: import pandas 
Python :: python list contains substring 
Python :: how to set the location on a pygame window 
Python :: change title size matplotlib 
Python :: python loop through files in directory 
Python :: grid search python 
Python :: how to print items in a list in a single line python 
Python :: pandas profiling 
Python :: apple 
Python :: divide by zero errors when using annotate 
Python :: pytho narrondir un nombre 
Python :: remove non-ascii characters python 
Python :: pil to grayscale 
Python :: create zero array in python 
Python :: add year to id django 
Python :: how to save model to a file python 
Python :: how to redefine a legend in pandas 
Python :: youtube to mp3 python 
Python :: python pandas remove punctuation 
Python :: streamlit st.file_uploader 
Python :: selenium send keys python 
Python :: binning data dataframe, faire classe statistique dataframe 
Python :: get all paragraph tags beautifulsoup 
Python :: kivy date widget 
Python :: print all values of dictionary 
Python :: flask oneid 
Python :: pandas normalize groupby 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =