RecordList representation capabilities

In [1]:
# Import Client and Session classes
from openerp_proxy.ext.all import HField, HTMLTable
from openerp_proxy import (Client,
                           Session)

cl = Client('localhost', 'openerp_proxy_test_db', 'admin', 'admin', protocol='xml-rpc')
cl
Out[1]:
RPC Client
login admin
Host localhost
Protocol xml-rpc
Port 8069
Database openerp_proxy_test_db
Info
To get list of registered objects for thist database
access registered_objects property:
 .registered_objects
To get Object instance just call get_obj method
 .get_obj(name)
where name is name of Object You want to get
or use get item syntax instead:
 [name]
In [2]:
so_list = cl['sale.order'].search_records([])
so_list
Out[2]:
RecordList(sale.order): length=8
Client xml-rpc://[email protected]:8069/openerp_proxy_test_db
Object Object ('sale.order')
Record count 8
Info
To get table representation of data call method
 .as_html_table
passing as arguments fields You want to see in resulting table
for better information get doc on as_html_table method:
 .as_html_table?
example of using this mehtod:
 .as_html_table('id','name','_name')
Here _name field is aliase for result of name_get methodcalled on record

Display simple sale orders in table view

In [3]:
# Use anyfield library to simplify code: https://pypi.python.org/pypi/anyfield
from anyfield import F

# High light rows by condition
highlighters = {
    '#99FF99': F.state == 'done',
    '#9999FF': F.state == 'draft',
    '#FFFF99': F.state == 'progress',
}

# Display as table.
# Note that prefetch method is used to fetch some set of fields with less RPC call.
# on big datasets it may speed up performance signifiantly.
# Each RecordList instance have related cache, which reduce need of reading data on each field get.
so_list.prefetch('id', 'name', 'partner_id', 'partner_id.email', 'state')
so_table = so_list.as_html_table(
    'id',
    'name',
    # _name attribute provides result of *name_search method:
    HField('partner_id._name', name='Partner name'),
    # silent=True means, if field cannot be found, not throw error
    HField('partner_id.email', name='Partner email', silent=True),
    # Also it is posible to display result of method calls
    # 'as_html_list()' is method of RecordList.
    HField(F.order_line.as_html_list(), 'Order lines'),
    'state',
    highlighters=highlighters,
)
so_table
Out[3]:
RecordList(`sale.order`)
Note, that You may use .to_csv() method of this table to export it to CSV format
id name Partner name Partner email Order lines state
8 SO008 Millennium Industries False
  • 20: Laptop Customized
  • 21: Mouse, Wireless
draft
7 SO007 Luminous Technologies False
  • 16: Laptop E5023
  • 17: GrapWorks Software
  • 18: Datacard
  • 19: USB Adapter
manual
6 SO006 Think Big Systems [email protected]
  • 15: PC Assamble + 2GB RAM
draft
5 SO005 Agrolait [email protected]
  • 12: External Hard disk
  • 13: Blank DVD-RW
  • 14: Printer, All-in-one
draft
4 SO004 Millennium Industries False
  • 8: Service on demand
  • 9: Webcam
  • 10: Multimedia Speakers
  • 11: Switch, 24 ports
draft
3 SO003 Chamber Works [email protected]
  • 6: On Site Monitoring
  • 7: Toner Cartridge
draft
2 SO002 Bank Wealthy and sons [email protected]
  • 4: Service on demand
  • 5: On Site Assistance
draft
1 SO001 Agrolait [email protected]
  • 1: Laptop E5023
  • 2: Pen drive, 16GB
  • 3: Headset USB
sent

Find all partners and display table with partner names and their sale orders

In [4]:
partners = cl._res_partner() # Find all partners
partners_tbl = partners.as_html_table(
    (F._name, 'Name'),
    HField(F.country_id._name, 'Country', silent=True),  # silent is used to ignore exceptions
                                                         # raised while getting field
    
    # anyfield F expressions suports basic logic operations
    HField((F.sale_order_ids & 
            F.sale_order_ids.as_html_table('id',
                                          '_name',
                                          'date_order',
                                          'amount_total',
                                          'state') | 
            False),
           'Sale orders'),
)  
partners_tbl
Out[4]:
RecordList(`res.partner`)
Note, that You may use .to_csv() method of this table to export it to CSV format
Name Country Sale orders
Administrator None False
Agrolait Belgium
id _name date_order amount_total state
5 SO005 2016-03-22 4887.0 draft
1 SO001 2016-03-22 9705.0 sent
Agrolait, Michel Fletcher Belgium False
Agrolait, Thomas Passot Belgium False
ASUSTeK Taiwan False
ASUSTeK, Joseph Walters Taiwan False
ASUSTeK, Tang Tsui Taiwan False
Axelor France False
Axelor, Laith Jubair France False
Bank Wealthy and sons United Kingdom
id _name date_order amount_total state
2 SO002 2016-03-22 2947.5 draft
Bank Wealthy and sons, Charlie Bernard United Kingdom False
Bank Wealthy and sons, Jessica Dupont United Kingdom False
Best Designers India False
Best Designers, Ayaan Agarwal India False
Camptocamp France False
Camptocamp, Luc Maurer France False
Chamber Works United States
id _name date_order amount_total state
3 SO003 2016-03-22 377.5 draft
Chamber Works, Angel Cook United States False
Chamber Works, Robert Anderson United States False
China Export China False
China Export, Chao Wang China False
China Export, Zhi Ch'ang China False
Delta PC United States False
Delta PC, Brian Williams United States False
Delta PC, Paul Williams United States False
Delta PC, Richard Ellis United States False
Demo Portal User None False
Demo User None False
Elec Import United States False
Elec Import, James Miller United States False
Epic Technologies United States False
Epic Technologies, David Simpson United States False
Epic Technologies, John M. Brown United States False
Global Solutions United Kingdom False
Global Solutions, Kevin Clarke United Kingdom False
Global Solutions, Morgan Rose United Kingdom False
Global Solutions, Robin Smith United Kingdom False
Luminous Technologies Spain
id _name date_order amount_total state
7 SO007 2016-03-22 14981.0 manual
Luminous Technologies, Laura Castro Spain False
Luminous Technologies, Sergio Pérez Spain False
Mediapole Germany False
Mediapole, Phillipp Miller Germany False
Millennium Industries United Kingdom
id _name date_order amount_total state
8 SO008 2016-03-22 7315.0 draft
4 SO004 2016-03-22 2240.0 draft
Millennium Industries, Jacob Taylor United Kingdom False
Nebula Business Argentina False
Nebula Business, Benjamin Flores Argentina False
Seagate United States False
Seagate, Edward Foster United States False
Spark Systems Brazil False
Spark Systems, Arthur Gomez Brazil False
Spark Systems, Julia Rivero Brazil False
Template User None False
The Jackson Group United States False
The Jackson Group, Daniel Jackson United States False
The Jackson Group, William Thomas United States False
Think Big Systems United States
id _name date_order amount_total state
6 SO006 2016-03-22 750.0 draft
Think Big Systems, George Wilson United States False
Think Big Systems, Lucas Jones United States False
Vauxoo Venezuela False
Vauxoo, Nhomar Hernandez Venezuela False
Vicking Direct United Kingdom False
Vicking Direct, Peter Mitchell United Kingdom False
Your Company None False
Your Company (copy) None False
Your Company (copy) None False
Your Company (copy), Mark Davis None False
Your Company (copy), Mark Davis None False
Your Company (copy), Roger Scott None False
Your Company (copy), Roger Scott None False
Your Company, Mark Davis None False
Your Company, Roger Scott None False

In such way HTML Table will be displayed in console

In [5]:
from IPython.display import display_pretty
display_pretty(partners_tbl)
Name                                    Country         Sale orders
--------------------------------------  --------------  --------------------------------------------------------------
Administrator                                           False
Agrolait                                Belgium         <openerp_proxy.ext.repr.generic.HTMLTable object at 0x2c8dc10>
Agrolait, Michel Fletcher               Belgium         False
Agrolait, Thomas Passot                 Belgium         False
ASUSTeK                                 Taiwan          False
ASUSTeK, Joseph Walters                 Taiwan          False
ASUSTeK, Tang Tsui                      Taiwan          False
Axelor                                  France          False
Axelor, Laith Jubair                    France          False
Bank Wealthy and sons                   United Kingdom  <openerp_proxy.ext.repr.generic.HTMLTable object at 0x2c8db90>
Bank Wealthy and sons, Charlie Bernard  United Kingdom  False
Bank Wealthy and sons, Jessica Dupont   United Kingdom  False
Best Designers                          India           False
Best Designers, Ayaan Agarwal           India           False
Camptocamp                              France          False
Camptocamp, Luc Maurer                  France          False
Chamber Works                           United States   <openerp_proxy.ext.repr.generic.HTMLTable object at 0x2c8de10>
Chamber Works, Angel Cook               United States   False
Chamber Works, Robert Anderson          United States   False
China Export                            China           False
China Export, Chao Wang                 China           False
China Export, Zhi Ch'ang                China           False
Delta PC                                United States   False
Delta PC, Brian Williams                United States   False
Delta PC, Paul Williams                 United States   False
Delta PC, Richard Ellis                 United States   False
Demo Portal User                                        False
Demo User                                               False
Elec Import                             United States   False
Elec Import, James Miller               United States   False
Epic Technologies                       United States   False
Epic Technologies, David Simpson        United States   False
Epic Technologies, John M. Brown        United States   False
Global Solutions                        United Kingdom  False
Global Solutions, Kevin Clarke          United Kingdom  False
Global Solutions, Morgan Rose           United Kingdom  False
Global Solutions, Robin Smith           United Kingdom  False
Luminous Technologies                   Spain           <openerp_proxy.ext.repr.generic.HTMLTable object at 0x2c8ddd0>
Luminous Technologies, Laura Castro     Spain           False
Luminous Technologies, Sergio Pérez     Spain           False
Mediapole                               Germany         False
Mediapole, Phillipp Miller              Germany         False
Millennium Industries                   United Kingdom  <openerp_proxy.ext.repr.generic.HTMLTable object at 0x2c8dd50>
Millennium Industries, Jacob Taylor     United Kingdom  False
Nebula Business                         Argentina       False
Nebula Business, Benjamin Flores        Argentina       False
Seagate                                 United States   False
Seagate, Edward Foster                  United States   False
Spark Systems                           Brazil          False
Spark Systems, Arthur Gomez             Brazil          False
Spark Systems, Julia Rivero             Brazil          False
Template User                                           False
The Jackson Group                       United States   False
The Jackson Group, Daniel Jackson       United States   False
The Jackson Group, William Thomas       United States   False
Think Big Systems                       United States   <openerp_proxy.ext.repr.generic.HTMLTable object at 0x2c8dd90>
Think Big Systems, George Wilson        United States   False
Think Big Systems, Lucas Jones          United States   False
Vauxoo                                  Venezuela       False
Vauxoo, Nhomar Hernandez                Venezuela       False
Vicking Direct                          United Kingdom  False
Vicking Direct, Peter Mitchell          United Kingdom  False
Your Company                                            False
Your Company (copy)                                     False
Your Company (copy)                                     False
Your Company (copy), Mark Davis                         False
Your Company (copy), Mark Davis                         False
Your Company (copy), Roger Scott                        False
Your Company (copy), Roger Scott                        False
Your Company, Mark Davis                                False
Your Company, Roger Scott                               False

Nested tables representation

In [6]:
partners = cl._res_partner() # Find all partners
partners_tbl = partners.as_html_table(
    (F._name, 'Name'),
    HField(F.country_id._name, 'Country', silent=True),  # silent is used to ignore exceptions
                                                         # raised while getting field
    
    # anyfield F expressions suports basic logic operations
    HField((F.sale_order_ids & 
            F.sale_order_ids.as_html_table('id',
                                           HField('as_table').with_args('_name',
                                                                        'date_order',
                                                                        'amount_total',
                                                                        'state')
            ) |
            False),
           'Sale orders'),
)  
partners_tbl
Out[6]:
RecordList(`res.partner`)
Note, that You may use .to_csv() method of this table to export it to CSV format
Name Country Sale orders
Administrator None False
Agrolait Belgium
id as_table
5
Field name System name Value
_name _name SO005
date_order date_order 2016-03-22
amount_total amount_total 4887.0
state state draft
1
Field name System name Value
_name _name SO001
date_order date_order 2016-03-22
amount_total amount_total 9705.0
state state sent
Agrolait, Michel Fletcher Belgium False
Agrolait, Thomas Passot Belgium False
ASUSTeK Taiwan False
ASUSTeK, Joseph Walters Taiwan False
ASUSTeK, Tang Tsui Taiwan False
Axelor France False
Axelor, Laith Jubair France False
Bank Wealthy and sons United Kingdom
id as_table
2
Field name System name Value
_name _name SO002
date_order date_order 2016-03-22
amount_total amount_total 2947.5
state state draft
Bank Wealthy and sons, Charlie Bernard United Kingdom False
Bank Wealthy and sons, Jessica Dupont United Kingdom False
Best Designers India False
Best Designers, Ayaan Agarwal India False
Camptocamp France False
Camptocamp, Luc Maurer France False
Chamber Works United States
id as_table
3
Field name System name Value
_name _name SO003
date_order date_order 2016-03-22
amount_total amount_total 377.5
state state draft
Chamber Works, Angel Cook United States False
Chamber Works, Robert Anderson United States False
China Export China False
China Export, Chao Wang China False
China Export, Zhi Ch'ang China False
Delta PC United States False
Delta PC, Brian Williams United States False
Delta PC, Paul Williams United States False
Delta PC, Richard Ellis United States False
Demo Portal User None False
Demo User None False
Elec Import United States False
Elec Import, James Miller United States False
Epic Technologies United States False
Epic Technologies, David Simpson United States False
Epic Technologies, John M. Brown United States False
Global Solutions United Kingdom False
Global Solutions, Kevin Clarke United Kingdom False
Global Solutions, Morgan Rose United Kingdom False
Global Solutions, Robin Smith United Kingdom False
Luminous Technologies Spain
id as_table
7
Field name System name Value
_name _name SO007
date_order date_order 2016-03-22
amount_total amount_total 14981.0
state state manual
Luminous Technologies, Laura Castro Spain False
Luminous Technologies, Sergio Pérez Spain False
Mediapole Germany False
Mediapole, Phillipp Miller Germany False
Millennium Industries United Kingdom
id as_table
8
Field name System name Value
_name _name SO008
date_order date_order 2016-03-22
amount_total amount_total 7315.0
state state draft
4
Field name System name Value
_name _name SO004
date_order date_order 2016-03-22
amount_total amount_total 2240.0
state state draft
Millennium Industries, Jacob Taylor United Kingdom False
Nebula Business Argentina False
Nebula Business, Benjamin Flores Argentina False
Seagate United States False
Seagate, Edward Foster United States False
Spark Systems Brazil False
Spark Systems, Arthur Gomez Brazil False
Spark Systems, Julia Rivero Brazil False
Template User None False
The Jackson Group United States False
The Jackson Group, Daniel Jackson United States False
The Jackson Group, William Thomas United States False
Think Big Systems United States
id as_table
6
Field name System name Value
_name _name SO006
date_order date_order 2016-03-22
amount_total amount_total 750.0
state state draft
Think Big Systems, George Wilson United States False
Think Big Systems, Lucas Jones United States False
Vauxoo Venezuela False
Vauxoo, Nhomar Hernandez Venezuela False
Vicking Direct United Kingdom False
Vicking Direct, Peter Mitchell United Kingdom False
Your Company None False
Your Company (copy) None False
Your Company (copy) None False
Your Company (copy), Mark Davis None False
Your Company (copy), Mark Davis None False
Your Company (copy), Roger Scott None False
Your Company (copy), Roger Scott None False
Your Company, Mark Davis None False
Your Company, Roger Scott None False

This website does not host notebooks, it only renders notebooks available on other websites.

Delivered by Fastly, Rendered by Rackspace

nbviewer GitHub repository.

nbviewer version: aa567da

nbconvert version: 5.3.1

Rendered (Tue, 19 Feb 2019 21:49:10 UTC)