Raspberry Pi interface to OpenERP

   
The Raspberry Pi  (approx €30) is a credit-card-sized single-board computer developed in the UK by the Raspberry Pi Foundation with the intention of promoting the teaching of basic computer science in schools.

The Raspberry Pi has a Broadcom BCM2835 system on a chip (SoC), which includes an ARM1176JZF-S 700 MHz processor. 

The Foundation provides Debian and Arch Linux ARM distributions for download.[17]  It has tools for supporting Python as the main programming language


Since 2011 I've been quite excited about the development of the Raspberry Pi,  mainly as an alternative solution to Arduino and other Microcontroller solutions for my CIM projects.  

Although the original use of the Raspberry Pi was for promotion of computer science, technology, engineering and math eduction within schools, and colleges (STEM),  it has a now become a sort of revolution amount hobby technologist and has a much bigger following in many other areas such as within  HTPC  Tinkerers (Home Theatre Personal Computer), Autonomous Robots and Robotics, Kinetic Arts, etc. 

Gladly to say, the development has now reached a mature stage where I believe it has a place within some Business and Industrial applications -  brining significant total cost of ownership costs savings compared to typical industrial PC solutions  (I would guess > 50%) . With an I2C and other interlaces you can connect external sensors and control external production systems.

I bought the Release B early in 2012  - as soon it became available,  and have been testing it since. As the foundation are promoting Python as the main development language,  I also see many embedded application interfaces to OpenERP !   It comes with a Raspbian veriosn of Linux but there are also various other Linux versions that will run on the Pi. Some people have even managed to a get a version of Android running on it. 

With the browsers supplied with Raspbian, there are problems connecting as a thin client to an OpenERP server as it's missing various libraries, but I know some developers are working to  fix this. As soon as it's working then I'll update this article.

    
                Raspberry Pi interface to OpenERP via LAN Interface

A Simple Interface to OpenERP
Eventhough the pi comes with USB for KeyBoard and mouse, I suggest the first thing to do is to install Tight-VNC,  for  remote connection and place the credit card device anywhere on your network. The installation of Tight VNC on a Raspberry Pi is described very well -> here . Install the GUI  as it's quite nice to test too. 

Python comes already pre-installed on the Pi but you may need to install some XML-RPC libraries to enable the connection to OpenERP. 

To get the demo code working correctly you need to create new  OpenERP database. Keep default values of admin / admin for username /  password of the administrator role. Name the database demo (or change the code below accordingly) Ensure to select demo data when creating the database. Install the sales, warehouse and manufacturing modules. You should see many BoM's already created. 

Now you're ready to connect from the Raspberry Pi. Start the Idle Python GUI and copy the code below. Make necessary changes to the IP address and name of databsase, etc.  Then run. 

Here is the Python code: (you can also test it from a PC first) 

Python Code - XML-RPC


import xmlrpclib

sock = xmlrpclib.ServerProxy('http://<your ip address of Openerp server>:8069/xmlrpc/object')
uid = 1
pwd = 'admin'  (normally the default user is 1 with password admin)
dbname ='demo'  the name of the OpenERP database

# find all products with a BOM i.e. where bom field != blank
args = [('bom_lines', '!=', '')] #query clause
ids = sock.execute(dbname, uid, pwd, 'mrp.bom', 'search', args)
ids=sorted(ids)

# Print these record ids

print 'The following BOM Records have a BOM ID of = ',ids 

# Get the details of the child for each master bom record
# Field Product ID returns the product ID and name of the product in tht product.product table
# Which is useful to retrieve all details of the parent and child BOM too.
bom_fields = ('name', 'product_id','bom_lines' )



for i in range(len(ids)):
   
    bom_id1 = sock.execute(dbname, uid, pwd, ('mrp.bom'), 'read', ids[i], bom_fields)

    
    print '----------------------------------'
    print 'Main BOM=', ids[i], bom_id1, bom_id1['bom_lines']

    # get childs boms and show these too    
    for child1 in bom_id1['bom_lines']:
        bom_child1 = sock.execute(dbname, uid, pwd, ('mrp.bom'), 'read', child1, bom_fields)

        # Extract the parent BOM ID of this child to see if this also has a BOM    
        anewlist = bom_child1 ['product_id']
        #print 'Child=',bom_child1, 
        print '*******Child1 =',child1, ',',bom_child1 ['name'], ',', anewlist [0] , ',',   bom_child1 ['bom_lines']

        
        #print '..........',anewlist [0] # extract the id of the parent bom
        #bom_id2 = sock.execute(dbname, uid, pwd, ('mrp.bom'), 'read', anewlist [0], bom_fields)

        
            
        # get any BOMs of childs boms and show these too  (this part needs finishing)



A list of all BOMS and child components will be printed out as follows  (with OpenERP 7.0 demo data) :  

Text Box

Report


The following BOM Records have a BOM ID of =  [1, 3, 5, 7, 11, 15, 19, 24, 30, 36, 45, 47, 49]
----------------------------------
Main BOM= 1 {'product_id': [19, '[HDD-SH2] HDD SH-2'], 'id': 1, 'name': 'HDD 500GB', 'bom_lines': [2]} [2]
*******Child1 = 2 , 320GB HDD , 18 , []
----------------------------------
Main BOM= 3 {'product_id': [20, '[HDD-DEM] HDD on Demand'], 'id': 3, 'name': 'HDD 2TB on Demand', 'bom_lines': [4]} [4]
*******Child1 = 4 , HDD 500GB , 19 , []
----------------------------------
Main BOM= 5 {'product_id': [20, '[HDD-DEM] HDD on Demand'], 'id': 5, 'name': 'HDD on Demand', 'bom_lines': [6]} [6]
*******Child1 = 6 , 320GB HDD , 18 , []
----------------------------------
Main BOM= 7 {'product_id': [28, '[LAP-CUS] Laptop Customized'], 'id': 7, 'name': 'Laptop Customized', 'bom_lines': [8, 9, 10]} [8, 9, 10]
*******Child1 = 8 , Windows 7 Professional , 41 , []
*******Child1 = 9 , USB Keyboard, QWERTY , 9 , []
*******Child1 = 10 , Mouse, Wireless , 13 , []
----------------------------------
Main BOM= 11 {'product_id': [28, '[LAP-CUS] Laptop Customized'], 'id': 11, 'name': 'Laptop Customized + Azerty', 'bom_lines': [12, 13, 14]} [12, 13, 14]
*******Child1 = 12 , Windows 7 Professional , 41 , []
*******Child1 = 13 , USB Keyboard, AZERTY , 10 , []
*******Child1 = 14 , Mouse, Laser , 12 , []
----------------------------------
Main BOM= 15 {'product_id': [17, '[C-Case] Computer Case'], 'id': 15, 'name': 'Computer Case-1', 'bom_lines': [16, 17, 18]} [16, 17, 18]
*******Child1 = 16 , Processesor AMD 8-Core , 24 , []
*******Child1 = 17 , Motherboard I9P57 , 21 , []
*******Child1 = 18 , HDD 320GB , 18 , []
----------------------------------
Main BOM= 19 {'product_id': [17, '[C-Case] Computer Case'], 'id': 19, 'name': 'Computer Case-2', 'bom_lines': [20, 21, 22, 23]} [20, 21, 22, 23]
*******Child1 = 20 , Processor Core i5 2.70 Ghz , 23 , []
*******Child1 = 21 , Motherboard A20Z7 , 22 , []
*******Child1 = 22 , HDD 500GB , 19 , []
*******Child1 = 23 , Graphics Card , 25 , []
----------------------------------
Main BOM= 24 {'product_id': [5, '[PCSC349] PC Assemble SC349'], 'id': 24, 'name': 'PC Assemble + 2GB RAM', 'bom_lines': [25, 26, 27, 28, 29]} [25, 26, 27, 28, 29]
*******Child1 = 25 , 15" LCD Monitor  , 7 , []
*******Child1 = 26 , Computer Case-1 , 17 , []
*******Child1 = 27 , Mouse, Laser , 12 , []
*******Child1 = 28 , USB Keyboard, QWERTY , 9 , []
*******Child1 = 29 , RAM DDR2 1GB , 16 , []
----------------------------------
Main BOM= 30 {'product_id': [4, '[PCSC234] PC Assemble SC234'], 'id': 30, 'name': 'PC Assemble + 512MB RAM', 'bom_lines': [31, 32, 33, 34, 35]} [31, 32, 33, 34, 35]
*******Child1 = 31 , 17" LCD Monitor , 8 , []
*******Child1 = 32 , Computer Case-2 , 17 , []
*******Child1 = 33 , Mouse, Laser , 12 , []
*******Child1 = 34 , USB Keyboard, QWERTY , 9 , []
*******Child1 = 35 , RAM DDR 512MB , 14 , []
----------------------------------
Main BOM= 36 {'product_id': [6, '[PC-DEM] PC Assemble + Custom (PC on Demand)'], 'id': 36, 'name': 'PC Assemble + Custom RAM (PC on Demand)', 'bom_lines': [37, 38, 39, 40, 41]} [37, 38, 39, 40, 41]
*******Child1 = 37 , 15" LCD Monitor  , 7 , []
*******Child1 = 38 , Computer Case-1 , 17 , []
*******Child1 = 39 , RAM DDR 512MB , 14 , []
*******Child1 = 40 , Mouse, Laser , 12 , []
*******Child1 = 41 , USB Keyboard, QWERTY , 9 , []
----------------------------------
Main BOM= 45 {'product_id': [25, '[CARD] Graphics Card - Type 1'], 'id': 45, 'name': 'Graphics Card RAMSR2', 'bom_lines': [46]} [46]
*******Child1 = 46 , RAM SR2 , 15 , []
----------------------------------
Main BOM= 47 {'product_id': [25, '[CARD] Graphics Card - Type 1'], 'id': 47, 'name': 'Graphics Card RAMSR3', 'bom_lines': [48]} [48]
*******Child1 = 48 , RAM SR3 , 16 , []

Links