# 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
so_list = cl['sale.order'].search_records([])
so_list
# 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
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
In such way HTML Table will be displayed in console
from IPython.display import display_pretty
display_pretty(partners_tbl)
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