() Odoo Extension API

Source: Internet
Author: User
Tags pprint packt

* Open XML-RPC Connection
>>> Import Xmlrpclib
>>> SRV, db = ' http://localhost:8069 ', ' V8dev '
>>> user, pwd = ' admin ', ' admin '
>>> common = Xmlrpclib. Serverproxy ('%s/xmlrpc/2/common '% srv)
>>> common.version ()
{' Server_version_info ': [8, 0, 0, ' final ', 0], ' server_serie ':
' 8.0 ', ' server_version ': ' 8.0 ', ' protocol_version ': 1}

Dependent Xmlrpclib

#验证
>>> uid = common.authenticate (db, User, pwd, {})
>>> Print UID

#取数据
>>> API = Xmlrpclib. Serverproxy ('%s/xmlrpc/2/object '% srv)


>>> api.execute_kw (db, UID, pwd, ' res.partner ', ' search_count ', [[]])
Get the total number of records set

>>> api.execute_kw (db, UID, pwd, ' res.partner ', ' Search ',
[(' country_id ', ' = ', ' Be '), (' parent_id ', '! = ', False)])

[43, 42]
Get the ID sequence of the recordset

>>> api.execute_kw (db, UID, pwd, ' res.partner ', ' read ', [[43]],
{' Fields ': [' id ', ' name ', ' parent_id ']})

[{' parent_id ': [7, ' agrolait '], ' id ': +, ' name ': ' Michel
Fletcher '}]
Get Records

>>> api.execute_kw (db, UID, pwd, ' res.partner ', ' search_read ',
[(' country_id ', ' = ', ' Be '), (' parent_id ', '! = ', False)],
{' Fields ': [' id ', ' name ', ' parent_id ']})

#其它方法
>>> api.execute_kw (db, UID, pwd, ' res.partner ', ' create ', [{' Name '):
' Packt '}])
75
>>> api.execute_kw (db, UID, pwd, ' res.partner ', ' write ', [[75],
{' name ': ' Packt Pub '}])
True
>>> api.execute_kw (db, UID, pwd, ' res.partner ', ' read ', [[[]], [' ID ',
' Name '])
[{' id ': ', ' name ': ' Packt Pub '}]
>>> api.execute_kw (db, UID, pwd, ' res.partner ', ' unlink ', [[75]])
True

* Do a desktop app with interface
note_api.py
----------------
Import Xmlrpclib


Class Noteapi ():

def __init__ (self, SRV, db, User, PWD):
Common = Xmlrpclib. Serverproxy ('%s/xmlrpc/2/common '% srv)
Self.api = Xmlrpclib. Serverproxy ('%s/xmlrpc/2/object '% srv)
Self.uid = common.authenticate (db, User, pwd, {})
Self.pwd = pwd
SELF.DB = db
Self.model = ' Todo.task '

def execute (Self, method, Arg_list, Kwarg_dict=none):
Return self.api.execute_kw (
Self.db, Self.uid, Self.pwd, Self.model,
Method, Arg_list, kwarg_dict or {})

def get (self, ids=none):
domain = [(' id ', ' in ', IDS)] If IDs else []
Fields = [' id ', ' name ']
Return Self.execute (' Search_read ', [Domain, Fields])

def set (self, text, Id=none):
If ID:
Self.execute (' Write ', [[id], {' Name ': text}])
Else
Vals = {' name ': text, ' user_id ': Self.uid}
id = self.execute (' Create ', [Vals])
Return ID

if __name__ = = ' __main__ ':
SRV, db = ' http://localhost:8069 ', ' V8dev '
User, pwd = ' admin ', ' admin '
API = Noteapi (SRV, DB, user, PWD)
From Pprint import Pprint
Pprint (API.get ())
----------------
note_gui.py
----------------
From Tkinter import Text, Tk
Import Tkmessagebox
From NOTE_API import Noteapi

Class NoteText (Text):
def __init__ (self, API, text= ", Id=none):
Self.master = Tk ()
Self.id = ID
Self.api = API
Text.__init__ (self, self.master, bg= ' #f9f3a9 ',
wrap= ' word ', undo=true)
Self.bind (' <Control-n> ', self.create)
Self.bind (' <Control-s> ', Self.save)
If ID:
Self.master.title (' #%d '% ID)
Self.delete (' 1.0 ', ' End ')
Self.insert (' 1.0 ', text)
Self.master.geometry (' 220x235 ')
Self.pack (fill= ' both ', expand=1)

def create (self, event=none):
NoteText (Self.api, ")

def save (Self, event=none):
Text = Self.get (' 1.0 ', ' End ')
Self.id = Self.api.set (text, self.id)
Tkmessagebox.showinfo (' Info ', ' Note%d Saved. '% self.id)


if __name__ = = ' __main__ ':
SRV, db = ' http://localhost:8069 ', ' V8dev '
User, pwd = ' admin ', ' admin '
API = Noteapi (SRV, DB, user, PWD)
For note in API.get ():
x = NoteText (API, note[' name '], note[' id '))
X.master.mainloop ()
----------------

* Erppeek
The first thing to install is Erppeek
$ pip install-u Erppeek

#API usage:
>>> Import Erppeek
>>> API = Erppeek. Client (' http://localhost:8069 ', ' V8dev ',
' admin ', ' admin ')
>>> api.common.version ()
>>> api.count (' Res.partner ', [])
>>> api.search (' Res.partner ', [(' country_id ', ' = ', ' be '),
(' parent_id ', '! = ', False)])
>>> api.read (' Res.partner ', [+], [' id ', ' name ', ' parent_id ')

>>> m = Api.model (' Res.partner ')
>>> m = API. Respartner

>>> M.count ([(' Name ', ' like ', ' packt% ')]) return is the number
>>> M.search ([(' Name ', ' like ', ' packt% ')]) returns the ID
>>> RECs = M.browse ([' Name ', ' like ', ' packt% ')] Return is the Record object

# CLI Usage
$ Erppeek--help can see the detailed information


* The plug-in development is finished here.






() Odoo Extension API

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.