宜兴通达竭诚为您服务。

通达科技 - 宜兴电脑维护及IT服务外包服务商

XML RPC
  • 上传者: Administrator
  • 上传时间:2024年02月24日 07时19分54秒
摘要:
XML RPC** It is a specification and a collection of implementations that allow procedure calls to be made over the internet by software running in dif ......
正文 相关文章 请喝咖啡

    XML RPC

    It is a specification and a collection of implementations that allow procedure calls to be made over the internet by software running in different environments and on different operating systems.

    It's a remote operation that's being asked for. XML is utilized for encoding, while HTTP is used for transport. Though it facilitates the transmission, processing, and return of complex data structures, XML-RPC is designed to be as simple as is practicable.

    Connection to Odoo

    In order to access data inside Odoo, we must first connect to it. The xmlrpc/2/common endpoint, one of two types available in Odoo, does not require authentication.

    Use this endpoint to get the version of Odoo or to verify the user's identity. The authenticating process returns the user's ID.

    API Key

    We may generate an API key for a user using Odoo 16.0. For adding a key to the user, enable developer mode. Select the Preferences menu from the user’s My Profile, as depicted below.

    odoo Development

    Select the Account Security Tab, and click on the New API key.

    odoo Development

    Give the API key a name and confirm the account's password.

    odoo Development

    You will then receive the API key.

    You can utilize the API key to connect to Odoo.

    import xmlrpc.client
    data_url = 'http://localhost:8016' # odoo instance url
    database = 'data' # database name
    user = 'admin' # username
    password = 'f2494e60974b564df60318c8782f169a5cc16463' # api key
    common_auth = xmlrpc.client.ServerProxy('{}/xmlrpc/2/common'.format(data_url))
    uid = common_auth.authenticate(database, user, password, {})

    With the database name, user login, and API key as the password, we can authenticate the user using the xmlrpc/2/common. User ID is a result of the authenticate function. Jot down that user ID (Needed for accessing data from Odoo).

    Calling Methods

    The second endpoint, xmlrpc/2/object, is used to access data stored in Odoo or to create new data within Odoo. We can get the data with the use of the xmlrpc/2/execute kw object's method.

    data_model = xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(data_url))

    The user ID created when connecting to Odoo will be used since xmlrpc/2/object requires authentication.

    Read/Search Records:

    Search:

    search_partners_ids = data_model.execute_kw(database, uid, password, 'res.partner', 'search', [[['is_company', '=', True]]])

    All record IDs in the chosen model are returned by the search function.

    Output

    [14, 10, 11, 15, 41, 1, 12, 13, 9]

    Limit your search to:

    partners = data_model.execute_kw(database, uid, password, 'res.partner', 'search', [[['is_company', '=', True]]], {'limit': 1})

    We are able to decide how many records we want by using the limit option.

    Output:

    [14]

    Search with Offset:

    partners = data_model.execute_kw(database, uid, password, 'res.partner', 'search', [[['is_company', '=', True]]], {'offset': 1})

    Using the offset argument, we can select the record from which to start our search.

    Output:

    [10, 11, 15, 41, 1, 12, 13, 9]

    Search Count:

    partners = data_model.execute_kw(database, uid, password, 'res.partner', 'search_count', [[['is_company', '=', True]]])

    Search count returns the number of records that meet the requirement.

    Read:

    Partner_id = data_model.execute_kw(database, uid, password, 'res.partner', 'search', [[['is_company', '=', True]]], {'limit': 1})
    partners = data_model.execute_kw(database, uid, password, 'res.partner', 'read', [partners_id])

    Each field's values are returned by the read method as a key-value pair. The IDs of the records we wish to get must be provided.

    Output:

    [{'id': 14, 'message_is_follower': False, 'message_follower_ids': [], 'message_partner_ids': [], 'message_ids': [], 'has_message': False, 'message_unread': False, 'message_unread_counter': 0, 'message_needaction': False, 'message_needaction_counter': 0, 'message_has_error': False, 'message_has_error_counter': 0, 'message_attachment_count': 0, 'message_main_attachment_id': False, 'website_message_ids': [], 'message_has_sms_error': False, 'phone_sanitized': '(870)-931-0505', 'phone_sanitized_blacklisted': False, 'phone_blacklisted': False, 'mobile_blacklisted': False, 'phone_mobile_search': False, 'email_normalized': 'azure.interior24@example.com', 'is_blacklisted': False, 'message_bounce': 0, 'activity_ids': [], 'activity_state': False, 'activity_user_id': False, 'activity_type_id': False, 'activity_type_icon': False, 'activity_date_deadline': False, 'my_activity_date_deadline': False, 'activity_summary': False, 'activity_exception_decoration': False, 'activity_exception_icon': False, 'name': 'Azure Interior', 'display_name': 'Azure Interior', 'date': False, 'title': False, 'parent_id': False, 'parent_name': False, 'child_ids': [26, 33, 27], 'ref': False, 'lang': 'en_US', 'active_lang_count': 1, 'tz': False, 'tz_offset': '+0000', 'user_id': False, 'vat': False, 'same_vat_partner_id': False, 'bank_ids': [], 'website': 'http://www.azure-interior.com', 'comment': False, 'category_id': [5], 'credit_limit': 0.0, 'active': True, 'employee': False, 'function': False, 'type': 'contact', 'street': '4557 De Silva St', 'street2': False, 'zip': '94538', 'city': 'Fremont', 'state_id': [13, 'California (US)'], 'country_id': [233, 'United States'], 'country_code': 'US', 'partner_latitude': 0.0, 'partner_longitude': 0.0, 'email': 'azure.Interior24@example.com', 'email_formatted': '"Azure Interior" ', 'phone': '(870)-931-0505', 'mobile': False, 'is_company': True, 'industry_id': False, 'company_type': 'company', 'company_id': False, 'color': 0, 'user_ids': [], 'partner_share': True, 'contact_address': 'Azure Interior\n4557 De Silva St\n\nFremont CA 94538\nUnited States', 'commercial_partner_id': [14, 'Azure Interior'], 'commercial_company_name': 'Azure Interior', 'company_name': False, 'barcode': False, 'self': [14, 'Azure Interior'], '__last_update': '2022-03-24 07:18:33', 'create_uid': [1, 'OdooBot'], 'create_date': '2022-03-24 07:17:52', 'write_uid': [1, 'OdooBot'], 'write_date': '2022-03-24 07:18:33', 'im_status': 'im_partner', 'channel_ids': [], 'signup_token': False, 'signup_type': False, 'signup_expiration': False, 'signup_valid': False, 'signup_url': False, 'property_product_pricelist': [1, 'Public Pricelist (EUR)'], 'partner_gid': 0, 'additional_info': False, 'property_stock_customer': [5, 'Partner Locations/Customers'], 'property_stock_supplier': [4, 'Partner Locations/Vendors'], 'picking_warn': 'no-message', 'picking_warn_msg': False, 'x_encrypted': False}]

    Read with fields:

    partner_id = data_model.execute_kw(database, uid, password, 'res.partner', 'search', [[['is_company', '=', True]]], {'limit': 1})
    partners = data_model.execute_kw(database, uid, password, 'res.partner', 'read', [partners_id], {'fields': ['name', 'email']})
    

    Using the fields option, we can specify which fields we want to fetch.

    Output:

    [{'id': 14, 'name': 'Azure Interior', 'email': 'azure.Interior24@example.com'}]

    Search Read:

    partners = data_model.execute_kw(database, uid, password, 'res.partner', 'search_read', [[['is_company', '=', True]]], {'fields': ['name', 'email'], 'limit': 1})

    Search read is the combination of both search and read

    Output:

    [{'id': 14, 'name': 'Azure Interior', 'email': 'azure.Interior24@example.com'}]

    Create records:

    partner_id = data_model.execute_kw(database, uid, password, 'res.partner', 'create', [{'name': 'Test Partner', 'email': 'test@test.com'}])

    Create method is used for creating a record in Odoo. It returns the id of the created records.

    Output:

    1

    Update records:

    partner_id = data_model.execute_kw(database, uid, password, 'res.partner', 'create', [{'name': 'Test Partner', 'email': 'test@test.com'}])
    partner = data_model.execute_kw(database, uid, password, 'res.partner', 'write', [[partner_id], {'name': 'Test Partner Updated'}])

    The write method is used to update the data in an existing record. It returns True if the record is updated.

    Output:

    True

    Delete Records:

    partner_id = data_model.execute_kw(database, uid, password, 'res.partner', 'create', [{'name': 'Test Partner', 'email': 'test@test.com'}])
    partner_id = data_model.execute_kw(database, uid, password, 'res.partner', 'unlink', [[partner_id]])

    A record is removed using the unlink method. If the record is erased, it returns true.

    Output:

    True
    本文章从网上收集,如有侵权请联系tderp@tderp.com删除
  • 微信扫一扫,一分也是爱:
  • 微信

服务原则及地区范围

宜兴通达网络科技有限公司,地处中国宜兴环科园内,是一家高新技术企业。公司在企业网络维护和企业信息化建设与咨询方面,有10多年经验。

我公司愿与客户一道,力求彻底解决客户问题!
我们不是在给企业提供“头痛医头、脚痛医脚”的暂时解决方案,而是在部署根本性安全与稳定服务!!
我们愿携手客户,建立企业IT规划;杜绝随意安装系统、软件等操作;力求共同维护有序、安全、稳定的网络办公环境!!!
IT服务,服务是根本,客户是上帝;我们提供快速响应、快速上门、快速排查,提供优质高效的服务!!!!

通达科技提供全国范围内的服务,服务形式包括远程协助、电话咨询、电子邮件咨询、传真咨询、问答平台的问题解决等。

宜兴地区提供上门服务:

  • 市区服务:宜城街道、城北街道(屺亭街道)、新街街道、新庄街道、环科园、渚桥开发区
  • 市郊服务:张渚镇、西渚镇、太华镇、徐舍镇、官林镇、杨巷镇、新建镇、和桥镇、高塍镇、万石镇、周铁镇、芳桥镇、丁蜀镇、湖父镇。
  • 联系电话:189-21-343434
  • 在线沟通: