tgpfeiffer / restful-openerp

36 stars 13 forks source link

RESTful OpenERP

This repository is not maintained and has not been updated for a long time. Feel free to use it for inspiration or build your own solution on top of it, but this code should not be used as-is.

Introduction

OpenERP is a powerful Open Source Software for Enterprise Resource Planning (ERP). It has a GTK desktop client and a web interface, both talking to the OpenERP backend via XML-RPC. This also allows to write third-party applications that use OpenERP functionality – however, not in a RESTful way.

The aim of this project is to provide a RESTful “proxy” for OpenERP's XML-RPC web service. We aim to build the API in such a way that

Status

Currently it is possible to get

Also, it is possible to create, for all object types defined within OpenERP (e.g., res.partner), a new object of this type by POSTing an appropriate description to /{database}/{model}. Such a description can in particular be obtained by taking the XML from /{database}/{model}/defaults, extracting the OpenERP-specific fragment (e.g., the res_partner node) and setting the body of all required elements.

Access control is done via HTTP Basic Auth using OpenERP as backend. There is a good test coverage of HTTP response codes, XML validity etc.

To illustrate:

List of all objects

curl -u user:pass http://localhost:8068/erptest/product.product gives:

<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title type="text">product.product items</title>
  <id>http://localhost:8068/erptest/product.product</id>
  <updated>2012-07-04T12:56:07Z</updated>
  <generator>PyAtom</generator>
  <entry>
    <title type="text">MESH (german)</title>
    <id>http://localhost:8068/erptest/product.product/147</id>
    <updated>2012-05-31T13:25:06Z</updated>
    <link href="http://localhost:8068/erptest/product.product/147" />
    <author>
      <name>None</name>
    </author>
  </entry>
  <entry>
    <title type="text">Is God a Number?</title>
    <id>http://localhost:8068/erptest/product.product/179</id>
    <updated>2012-06-13T08:05:54Z</updated>
    <link href="http://localhost:8068/erptest/product.product/179" />
    <author>
      <name>None</name>
    </author>
  </entry>
  ...
</feed>

curl -u user:pass http://localhost:8068/erptest/product.product?default_code=01-2037-01 gives:

<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title type="text">product.product items</title>
  <id>http://localhost:8068/erptest/product.product</id>
  <updated>2012-05-31T13:25:06Z</updated>
  <generator>PyAtom</generator>
  <entry>
    <title type="text">MESH (german)</title>
    <id>http://localhost:8068/erptest/product.product/147</id>
    <updated>2012-05-31T13:25:06Z</updated>
    <link href="http://localhost:8068/erptest/product.product/147" />
    <author>
      <name>None</name>
    </author>
  </entry>
</feed>

Single object description

curl -u user:pass http://localhost:8068/erptest/product.product/147 gives:

<?xml version="1.0" encoding="utf-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">
  <title type="text">MESH (german)</title>
  <id>http://localhost:8068/erptest/product.product/147</id>
  <updated>2012-05-31T13:25:06Z</updated>
  <link href="http://localhost:8068/erptest/product.product/147" rel="self" />
  <author>
    <name>None</name>
  </author>
  <content type="application/vnd.openerp+xml">
  <product_product xmlns="http://localhost:8068/erptest/product.product/schema">
    <ean13 type='char'>9783540853305</ean13>
    <code type='char'>01-2037-01</code>
    <incoming_qty type='float'><!-- 0.0 --></incoming_qty>
    <name_template type='char'><!-- False --></name_template>
    <company_id type='many2one'>
      <link href='http://localhost:8068/erptest/res.company/1' />
    </company_id>
    ...
  </product_product>
  </content>
</entry>

curl -u user:pass http://localhost:8068/erptest/product.product/147?lang=de_DE gives (note the translated title):

<?xml version="1.0" encoding="utf-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">
  <title type="text">MESH (deutsch)</title>
  <id>http://localhost:8068/erptest/product.product/147</id>
  <updated>2012-05-31T13:25:06Z</updated>
  <link href="http://localhost:8068/erptest/product.product/147" rel="self" />
  <author>
    <name>None</name>
  </author>
  <content type="application/vnd.openerp+xml">
  <product_product xmlns="http://localhost:8068/erptest/product.product/schema">
    <ean13 type='char'>9783540853305</ean13>
    <code type='char'>01-2037-01</code>
    <incoming_qty type='float'><!-- 0.0 --></incoming_qty>
    <name_template type='char'><!-- False --></name_template>
    <company_id type='many2one'>
      <link href='http://localhost:8068/erptest/res.company/1' />
    </company_id>
    ...
  </product_product>
  </content>
</entry>

Schema

curl -u user:pass http://localhost:8068/erptest/product.product/schema gives:

<?xml version="1.0" encoding="utf-8"?>
<element name="res_partner" xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes" ns="http://localhost:8068/erptest/res.partner/schema">
<interleave>
  <element name="id"><data type="decimal" /></element>
  <element name="ean13">
    <attribute name="type" />
    <optional><text /></optional>
  </element>
  <element name="code">
    <attribute name="type" />
    <optional><text /></optional>
  </element>
  <element name="incoming_qty">
    <attribute name="type" />
    <optional><data type="double" /></optional>
  </element>
  ...
</interleave>
</element>

Roadmap

See issues.

Dependencies

There is a requirements.txt file for pip that can be used to satisfy the required dependencies.

Installation

To install restful-openerp in a Python virtualenv, do as follows:

License

AGPLv3 for now. Will maybe change later.