You are on page 1of 12

Open Source RAD with OpenERP 7.

0
PREAMBLE OpenERP is a modern Suite of Business Applications, released under
the AGPL license, and featuring CRM, HR, Sales, Accounting, Manufacturing,
Warehouse Management, Proect Management, and more!
"t is #ased on a modular, scala#le, and intuiti$e Rapid Application Development
(RAD) frame%or& %ritten in P'thon!
OpenERP features a complete and modular tool#o( for )uic&l' #uilding
applications* integrated Object-Relationship Mapping (ORM) support,
template+#ased Model-View-Controller (MVC) interfaces, a report generation
s'stem, automated internationali,ation, and much more!
Python is a high+le$el d'namic programming language, ideal for RAD,
com#ining po%er %ith clear s'nta(, and a core &ept small #' design!
Tip: Useful links
Main website, with OpenERP downloads: www.openerp.com
Functional & technical documentation: doc.openerp.com
Community resources: www.openerp.com/community
Continous nte!ration ser"er: runbot.openerp.com
#earnin! Python: doc.python.or!
Installing OpenERP
-penERP is distri#uted as pac&ages.installers for most platforms, #ut can also
#e installed from the source on an' platform!
OpenERP Architecture
-penERP uses the %ell+&no%n client+ser$er paradigm* the client is running as
a /a$ascript application in 'our #ro%ser, connecting to the ser$er using the
/S-0+RPC protocol o$er H11P2S3! Ad+hoc clients can also #e easil' %ritten and
connect to the ser$er using 4ML+RPC or /S-0+RPC!
Tip: Installation procedure
$he procedure %or installin! OpenERP is li&ely to e"ol"e 'dependencies and so on(, so ma&e sure to always
chec& the speci%ic documentation 'pac&a!ed & on website( %or the latest procedures. )ee
http://doc.openerp.com/"*.+/install
Package installation
Windo%s all+in+one installer
Linu(
all+in+one pac&ages a$aila#le for 5e#ian+#ased 2!de#3 and RedHat+#ased
2!rpm3 distri#utions
Mac no all+in+one installer, needs to #e installed from source
Installing from source
1here are t%o alternati$es* using a tar#all pro$ided on the %e#site, or directl'
getting the source using Ba,aar 2distri#uted Source 6ersion Control3! 7ou also
need to install the re)uired dependencies 2PostgreS8L and a fe% P'thon
li#raries 9 see documentation on doc!openerp!com3!
Compilation tip: OpenERP bein! Python,based, no compilation step is needed
Tpical !a"aar checkout proce#ure $on De!ian%!ase# &inu'(
$ sudo apt-get install bzr # Install Bazaar (version control software)
$ bzr cat -d lp:~openerp-dev/openerp-tools/trunk setups! " s! # #et Installer
$ $ake init-v%& # Install 'pen()* %&
$ $ake server # +tart 'pen()* +erver wit! e$bedded ,eb
Data!ase creation
After starting the ser$er, open !ttp://local!ost:-&./ in 'our fa$orite
#ro%ser! 7ou %ill see the 5ata#ase Manager screen %here 'ou can create a
ne% data#ase! Each data#ase has its o%n modules and config, and can #e
created in demo mode to test a pre+populated data#ase 2do not use demo
mode for a real data#ase:3
)uil#ing an OpenERP mo#ule* i#ea
C-01E41 1he code samples used in this memento are ta&en from a h'pothetical
idea module! 1he purpose of this module %ould #e to help creati$e minds, %ho
often come up %ith ideas that cannot #e pursued immediatel', and are too
easil' forgotten if not logged some%here! "t could #e used to record these
ideas, sort them and rate them!
Note: Modular development
OpenERP uses modules as %eature containers, to %oster maintainable and robust de"elopment. Modules
pro"ide %eature isolation, an appropriate le"el o% abstraction, and ob"ious M-C patterns.
+omposition of a mo#ule
A module ma' contain an' of the follo%ing elements*
business objects* declared as P'thon classes e(tending the osv.Model
class, the persistence of these resources is completel' managed #'
-penERP ;
data* 4ML.CS6 files %ith meta+data 2$ie%s and %or&flo%s declaration3,
configuration data 2modules parametri,ation3 and demo data 2optional #ut
recommended for testing, e!g! sample ideas3 ;
wizards* stateful interacti$e forms used to assist users, often a$aila#le as
conte(tual actions on resources ;
reports* RML 24ML format3, MA<- or -pen-ffice report templates, to #e
merged %ith an' &ind of #usiness data, and generate H1ML, -51 or P5=
reports!
Tpical mo#ule structure
Each module is contained in its o%n director' %ithin the server/bin/addons
director' in the ser$er installation!
Note: .ou can declare your own addons directory in the con%i!uration %ile o% OpenERP 'passed to the ser"er
with the -c option( usin! the addons_path option.
addons/
"- idea/ # 0!e $odule director1
"- de$o/ # 2e$o and unit test population data
"- i3-n/ # 0ranslation files
"- report/ # )eport definitions
"- securit1/ # 2eclaration of groups and access rig!ts
"- view/ # 4iews (for$s5lists)5 $enus and actions
"- wizard/ # ,izards definitions
"- workflow/ # ,orkflow definitions
"- 66init66p1 # *1t!on package initialization (re7uired)
"- 66openerp66p1 # $odule declaration (re7uired)
"- ideap1 # *1t!on classes5 t!e $odule8s ob9ects
1he __init__.py file is the P'thon module descriptor, #ecause an -penERP
module is also a regular P'thon module!
,,init,,.p*
# I$port all files : directories containing p1t!on code
i$port idea5 wizard5 report
1he __openerp__.py is the -penERP module manifest and contains a single
P'thon dictionar' %ith the declaration of the module* its name, dependencies,
description, and composition!
Copyright 2013 Open Object Press - All rights reserved See license on page 12 p1!12
1
2
3
"
#
$
%
&
'
10
11
12
13
1"
1#
1$
1%
1&
,,openerp,,.p*
;
8na$e8 : 8Idea85
8version8 : 83&85
8aut!or8 : 8'pen()*85
8description8 : 8Ideas $anage$ent $odule85
8categor18: 8(nterprise Innovation85
8website8: 8!ttp://wwwopenerpco$85
8depends8 : <8base8=5 # list of dependencies5 conditioning startup order
8data8 : < # data files to load at $odule install
8securit1/groups>$l85 # alwa1s load groups first?
8securit1/ir$odelaccesscsv85 # load access rig!ts after groups
8workflow/workflow>$l85
8view/views>$l85
8wizard/wizard>$l85
8report/report>$l85
=5
8de$o8: <8de$o/de$o>$l8=5 # de$o data (for unit tests)
@
O!-ect%Relational .apping Ser/ice 0 OR.
<e' component of -penERP, the -RM is a complete -#ect+Relational mapping
la'er, freeing de$elopers from ha$ing to %rite #asic S8L plum#ing! Business
o#ects are declared as P'thon classes inheriting from the osv.Model class,
%hich ma&es them magicall' persisted #' the -RM la'er!
Predefined attri#utes are used in the P'thon class to specif' a #usiness o#ect>s
characteristics for the -RM*
i#ea.p*
fro$ osv i$port osv5 fields
class idea idea(osvAodel):
6na$e B 8ideaidea8
6colu$ns B ;
8na$e8: fieldsc!ar(80itle85 sizeB.C5 re7uiredB0rue5 translateB0rue)5
8state8: fieldsselection(<(8draft8582raft8)5
(8confir$ed858Donfir$ed8)=58+tate85re7uiredB0rue5readonl1B0rue)5
# 2escription is read-onl1 w!en not draft?
8description8: fieldste>t(82escription85 readonl1B0rue5
statesB;8draft8: <(8readonl185 Ealse)=@ )5
8active8: fieldsboolean(8Fctive8)5
8invent6date8: fieldsdate(8Invent date8)5
# b1 convention5 $an1Gone fields end wit! 86id8
8inventor6id8: fields$an1Gone(8respartner858Inventor8)5
8inventor6countr16id8: fieldsrelated(8inventor6id858countr185
readonl1B0rue5 t1peB8$an1Gone85
relationB8rescountr185 stringB8Dountr18)5
# b1 convention5 HG$an1 fields end wit! 86ids8
8vote6ids8: fieldsoneG$an1(8ideavote858idea6id8584otes8)5
8sponsor6ids8: fields$an1G$an1(8respartner858idea6sponsor6rel85
8idea6id858sponsor6id858+ponsors8)5
8score8: fieldsfloat(8+core85digitsB(G53))5
8categor16id8 B $an1Gone(8ideacategor185 8Dategor18)5
@
6defaults B ;
8active8: 0rue5 # ideas are active b1 default
8state8: 8draft85 # ideas are in draft state b1 default
@
def 6c!eck6na$e(self5cr5uid5ids):
for idea in selfbrowse(cr5 uid5 ids):
if 8spa$8 in ideana$e: return Ealse # Dan8t create ideas wit! spa$?
return 0rue
6s7l6constraints B <(8na$e6uni7858uni7ue(na$e)85 8Ideas $ust be uni7ue?8)=
6constraints B <(6c!eck6na$e5 8*lease avoid spa$ in ideas ?85 <8na$e8=)=
Pre#efine# os/.os/ attri!utes for !usiness o!-ects
_name (re)*ired+ b*siness object na,e- in dot-notation (in ,od*le na,espace+
_columns (re)*ired+ dictionary ./ield na,e0/ield declaration 1
_defaults dictionary2 ./ield na,e0literal or /*nction providing de/a*lt1
6defaults<8na$e8= B la$bda self5cr5uid5conte>t: 8eggs8
_auto i/ True (de/a*lt+ the O34 5ill create the database table set
to False to create yo*r o5n table!vie5 5ithin the init() ,ethod
_inherit _name o/ the parent b*siness object (/or inheritance+
_inherits /or decoration inheritance2 dictionary ,apping the 6name o/
the parent b*siness object(s+ to the na,es o/ the corresponding
/oreign 7ey /ields to *se
Pre#efine# os/.os/ attri!utes for !usiness o!-ects
_constraints list o/ t*ples de/ining the Python constraints- in the /or,
(func_name, message, fields) (0%0+
_sql_constraints list o/ t*ples de/ining the S89 constraints- in the /or,
(name, sql_def, message) (0$'+
_log_access :/ ;r*e (de/a*lt+- " /ields (create6*id- create6date- 5rite6*id-
5rite6date+ 5ill be *sed to log record-level operations- ,ade
accessible via the perm_read() /*nction
_order <a,e o/ the /ield *sed to sort the records in lists (de/a*lt2 =id=+
_rec_name Alternative /ield to *se as na,e- *sed by name_get() (de/a*lt2
=name'+
_sql S89 code to create the table!vie5 /or this object (i/ _auto is
>alse+ can be replaced by S89 e?ec*tion in the init() ,ethod
_table S89 table na,e to *se (de/a*lt2 _name 5ith dots == replaced by
*nderscores =6=+
Inheritance mechanisms
OR. fiel# tpes
-#ects ma' contain ? t'pes of fields* simple, relational, and functional! imple
t'pes are integers, floats, #ooleans, strings, etc! Relational fields represent the
relationships #et%een o#ects 2one@man', man'@one, man'@man'3! !"nctional
fields are not stored in the data#ase #ut calculated on+the+fl' as P'thon
functions! Rele$ant e(amples in the idea class a#o$e are indicated %ith the
corresponding line num#ers 2A44,443
OR. fiel#s tpes
Common attributes supported by all fields (optional unless specified)
Copyright 2013 Open Object Press - All rights reserved See license on page 12 p2!12
1'
20
21
22
23
2"
2#
2$
2%
2&
2'
30
31
32
33
3"
3#
3$
3%
3&
3'
"0
"1
"2
"3
""
"#
"$
"%
"&
"'
#0
#1
#2
#3
#"
##
#$
#%
#&
#'
$0
$1
$2
$3
$"
$#
$$
$%
$&
$'
%0
%1
OR. fiel#s tpes
string /ield label (required)
required True i/ ,andatory
readonly True i/ not editable
help help tooltip
select True to create a
database inde? on this col*,n
conte!t dictionary 5ith conte?t*al
para,eters (/or relational /ields+
change_default ;r*e i/ /ield sho*ld be *sable
as condition /or de/a*lt val*es in clients
states dyna,ic changes to this /ield=s
co,,on attrib*tes based on the state /ield
(0"2-"$+
Simple fields
!oolean(...) integer(...) #ate(...)
#atetime(...) time(...)
8active8: fieldsboolean(8Fctive8)5
8priorit18: fieldsinteger(8*riorit18)5
8start6date8: fieldsdate(8+tart 2ate8)5
char(string,si"e,translate#$alse,..)
te't(string, translate#$alse, %)
Text-based fields
translate True i/ /ield val*es can be
translated by *sers- /or char/te!t /ields
si"e optional ,a? si@e /or char /ields
(0"1-"#+
float(string, digits#&one, ...)
Decimal value
digits t*ple (precision- scale+ (0#&+
selection(values, string, ...)
Field allowing selection among
a set of predefined values
values list o/ val*es (7ey-label t*ples+ or
/*nction ret*rning s*ch a list (required) (0"2+
!inar(string, filters#&one, ...)
Field for storing a file or binary
content.
filters optional /ilena,e /ilters /or selection
8picture8: fieldsbinar1(8*icture85
filtersB8Hpng5Hgif8)
reference(string, selection, si"e,..)
Field with dynamic relationship
to any other obect! associated
with an assistant widget
selection ,odel _name o/ allo5ed objects
types and corresponding label (sa,e /or,at as
values /or selection /ields+ (required)
si"e si@e o/ te?t col*,n *sed to store it
(storage /or,at is =model_name,ob'ect_id'+
8contact8: fieldsreference(8Dontact85<
(8respartner858*artner8)5
(8respartnercontact858Dontact8)=)
Relational fields
Common attributes supported by
relational fields
domain optional /ilter in the /or, o/
arg*,ents /or search (see search(++
man1one(ob', ondelete#'set null', %)
(0#0+
"elationship towards a parent
obect (using a foreign #ey)
ob' _name o/ destination object (required)
ondelete deletion handling- eg =set null=-
=cascade=- see PostgreS89 doc*,entation
one1man(ob', field_id, %) (0##+
$irtual relationship towards
multiple obects (inverse of
many%one)
ob' _name o/ destination object (required)
field_id /ield na,e o/ inverse ,any2one- ie
corresponding /oreign 7ey (required)
man1man(ob', rel, field(, field), %)
(0#$+
&idirectional multiple
relationship between obects
ob' _name o/ destination object (required)
rel2 optional na,e o/ relationship table to *se
(de/a*lt2 a*to-assigned based on ,odel na,es+
field( na,e o/ /ield in rel table storing the id
o/ the c*rrent object (de/a*lt2 based on ,odel+
field) na,e o/ /ield in rel table storing the id
o/ the target object (de/a*lt2 based on ,odel+
Functional fields
OR. fiel#s tpes
function(fnct, arg#&one, fnct_inv#&one, fnct_inv_arg#&one, type#'float',
fnct_search#&one, ob'#&one, store#$alse, multi#$alse,%)
Functional field simulating a real field! computed rather than stored
fnct /*nction to co,p*te the /ield val*e (required)
def fnct(self, cr, uid, ids, field_name, arg, conte!t)
ret*rns a dictionary * ids+values , 5ith val*es o/ type type
fnct_inv /*nction *sed to 5rite a val*e in the /ield instead
def fnct_inv(ob', cr, uid, id, name, value, fnct_inv_arg, conte!t)
type type o/ si,*lated /ield (can be any other type e?cept =/*nction=+
fnct_search /*nction *sed to search on this /ield
def fnct_search(ob', cr, uid, ob', name, args)
ret*rns a list o/ t*ples arg*,ents /or search()- eg -('id','in',-(,.,/0)0
ob'2 ,odel _name o/ si,*lated /ield i/ it is a relational /ield
store, multi2 opti,i@ation ,echanis,s (see *sage in Per/or,ance Section+
relate#(f(, f), %, type#'float', %) 'hortcut field e(uivalent to browsing chained fields
f(,f),... chained /ields to reach target (f1 required) (0#1+
type2 type o/ target /ield
propert(ob', type#'float', vie1_load#&one, group_name#&one, %)
Dynamic attribute with specific access rights
ob' object (required)
type2 type o/ e)*ivalent /ield

Tip: relational fields symmetry
one/many 0 many/one are symmetric
many/many 0 many/many are symmetric when in"ersed 'swap field( and field) i% e1plicit(
one/many 0 many/one 2 many/one 0 one/many 3 many/many
Special 2 Reser/e# fiel# names
A fe% field names are reser$ed for pre+defined #eha$ior in -penERP! Some of them
are created automaticall' #' the s'stem, and in that case an' field %ih that name %ill
#e ignored!
id *ni)*e syste, identi/ier /or the object
name /ield 5hose val*e is *sed to display the record in lists- etc
i/ ,issing- set _rec_name to speci/y another /ield to *se
active toggle visibility2 records 5ith active set to False are hidden by de/a*lt
sequence de/ines order and allo5s dragAdrop reordering i/ visible in list vie5s
state li/ecycle stages /or the object- *sed by the states attrib*te
parent_id de/ines tree str*ct*re on records- and enables child_of operator
parent_left-
parent_right
*sed in conj*nction 5ith _parent_store /lag on object- allo5s /aster
access to tree str*ct*res (see also )erformance *ptimi+ation section+
create_date-
create_uid-
1rite_date-
1rite_uid
*sed to log creator- last *pdater- date o/ creation and last *pdate date o/
the record disabled i/ _log_access /lag is set to False
(created by O34- do not add the,+
3orking with the OR.
"nheriting from the osv.Model class ma&es all the -RM methods a$aila#le on
#usiness o#ects! 1hese methods ma' #e in$o&ed on the self o#ect %ithin the
P'thon class itself 2see e(amples in the ta#le #elo%3, or from outside the class
#' first o#taining an instance $ia the -RM pool s'stem!
OR. usage sample
class ideaG ideaG(osvAodel):
6in!erit B 8ideaidea8
def 6score6calc(self5cr5uid5ids5field5arg5conte>tBIone):
res B ;@
# 0!is loop generates onl1 G 7ueries t!anks to browse()?
for idea in selfbrowse(cr5uid5ids5conte>tBconte>t):
su$6vote B su$(<vvote for v in ideavote6ids=)
Copyright 2013 Open Object Press - All rights reserved See license on page 12 p3!12
%2
%3
%"
%#
%$
%%
%&
avg6vote B su$6vote/len(ideavote6ids)
res<ideaid= B avg6vote
return res
6colu$ns B ;
# )eplace static score wit! average of votes
8score8:fieldsfunction(6score6calc5t1peB8float8)
@
OR. .etho#s on os/..o#el o!-ects
*'$ generic accessor
self.pool.get('ob'ect_name') ,ay be *sed to
obtain a ,odel /ro, any other
Common parameters! used by
multiple methods
cr database connection (c*rsor+
uid id o/ *ser per/or,ing the operation
ids record ids to per/or, the operation on
conte!t optional dictionary o/ conte?t*al
para,eters- eg ; 8lang8: 8en6J+85 @
search(cr, uid, domain, offset#2,
limit#&one, order#&one,
conte!t#&one, count#$alse)
"eturns, list of ids of records
matching the given criteria
domain /ilter speci/ying search criteria
offset2 optional n*,ber o/ records to s7ip
limit2 optional ,a? n*,ber o/ records to
ret*rn
order2 optional col*,ns to sort by (de/a*lt2
self._order+
count2 i/ True- ret*rns only the n*,ber o/
records ,atching the criteria- not their ids
#Operators: B5 ?B5 K5 KB5 L5 LB5 like5 ilike5
#in5 not in5 c!ild6of5 parent6left5 parent6rig!t
#Prefix operators: 8:8 (default)5 8"85 8?8
#Eetc! non-spa$ partner s!ops M partner NC
ids B selfsearc!(cr5 uid5
< '|'5 (8partner6id85 '!='5 NC)5
'!'5 (8na$e85 'ilike'5 8spa$8)5=5
orderB8partner6id8 )
create(cr, uid, values,
conte!t#&one)
Creates a new record with the
specified value
"eturns, id of the new record
values dictionary o/ /ield val*es
idea6id B selfcreate(cr5 uid5
; 8na$e8: 8+pa$ recipe85
8description8 : 8spa$ : eggs85
8inventor6id8: CO5
@)
rea#(cr, uid, ids, fields#&one,
conte!t#&one)
"eturns, list of dictionaries with
re(uested field values
fields optional list o/ /ield na,es to ret*rn
(de/a*lt2 all /ields+
results B selfread(cr5 uid5 <CG5CN=5
<8na$e85 8inventor6id8=)
print 8Inventor:85 results<&=<8inventor6id8=
rea#,group(cr, uid, domain, fields,
groupby, offset#2, limit#&one,
orderby#&one, conte!t#&one)
"eturns, list of dictionaries with
re(uested field values! grouped
by given groupby field(s).
domain2 search /ilter (see search()+
fields list o/ /ield na,es to read
groupby2 /ield or list o/ /ields to gro*p by
offset, limit2 see search()
orderby2 optional ordering /or the res*lts
K print selfread6group(cr5uid5<=5
<8score8=5 <8inventor6id8=)
<;8inventor6id8: (35 8Fd$inistrator8)5
8score8: GN5 # aggregated score
8inventor6id6count8: 3G5 # group count
@5
;8inventor6id8: (N5 82e$o8)5
8score8: 3N5
8inventor6id6count8: %5
@=
write(cr, uid, ids, values, conte!t#&one)
-pdates records with given ids
with the given values.
"eturns, True
values dictionary o/ /ield val*es to *pdate
selfwrite(cr5 uid5 <CG5CN=5
; 8na$e8: 8spa$ : eggs85
8partner6id8: GC5
@)
cop(cr, uid, id, defaults,conte!t#&one)
Duplicates record with given id
updating it with de/a*lts values.
"eturns, True
defaults dictionary o/ /ield val*es to ,odi/y
in the copied val*es 5hen creating the
d*plicated object
OR. .etho#s on os/..o#el o!-ects
unlink(cr, uid, ids, conte!t#&one)
Deletes records with the given ids
"eturns, True
selfunlink(cr5 uid5 <CG5CN=)
!rowse(cr, uid, ids, conte!t#&one)
Fetches records as obects!
allowing to use dot-notation to
browse fields and relations
"eturns, obect or list of obects
re(uested
idea B selfbrowse(cr5 uid5 CG)
print 8Idea description:85 ideadescription
print 8Inventor countr1 code:85
ideainventor6idaddress<&=countr16idcode
for vote in ideavote6ids:
print 84ote PGGf8 P votevote
#efault,get(cr, uid, fields,
conte!t#&one)
"eturns, a dictionary of the
default values for fields (set on
the obect class! by the user
preferences! or via the context)
fields list of field names
defs B selfdefault6get(cr5uid5
<8na$e858active8=)
# active s!ould be 0rue b1 default
assert defs<8active8=
perm,rea#(cr, uid, ids, details#3rue)
"eturns, a list of ownership
dictionaries for each re(uested
record
details2 i/ True- 4_uid /ields val*es are
replaced 5ith pairs (id, name_of_user)
ret*rned dictionaries contain2 object id (id+-
creator *ser id (create_uid+- creation date
(create_date+- *pdater *ser id (1rite_uid+-
*pdate date (1rite_date+
per$s B selfper$6read(cr5uid5<CG5CN=)
print 8creator:85 per$s<&=get(8create6uid85 8n/a8)
fiel#s,get(cr, uid, fields#&one,
conte!t#&one)
"eturns a dictionary of field
dictionaries! each one describing
a field of the business obect
fields list o/ /ield na,es
class idea idea(osvosv):
()
6colu$ns B ;
8na$e8 : fieldsc!ar(8Ia$e85sizeB.C)
()
def test6fields6get(self5cr5uid):
assert(selffields6get(8na$e8)<8size8= BB .C)
fiel#s,/iew,get(cr, uid,
vie1_id#&one, vie1_type#'form',
conte!t#&one, toolbar#$alse)
"eturns a dictionary describing
the composition of the re(uested
view (including inherited views)
vie1_id id o/ the vie5 or &one
vie1_type2 type o/ vie5 to ret*rn i/ vie56id
is &one (=/or,=-=tree=- B+
toolbar True to also ret*rn conte?t actions
def test6fields6view6get(self5cr5uid):
idea6ob9 B selfpoolget(8ideaidea8)
for$6view B idea6ob9fields6view6get(cr5uid)
name,get(cr, uid, ids,
conte!t#&one)
"eturns tuples with the text
representation of re(uested
obects for to-many relationships
# Ideas s!ould be s!own wit! invention date
def na$e6get(self5cr5uid5ids):
res B <=
for r in selfread(cr5uid5ids<8na$e858create6date8=)
resappend((r<8id8=5 8Ps (Ps)8 (r<8na$e8=51ear))
return res
name,search(cr, uid, name#'',
domain#&one, operator#'ili5e',
conte!t#&one, limit#62)
"eturns list of obect names
matching the criteria! used to
provide completion for to-many
relationships. .(uivalent of
search() on name / name_get()

name object na,e to search /or
operator2 operator /or na,e criterion
domain, limit2 sa,e as /or search()+
# Dountries can be searc!ed b1 code or na$e
def na$e6searc!(self5cr5uid5na$eB885
do$ainB<=5operatorB8ilike85
conte>tBIone5li$itB-&):
ids B <=
if na$e and len(na$e) BB G:
ids B selfsearc!(cr5 user5
<(8code85 8B85 na$e)= M args5
li$itBli$it5 conte>tBconte>t)
if not ids:
ids B selfsearc!(cr5 user5
<(8na$e85 operator5 na$e)= M args5
li$itBli$it5 conte>tBconte>t)
return selfna$e6get(cr5uid5ids)
Copyright 2013 Open Object Press - All rights reserved See license on page 12 p"!12
%'
&0
&1
&2
&3
&"
&#
OR. .etho#s on os/..o#el o!-ects
e'port,#ata(cr, uid, ids, fields,
conte!t#&one)
.xports fields for selected obects!
returning a dictionary with a
datas matrix. -sed when
exporting data via client menu.
fields list o/ /ield na,es
conte!t ,ay contain import_comp (de/a*lt2
False+ to ,a7e e?ported data co,patible 5ith
import_data() (,ay prevent e?porting so,e
/ields+
import,#ata(cr, uid, fields, data,
mode#'init', current_module#'',
noupdate#$alse, conte!t#&one,
filename#&one)
0mports given data in the given
module -sed when exporting data
via client menu
fields list o/ /ield na,es
data data to i,port (see e!port_data()+
mode =init= or =*pdate= /or record creation
current_module2 ,od*le na,e
noupdate /lag /or record creation
filename2 optional /ile to store partial i,port
state /or recovery
Tip: use read() throu!h webser"ice calls, but pre%er bro1se() internally
)uil#ing the mo#ule interface
1o construct a module, the main mechanism is to insert data records declaring
the module interface components! Each module element is a regular data
record* menus, $ie%s, actions, roles, access rights, etc!
+ommon 4.& structure
4ML files declared in a module>s data section contain record declarations in the
follo%ing form*
LQ>$l versionBR3&R encodingBRutf--RQK
LopenerpK
LdataK
Lrecord $odelBRob9ect6$odel6na$eR idBRob9ect6>$l6idRK
Lfield na$eBRfield3RKvalue3L/fieldK
Lfield na$eBRfieldGRKvalueGL/fieldK
L/recordK
Lrecord $odelBRob9ect6$odel6na$eGR idBRob9ect6>$l6idGRK
Lfield na$eBRfield3R refBR$oduleob9ect6>$l6idR/K
Lfield na$eBRfieldGR evalBRref(8$oduleob9ect6>$l6id8)R/K
L/recordK
L/dataK
L/openerpK
Each t'pe of record 2$ie%, menu, action3 supports a specific set of child entities
and attri#utes, #ut all share the follo%ing special attri#utes*
id the uni)ue 2per module3 e(ternal identifier of this record 2(mlBid3
ref
ma' #e used instead of normal element content to reference another record
2%or&s cross+module #' prepending the module name3
eval
used instead of element content to pro$ide $alue as a P'thon e(pression, that
can use the ref() method to find the data#ase id for a gi$en (mlBid
Tip: XML RelaN! validation
OpenERP "alidates the synta1 and structure o% 4M# %iles, accordin! to a Rela156 !rammar, %ound in
server/bin/import_!ml.rng.
For manual chec& use 1mllint: !mllint 7rela!ng /path/to/import_!ml.rng 8file9
Common CSV syntax
CS6 files can also #e added in the data section and the records %ill #e inserted
#' the -S6>s import_data() method, using the CS6 filename to determine the
target o#ect model! 1he -RM automaticall' reconnects relationships #ased on
the follo%ing special column names*
id (!ml_id) column containing identifiers for relationships
many)one_field
reconnect man'@one using name_search()
many)one_fieldid reconnect man'@one #ased on o#ect>s !ml_id
many)one_field.id
reconnect man'@one #ased on o#ect>s database id
many)many_field reconnect $ia name_search(), multiple $alues %. commas
many)many_fieldid reconnect %. o#ect>s !ml_id, multiple $alues %. commas
many)many_field.id
reconnect %. o#ect>s database id, multiple $alues %. commas
one)many_field/field creates one)many destination record and sets field $alue
ir.mo#el.access.cs/
RidR5Rna$eR5R$odel6id:idR5Rgroup6id:idR5Rper$6readR5Rper$6writeR5Rper$6createR5Rper$6unlinkR
Raccess6idea6ideaR5RideaideaR5R$odel6idea6ideaR5Rbasegroup6userR535&5&5&
Raccess6idea6voteR5RideavoteR5R$odel6idea6voteR5Rbasegroup6userR535&5&5&
.enus an# actions
Actions are declared as regular records and can #e triggered in ? %a's*
#' clic&ing on menu items lin&ed to a specific action
#' clic&ing on #uttons in $ie%s, if these are connected to actions
as conte(tual actions on an o#ect 2$isi#le in the side #ar3
Action declaration
Lrecord $odelBRiractionsact6windowR idBRaction6idRK
Lfield na$eBRna$eRKactionna$eL/fieldK
Lfield na$eBRview6idR refBRview6idR/K
Lfield na$eBRdo$ainRK<list of N-tuples ($a> GO& c!aracters)=L/fieldK
Lfield na$eBRconte>tRK;conte>t dictionar1 ($a> GO& c!aracters)@L/fieldK
Lfield na$eBRres6$odelRKob9ect$odelna$eL/fieldK
Lfield na$eBRview6t1peRKfor$"treeL/fieldK
Lfield na$eBRview6$odeRKfor$5tree5calendar5grap!L/fieldK
Lfield na$eBRtargetRKnewL/fieldK
Lfield na$eBRsearc!6view6idR refBRsearc!6view6idR/K
L/recordK
id identi/ier o/ the action in table ir.actions.act_1indo1- ,*st be *ni)*e
name action na,e (required)
view1id speci/ic vie5 to open (i/ ,issing- highest priority vie5 o/ given type is *sed+
domain t*ple (see search() arg*,ents+ /or /iltering the content o/ the vie5
context conte?t dictionary to pass to the vie5
res1model object ,odel on 5hich the vie5 to open is de/ined
view1type set to form to open records in edit ,ode- set to tree /or a hierarchy vie5 only
view1mode i/ view1type is form- list allo5ed ,odes /or vie5ing records (form! tree! +
target set to new to open the vie5 in a ne5 5indo5!pop*p
search1view1id identi/ier o/ the search vie5 to replace de/a*lt search /or, (new in version 2.3+
Menu declaration
1he menuitem element is a shortcut for declaring an ir.ui.menu record and
connect it %ith a corresponding action $ia an ir.model.data record!
L$enuite$ idBR$enu6idR parentBRparent6$enu6idR na$eBRlabelR
actionBRaction6idR groupsBRgroupna$e35groupna$eGR se7uenceBR3&R/K
id identi/ier o/ the ,en*ite,- ,*st be *ni)*e
parent e?ternal :C (?,l6id+ o/ the parent ,en* in the hierarchy
name optional ,en* label (de/a*lt2 action na,e+
action identi/ier o/ action to e?ec*te- i/ any
groups list o/ gro*ps that can see this ,en* ite, (i/ ,issing- all gro*ps can see it+
se(uence integer inde? /or ordering sibling ,en*ite,s (10-20-30+
5iews an# inheritance
6ie%s form a hierarch'! Se$eral $ie%s of the same t'pe can #e declared on the
same o#ect, and %ill #e used depending on their priorities! B' declaring an
inherited $ie% it is possi#le to add.remo$e features in a $ie%!
6eneric /iew #eclaration
Lrecord $odelBRiruiviewR idBRview6idRK
Lfield na$eBRna$eRKviewna$eL/fieldK
Lfield na$eBR$odelRKob9ect6na$eL/fieldK
L?-- t1pes: tree5for$5calendar5searc!5grap!5gantt5kanban --K
Lfield na$eBRt1peRKfor$L/fieldK
Lfield na$eBRpriorit1R evalBR3.R/K
Lfield na$eBRarc!R t1peBR>$lRK
L?-- view content: Lfor$K5 LtreeK5 Lgrap!K5 S --K
L/fieldK
L/recordK
id *ni)*e vie5 identi/ier
name vie5 na,e
model object ,odel on 5hich the vie5 is de/ined (sa,e as res1model in actions+
type vie5 type2 form- tree- graph- calendar- search! gantt! #anban
priority vie5 priority- s,aller is higher (de/a*lt2 1$+
arch architect*re o/ the vie5- see vario*s vie5 types belo5
Copyright 2013 Open Object Press - All rights reserved See license on page 12 p#!12
&%
&&
&'
'0
'1
'2
'3
'"
'#
'$
'%
'&
''
100
101
102
103
10"
10#
10$
10%
10&
10'
110
111
112
113
11"
11#
11$
11%
11&
11'
120
121
122
123
12"
12#
12$
7orms $to /iew2e#it recor#s(
=orms allo% creation.edition or resources, and correspond to 8form9 elements!
Allo5ed ele,ents all (see #orm elements below)
Lfor$ stringBRIdea for$RK
Lgroup colBR.R colspanBRCRK
Lgroup colspanBROR colBR.RK
Lfield na$eBRna$eR colspanBR.R/K
Lfield na$eBRinventor6idR/K
Lfield na$eBRinventor6countr16idR /K
Lfield na$eBRscoreR/K
L/groupK
Lgroup colspanBR3R colBRGRK
Lfield na$eBRactiveR/KLfield na$eBRinvent6dateR/K
L/groupK
L/groupK
Lnotebook colspanBRCRK
Lpage stringBR#eneralRK
Lseparator stringBR2escriptionR/K
Lfield colspanBRCR na$eBRdescriptionR nolabelBR3R/K
L/pageK
Lpage stringBR4otesRK
Lfield colspanBRCR na$eBRvote6idsR nolabelBR3RK
LtreeK
Lfield na$eBRpartner6idR/K
Lfield na$eBRvoteR/K
L/treeK
L/fieldK
L/pageK
Lpage stringBR+ponsorsRK
Lfield colspanBRCR na$eBRsponsor6idsR nolabelBR3R/K
L/pageK
L/notebookK
Lfield na$eBRstateR/K
Lbutton na$eBRdo6confir$R stringBRDonfir$R t1peBRob9ectR/K
L/for$K
Ne": t#e v$%& form '(I
7s o% OpenERP *.+ a new %orm "iew 7P has been introduced. t can be turned on by addin!
versionBT%&T to the Lfor$K element. $his new %orm 7P allows mi1in! arbitrary 48$M# code with
re!ular OpenERP %orm elements. t also introduces a %ew speci%ic elements to produce better,loo&in! %orms,
such as Ls!eetK, L!eaderK, LfooterK, and a set o% !eneral purpose C)) classes to customi9e the
appearance and beha"ior o% %orm elements. :est practices and e1amples %or the new %orm 7P are a"ailable in
the technical documentation:
!ttp://docopenerpco$/trunk/developers/server/for$-view-guidelines
7orm Elements
Co,,on attrib*tes /or all ele,ents2
string label o/ the ele,ent
nolabel2 1 to hide the /ield label
colspan2 n*,ber o/ col*,n on 5hich the /ield ,*st span
ro1span2 n*,ber o/ ro5s on 5hich the /ield ,*st span
col2 n*,ber o/ col*,n this ele,ent ,*st allocate to its child ele,ents
invisible2 4 to hide this ele,ent co,pletely
eval2 eval*ate this Python code as ele,ent content (content is string by de/a*lt+
attrs2 Python ,ap de/ining dyna,ic conditions on these attrib*tes2 readonly-
invisible- required based on search t*ples on other /ield val*es
field a*to,atic 5idgets depending on the corresponding /ield type Attrib*tes2
string label o/ the /ield /or this partic*lar vie5
nolabel2 4 to hide the /ield label
required2 override required /ield attrib*te /ro, 4odel /or this vie5
readonly2 override readonly /ield attrib*te /ro, 4odel /or this vie5
pass1ord2 True to hide characters typed in this /ield
conte!t Python code declaring a conte?t dictionary
domain2 Python code declaring list o/ t*ples /or restricting val*es
on_change2 Python ,ethod to call 5hen /ield val*e is changed
groups2 co,,a-separated list o/ gro*p (id+ allo5ed to see this /ield
1idget2 select alternative /ield 5idget (url! email! image! float1time!
reference! html! progressbar! statusbar! handle! etc.+
properties dyna,ic 5idget sho5ing all available properties (no attrib*te+
button clic7able 5idget associated 5ith actions Speci/ic attrib*tes2
type2 type o/ b*tton2 wor#flow (de/a*lt+- obect- or action
name2 5or7/lo5 signal- /*nction na,e (5itho*t parentheses+ or
action to call (depending on type+
confirm2 te?t o/ con/ir,ation ,essage 5hen clic7ed
states2 co,,a-separated list o/ states in 5hich this b*tton is sho5n
separator hori@ontal separator line /or str*ct*ring vie5s- 5ith optional label
newline place-holder /or co,pleting the c*rrent line o/ the vie5
label /ree-te?t caption or legend in the /or,
group *sed to organise /ields in gro*ps 5ith optional label (adds /ra,e+
noteboo#!
page
noteboo# ele,ents are tab containers /or page ele,ents Attrib*tes2
name2 label /or the tab!page
position2 tabs position in noteboo7 (inside! top! bottom! left! right+
Dnamic /iews
"n addition to %hat can #e done %ith states and attrs attri#utes, functions ma'
#e called #' $ie% elements 2$ia #uttons of t'pe ob'ect, or on_change triggers on
fields3 to o#tain d'namic #eha$ior! 1hese functions ma' alter the $ie%
interface #' returning a P'thon map %ith the follo%ing entries*
value a dictionary o/ /ield na,es and their ne5 val*es
domain a dictionary o/ /ield na,es and their *pdated do,ains o/ val*e
warning a dictionary 5ith a title and message to sho5 a 5arning dialog
&ists an# 8ierarchical Tree &ists
List $ie%s include #ield elements, are created %ith t'pe tree, and ha$e a 8tree9
parent element! 1he' are used to define flat lists 2edita#le or not3 and
hierarchical lists!
Attrib*tes colors2 list o/ colors or D;49 color codes ,apped to Python
conditions
editable top or bottom to allo5 in-place edit
toolbar2 set to True to display the top level o/ object
hierarchies as a side toolbar (only /or hierarchical lists- ie
opened 5ith actions that set the view6t1pe to UtreeT instead o/
U$odeT+
Allo5ed ele,ents #ield, gro"p, separator, tree, b"tton, #ilter, newline
Ltree stringBRIdea DategoriesR toolbarBR3R colorsBRblue:stateBBdraftRK
Lfield na$eBRna$eR/K
Lfield na$eBRstateR/K
L/treeK
Copyright 2013 Open Object Press - All rights reserved See license on page 12 p$!12
12%
12&
12'
130
131
132
133
13"
13#
13$
13%
13&
13'
1"0
1"1
1"2
1"3
1""
1"#
1"$
1"%
1"&
1"'
1#0
1#1
1#2
1#3
1#"
1##
1#$
1#%
1#&
1#'
1$0
1$1
1$2
9an!an )oar#s
As of -penERP C!D a ne% t'pe $ersatile #oard $ie%, in %hich each record is
rendered as a small E&an#an cardF! "t supports dragGdrop to manage the
lifec'cle of the &an#an cards #ased on configura#le dimensions!
<an#an $ie%s are introduced in the -penERP C!D release notes and defined
using the 8We# templating language, documented in the technical
documentation* see http*..#it!l'.DHus54t and
http*..doc!openerp!com.trun&.de$elopers.%e#.)%e#
+alen#ars
6ie%s used to displa' date fields as calendar e$ents 28calendar9 parent3
Attrib*tes
color2 na,e o/ /ield /or color seg,entation
date_start na,e o/ /ield containing event start date!ti,e
day_length length o/ a E5or7ingF day in ho*rs (de/a*lt2 &+
date_stop na,e o/ /ield containing event stop date!ti,e
or
date_delay na,e o/ /ield containing event d*ration
Allo5ed ele,ents #ield (to de#ine the label #or each calendar event)
Lcalendar stringBRIdeasR date6startBRinvent6dateR colorBRinventor6idRK
Lfield na$eBRna$eR/K
L/calendarK
6antt +harts
Bar chart t'picall' used to sho% proect schedule 28gantt9 parent element3
Attrib*tes same as 8calendar9
Allo5ed ele,ents #ield, level
level ele,ents are *sed to de/ine the Gantt chart levels- 5ith
the enclosed /ield *sed as label /or that drill-do5n level
Lgantt stringBRIdeasR date6startBRinvent6dateR colorBRinventor6idRK
Llevel ob9ectBRideaideaR linkBRidR do$ainBR<=RK
Lfield na$eBRinventor6idR/K
L/levelK
L/ganttK
+harts $6raphs(
6ie%s used to displa' statistics charts 28graph9 parent element3
Tip: charts are most use%ul with custom "iews e1tractin! ready,to,use statistics
Attrib*tes type type o/ chart2 bar- pie (de/a*lt+
orientation2 hori+ontal! vertical
Allo5ed ele,ents #ield, %ith specific #eha$ior*
/irst /ield in vie5 is H a?is- 2
nd
one is I- 3
rd
one is J
2 /ields re)*ired- 3
rd
one is optional
group attrib*te de/ines the G3OKP LI /ield (set to 1+
operator attrib*te sets the aggregation operator to *se /or
other /ields 5hen one /ield is gro*ped (:,4,44,min,ma!+
Lgrap! stringBR0otal idea score b1 InventorR t1peBRbarRK
Lfield na$eBRinventor6idR /K
Lfield na$eBRscoreR operatorBRMR/K
L/grap!K
Search /iews
Search $ie%s customi,e the search panel on top of other $ie%s!
Allo5ed ele,ents #ield, gro"p, separator, label, search, #ilter, newline, properties
filter ele,ents allo5 de/ining b*tton /or do,ain /ilters
adding a conte!t attrib*te to /ields ,a7es 5idgets that alter the
search conte?t (*se/*l /or conte?t-sensitive /ields- eg
pricelist-dependent prices+
Lsearc! stringBR+earc! IdeasRK
Lgroup colBR.R colspanBRCRK
Lfilter stringBRA1 IdeasR
do$ainBR<(8inventor6id858B85uid)=R
!elpBRA1 own ideasR/K
Lfield na$eBRna$eR/K
Lfield na$eBRdescriptionR/K
Lfield na$eBRinventor6idR/K
L?-- following conte>t field is for illustration onl1 --K
Lfield na$eBRinventor6countr16idR widgetBRselectionR
conte>tBR;8inventor6countr18: self@R/K
L/groupK
L/searc!K
5iew Inheritance
E(isting $ie%s should #e modif'ing through inherited $ie%s, ne$er directl'! An
inherited $ie% references its parent $ie% using the inherit_id field, and ma' add
or modif' e(isting elements in the $ie% #' referencing them through 4Path
e(pressions, and specif'ing the appropriate position!
Tip: 4Path re%erence can be %ound at www.w;.or!/$R/1path
position
inside2 p*t inside ,atch (de/a*lt+
replace2 replace ,atch
before2 p*t be/ore ,atch
after2 p*t a/ter ,atch
L?-- i$proved idea categories list --K
Lrecord idBRidea6categor16listGR $odelBRiruiviewRK
Lfield na$eBRna$eRKidcategor1listGL/fieldK
Lfield na$eBR$odelRKiruiviewL/fieldK
Lfield na$eBRin!erit6idR refBRid6categor16listR/K
Lfield na$eBRarc!R t1peBR>$lRK
L>pat! e>prBR/tree/field<Vna$eB8description8=R positionBRafterRK
Lfield na$eBRidea6idsR stringBRIu$ber of ideasR/K
L/>pat!K
L/fieldK
L/recordK
Reports
1here are se$eral report engines in -penERP, to produce reports from
different sources and in man' formats!
Special e(pressions used inside report templates produce d'namic data
and.or modif' the report structure at rendering time!
Custom report parsers ma' #e %ritten to support additional e(pressions!
Alternati/e Report 7ormats (see doc.openerp.com)
s(%@rml -pen-ffice D!I templates 2!s(%3 con$erted to RML %ith
s(%@rml tool, and the RML rendered in H1ML or P5=
rml RML templates rendered directl' as H1ML or P5=
(ml,(sl*rml 4ML data J 4SL*RML st'lesheets to generate RML
odt@odt -pen-ffice templates 2!odt3 used to produce directl'
-pen-ffice documents 2!odt3
E'pressions use# in OpenERP report templates
-- 8content9 00
dou#le #rac&ets content is e$aluated as a P'thon e(pression
#ased on the follo%ing e(pressions
;redefined e!pressions
ob'ects contains the list of records to print
data comes from the %i,ard launching the report
user contains the current user 2bro1se_record, as returned bro1se()3
time gi$es access to P'thon time module
repeat<n(list,'var','tag') repeats the current parent element named tag for each
o#ect in list, ma&ing the o#ect a$aila#le as var during each loop
set3ag('tag(','tag)') replaces the parent RML tag( %ith tag)
remove;arent&ode('tag') remo$es parent RML element tag
format=ang(value, digits#), date#$alse, date_time#$alse, grouping#3rue,
monetary#$alse) can #e used to format a date, time or amount according to
the locale
set=ang('lang_code') sets the current language and locale for translations
Report #eclaration
Copyright 2013 Open Object Press - All rights reserved See license on page 12 p%!12
1$3
1$"
1$#
1$$
1$%
1$&
1$'
1%0
1%1
1%2
1%3
1%"
1%#
1%$
1%%
1%&
1%'
1&0
1&1
1&2
1&3
1&"
1&#
1&$
1&%
1&&
1&'
1'0
1'1
1'2
1'3
1'"
1'#
1'$
1'%
1'&
L?-- 0!e following creates records in iractionsreport>$l $odel --K
Lreport idBRidea6reportR stringBR*rint IdeasR $odelBRideaideaR
na$eBRideareportR r$lBRidea/report/idear$lR K
L?-- Jse addons/base_report_designer/wizard/tiny_sxw2rml/tiny_sxw2rmlpy
to generate t!e )AW te$plate file fro$ a s>w te$plate --K
id *ni)*e report identi/ier
name na,e /or the report (required)
string report title (required)
model object ,odel on 5hich the report is de/ined (required)
rml! sxw! xml! xsl path to report te,plate so*rces (starting /ro, addons+- depending on report
auto set to False to *se a c*sto, parser- by s*bclassing report_s!1.rml_parse and
declaring the report as /ollo5s2
report_s!1.report_s!1(report_name, ob'ect_model,rml_path,parser#custom>lass)
header set to False to s*ppress report header (de/a*lt2 True+
groups co,,a-separated list o/ gro*ps allo5ed to vie5 this report
menu set to True to display this report in the Print ,en* (de/a*lt2 True+
#eywords speci/y report type 7ey5ord (de/a*lt2 client1print1multi+
Tip: RM# <ser 6uide: www.reportlab.com/docs/rml/pd%,user!uide.pd%
?!ample @M= report e!tract
Lstor1K
Lblock0able st1leBR0ableRK
LtrK
LtdKLpara st1leBR0itleRKIdea na$eL/paraK L/tdK
LtdKLpara st1leBR0itleRK+coreL/paraK L/tdK
L/trK
LtrK
LtdKLparaK<< repeatIn(ob9ects58o858tr8) == << ona$e ==L/paraKL/tdK
LtdKLparaK<< oscore ==L/paraKL/tdK
L/trK
L/block0ableK
L/stor1K
3orkflows
Wor&flo%s ma' #e associated %ith an' o#ect in
-penERP, and are entirel' customi,a#le!
Wor&flo%s are used to structure and manage
the life+c'cles of #usiness o#ects and
documents, and define transitions, triggers, etc!
%ith graphical tools!
Wor&flo%s, acti$ities 2nodes or actions3 and
transitions 2conditions3 are declared as 4ML
records, as usual! 1he to&ens that na$igate in
%or&flo%s are called wor$items!
3orkflow #eclaration
Wor&flo%s are declared on o#ects that possess a state field 2see the e(ample
idea class in the -RM section3
Lrecord idBRwkf6ideaR $odelBRworkflowRK
Lfield na$eBRna$eRKideabasicL/fieldK
Lfield na$eBRosvRKideaideaL/fieldK
Lfield na$eBRon6createR evalBR3R/K
L/recordK
id *ni)*e 5or7/lo5 record identi/ier
name na,e /or the 5or7/lo5 (required)
osv object ,odel on 5hich the 5or7/lo5 is de/ined (required)
on1create i/ True- a 5or7ite, is instantiated a*to,atically /or each ne5 osv record
Wor!low Acti"ities #nodes$
Lrecord idBRact6confir$edR $odelBRworkflowactivit1RK
Lfield na$eBRna$eRKconfir$edL/fieldK
Lfield na$eBRwkf6idR refBRwkf6ideaR/K
Lfield na$eBRkindRKfunctionL/fieldK
Lfield na$eBRactionRKaction6confir$ed()L/fieldK
L/recordK
id *ni)*e activity identi/ier
w#f1id parent 5or7/lo5 identi/ier
name activity node label
flow1start True to ,a7e it a =begin= node- receiving a 5or7ite, /or each 5or7/lo5 instance
flow1stop True to ,a7e it an =end= node- ter,inating the 5or7/lo5 5hen all ite,s reach it
oin1mode logical behavior o/ this node regarding inco,ing transitions2
5*"2 activate on the /irst inco,ing transition (de/a*lt+
67D2 5aits /or all inco,ing transitions to beco,e valid
split1mode logical behavior o/ this node regarding o*tgoing transitions2
5*"2 one valid transition necessary- send 5or7ite, on it (de/a*lt+
*"2 send 5or7ite,s on all valid transitions (0 or ,ore+- se)*entially
67D2 send a 5or7ite, on all valid transitions at once (/or7+
#ind type o/ action to per/or, 5hen node is activated by a transition2
dummy to per/or, no operation 5hen activated (de/a*lt+
function to invo7e a /*nction deter,ined by action
subflow to e?ec*te the s*b/lo5 5ith subflow1id- invo7ing action to deter,ine
the record id o/ the record /or 5hich the s*b/lo5 sho*ld be instantiated :/ action
ret*rns no res*lt- the 5or7ite, is deleted
stopall to ter,inate the 5or7/lo5 *pon activation
subflow1id i/ 7ind subflow- id o/ the s*b/lo5 to e?ec*te (*se ref attrib*te or search 5ith a t*ple+
action object ,ethod call- *sed i/ 7ind is function or subflow. ;his /*nction sho*ld also
*pdate the state /ield o/ the object- eg /or a function 7ind2
def action6confir$ed(self5 cr5 uid5 ids):
selfwrite(cr5 uid5 ids5 ; 8state8 : 8confir$ed8 @)
# S perfor$ ot!er tasks
return 0rue
3orkflow Transitions $e#ges(
Conditions are e$aluated in this order* roleBid, signal, condition e(pression
Lrecord idBRtrans6idea6draft6confir$edR $odelBRworkflowtransitionRK
Lfield na$eBRact6fro$R refBRact6draftR/K
Lfield na$eBRact6toR refBRact6confir$edR/K
Lfield na$eBRsignalRKbutton6confir$L/fieldK
Lfield na$eBRrole6idR refBRidea6$anagerR/K
Lfield na$eBRconditionRK3 BB 3L/fieldK
L/recordK
act1from! act1to identi/iers o/ the so*rce and destination activities
signal na,e o/ a b*tton o/ type 5or7/lo5 that triggers this transition
role1id re/erence to the role that *ser ,*st have to trigger the transition (see "oles+
condition Python e?pression that ,*st eval*ate to True /or transition to be triggered
Tip: OpenERP %eatures a !raphical wor&%low editor, a"ailable by switchin! to the =ia!ram "iew while "iewin! a
wor&%low in the )ettin!s>$echnical>?or&%lows
Securit
Access control mechanisms must #e com#ined to achie$e a coherent securit'
polic'!
6roup%!ase# access control mechanisms
Groups are created as normal records on the res.groups model, and granted
menu access $ia menu definitions! Ho%e$er e$en %ithout a menu, o#ects ma'
still #e accessi#le indirectl', so actual object%le"el permissions
2create,read,write,"nlin$3 must #e defined for groups! 1he' are usuall' inserted
$ia CS6 files inside modules! "t is also possi#le to restrict access to speci!ic
!ields on a $ie% or o#ect using the field>s groups attri#ute!
ir.mo#el.access.cs/
RidR5Rna$eR5R$odel6id:idR5Rgroup6id:idR5Rper$6readR5Rper$6writeR5Rper$6createR5Rper$6unlinkR
Raccess6idea6ideaR5RideaideaR5R$odel6idea6ideaR5Rbasegroup6userR5353535&
Raccess6idea6voteR5RideavoteR5R$odel6idea6voteR5Rbasegroup6userR5353535&
Roles
Roles are created as normal records on the res.roles model and used onl' to
condition %or&flo% transitions through transitions> role_id attri#ute!
3i"ar#s
Wi,ards descri#e stateful interacti$e sessions %ith the user through d'namic
forms! 1he' are constructed #ased on the osv0ransientAodel class and
automaticall' gar#age+collected after use! 1he'>re defined using the same AP"
and $ie%s as regular osvAodel o#ects!
3i"ar# mo#els $Transient.o#el(
fro$ osv i$port fields5osv
Copyright 2013 Open Object Press - All rights reserved See license on page 12 p&!12
1''
200
201
202
203
20"
20#
20$
20%
20&
20'
210
211
212
213
21"
21#
21$
21%
21&
21'
220
221
222
223
22"
22#
22$
22%
22&
22'
230
231
232
233
23"
23#
23$
23%
i$port dateti$e
class cleanup6wizard cleanup6wizard(osv0ransientAodel):
6na$e B 8ideacleanupwizard8
6colu$ns B ;
8idea6age8: fieldsinteger(8Fge (in da1s)8)5
@
def cleanup(self5cr5uid5ids5conte>tBIone):
idea6ob9 B selfpoolget(8ideaidea8)
for wiz in selfbrowse(cr5uid5ids):
if wizidea6age LB N:
raise osve>cept6osv(8Jser(rror858*lease select a larger age8)
li$it B dateti$edatetoda1()-dateti$eti$edelta(da1sBwizidea6age)
ids6to6del B idea6ob9searc!(cr5uid5 <(8create6date85 8L8 5
li$itstrfti$e(8PX-P$-Pd &&:&&:&&8))=5conte>tBconte>t)
idea6ob9unlink(cr5uid5ids6to6del)
return ;@
3i"ar# /iews
Wi,ards use regular $ie%s and their #uttons ma' use a special cancel attri#ute
to close the %i,ard %indo% %hen clic&ed!
Lrecord idBRwizard6idea6cleanupR $odelBRiruiviewRK
Lfield na$eBRna$eRKideacleanupwizardfor$L/fieldK
Lfield na$eBR$odelRKideacleanupwizardL/fieldK
Lfield na$eBRt1peRKfor$L/fieldK
Lfield na$eBRarc!R t1peBR>$lRK
Lfor$ stringBRIdea Dleanup ,izardRK
Llabel colspanBRCR stringBR+elect t!e age of ideas to cleanupR/K
Lfield na$eBRidea6ageR stringBRFge (da1s)R/K
Lgroup colspanBRCRK
Lbutton stringBRDancelR specialBRcancelR/K
Lbutton stringBRDleanupR na$eBRcleanupR t1peBRob9ectR/K
L/groupK
L/for$K
L/fieldK
L/recordK
3i"ar# e'ecution
Such %i,ards are launched $ia regular action records, %ith a special target field
used to open the %i,ard $ie% in a ne% %indo%!
Lrecord idBRaction6idea6cleanup6wizardR $odelBRiractionsact6windowRK
Lfield na$eBRna$eRKDleanupL/fieldK
Lfield na$eBRt1peRKiractionsact6windowL/fieldK
Lfield na$eBRres6$odelRKideacleanupwizardL/fieldK
Lfield na$eBRview6t1peRKfor$L/fieldK
Lfield na$eBRview6$odeRKfor$L/fieldK
Lfield na$eBRtargetRKnewL/fieldK
L/recordK
3e!Ser/ices 0 4.&%RP+
-penERP is accessi#le through 4ML+RPC interfaces, for %hich li#raries e(ist in
man' languages!
Pthon e'ample
i$port >$lrpclib
# define Y'+05 *')05 2B5 J+()5 *F++
url B 8!ttp://Ps:Pd/>$lrpc/co$$on8 P (Y'+05*')0)
sock B >$lrpclib+erver*ro>1(url)
uid B socklogin(2B5J+()5*F++)
print RWogged in as Ps (uid:Pd)R P (J+()5uid)
# Dreate a new idea
url B 8!ttp://Ps:Pd/>$lrpc/ob9ect8 P (Y'+05*')0)
sock B >$lrpclib+erver*ro>1(url)
args B ;
8na$e8 : 8Fnot!er idea85
8description8 : 80!is is anot!er idea of $ine85
8inventor6id8: uid5
@
idea6id B socke>ecute(2B5uid5*F++58ideaidea858create85args)
P8P e'ample
LQ
include(8>$lrpcinc8)Z // Jse p!p>$lrpc librar15 available on sourceforge
// define $Y'+05 $*')05 $2B5 $J+()5 $*F++
$client B new >$lrpc6client(R!ttp://$Y'+0:$*')0/>$lrpc/co$$onR)Z
$$sg B new >$lrpc$sg(RloginR)Z
$$sg-Kadd*ara$(new >$lrpcval($2B5 RstringR))Z
$$sg-Kadd*ara$(new >$lrpcval($J+()5 RstringR))Z
$$sg-Kadd*ara$(new >$lrpcval($*F++5 RstringR))Z
resp B $client-Ksend($$sg)Z
uid B $resp-Kvalue()-Kscalarval()
ec!o RWogged in as $J+() (uid:$uid)R
// Dreate a new idea
$arra14al B arra1(
8na$e8BKnew >$lrpcval(RFnot!er IdeaR5 RstringR) 5
8description8BKnew >$lrpcval(R0!is is anot!er idea of $ineR 5 RstringR)5
8inventor6id8BKnew >$lrpcval($uid5 RintR)5
)Z
Copyright 2013 Open Object Press - All rights reserved See license on page 12 p'!12
23&
23'
2"0
2"1
2"2
2"3
2""
2"#
2"$
2"%
2"&
2"'
2#0
2#1
2#2
2#3
2#"
2##
2#$
2#%
2#&
2#'
2$0
2$1
2$2
2$3
2$"
2$#
2$$
2$%
2$&
2$'
2%0
2%1
2%2
2%3
2%"
2%#
2%$
2%%
2%&
2%'
2&0
2&1
2&2
2&3 2&"
2&#
2&$
2&%
2&&
2&'
2'0
2'1
2'2
2'3
2'"
2'#
2'$
2'%
2'&
2''
300
301
302
303
30" 30#
30$
30%
30&
30'
310
Copyright 2013 Open Object Press - All rights reserved See license on page 12 p10!12
Performance Optimi"ation
As Enterprise Management Soft%are t'picall' has to deal %ith large amounts
of records, 'ou ma' %ant to pa' attention to the follo%ing anti-patterns, to
o#tain consistent performance*
5o not place bro1se() calls inside loops, put them #efore and access onl'
the #ro%sed o#ects inside the loop! 1he -RM %ill optimi,e the num#er of
data#ase )ueries #ased on the browsed attri#utes!
A$oid recursion on o#ect hierarchies 2o#ects %ith a parent_id
relationship3, #' adding parent_left and parent_right integer fields on 'our
o#ect, and setting _parent_store to 3rue in 'our o#ect class! 1he -RM %ill
use a modi#ied preorder tree traversal to #e a#le to perform recursi$e
operations 2e!g! child_of3 %ith data#ase )ueries in O(%) instead of O(n)
5o not use function fields lightl', especiall' if 'ou include them in tree
$ie%s! 1o optimi,e function fields, t%o mechanisms are a$aila#le*
multi* all fields sharing the same multi attri#ute $alue %ill #e computed
%ith one single call to the function, %hich should then return a
dictionar' of $alues in its values map
store* function fields %ith a store attri#ute %ill #e stored in the
data#ase, and recomputed on demand %hen the rele$ant trigger o#ects
are modified! 1he format for the trigger specification is as follo%s* store
B ;8$odel8: (6ref6fnct5 fields5 priorit1)@ 2see e(ample #elo%3
def 6get6idea6fro$6vote(self5cr5uid5ids5conte>tBIone):
res B ;@
vote6ids B selfpoolget(8ideavote8)browse(cr5uid5ids5conte>tBconte>t)
for v in vote6ids:
res<videa6idid= B 0rue # +tore t!e idea identifiers in a set
return reske1s()
def 6co$pute(self5cr5uid5ids5field6na$e5arg5conte>tBIone):
res B ;@
for idea in selfbrowse(cr5uid5ids5conte>tBconte>t):
vote6nu$ B len(ideavote6ids)
vote6su$ B su$(<vvote for v in ideavote6ids=)
res<ideaid= B ;
8vote6su$8: vote6su$5
8vote6avg8: (vote6su$/vote6nu$) if vote6nu$ else &&5
@
return res
6colu$ns B ;
# 0!ese fields are reco$puted w!enever one of t!e votes c!anges
8vote6avg8: fieldsfunction(6co$pute5 stringB84otes Fverage85
store B ;8ideavote8: (6get6idea6fro$6vote5<8vote8=53&)@5$ultiB8votes8)5
8vote6su$8: fieldsfunction(6co$pute5 stringB84otes +u$85
store B ;8ideavote8: (6get6idea6fro$6vote5<8vote8=53&)@5$ultiB8votes8)5
@
+ommunit 2 +ontri!uting
-penERP proects are hosted on Launchpad2LP3, %here all proect resources ma' #e
found* Ba,aar #ranches, #ug trac&ing, #lueprints, =A8s, etc! Create a free account
on launchpad!net to #e a#le to contri#ute!
&aunchpa# groups
Group* Members Bazaar/LP restrictions
*pen.") 8uality
Team (9openerp)
OpenM3P Core ;ea, Can ,erge and co,,it on
o//icial branches
*pen.") Drivers
(9openerp-drivers)
Selected active
co,,*nity ,e,bers
Can con/ir, b*gs and set
,ilestones on b*gs
*pen.") Community
(9openerp-community)
Open gro*p- anyone
can join
Can create co,,*nity branches
5here everyone can contrib*te
:;embers of upper groups are also members of lower groups
Copyright 2013 Open Object Press - All rights reserved See license on page 12 p11!12
311
312
313
31"
31#
31$
31%
31&
31'
320
321
322
323
32"
32#
32$
32%
32&
32'
330
331
332
333
&icense
Cop'right K @IDI+@ID? -pen -#ect Press! All rights reser$ed!
7ou ma' ta&e electronic cop' of this %or& and distri#ute it if 'ou don>t change the
content! 7ou can also print a cop' to #e read #' 'ourself onl'!
We ha$e contracts %ith different pu#lishers in different countries to sell and
distri#ute paper or electronic #ased $ersions of this %or& 2translated or not3
in #oo&stores! 1his helps to distri#ute and promote the -pen ERP product! "t
also helps us to create incenti$es to pa' contri#utors and authors %ith the
ro'alties!
5ue to this, grants to translate, modif' or sell this %or& are strictl' for#idden, unless
-penERP s!a! 2representing -pen -#ect Press3 gi$es 'ou a %ritten authori,ation for
this!
While e$er' precaution has #een ta&en in the preparation of this %or&, the pu#lisher
and the authors assume no responsi#ilit' for errors or omissions, or for damages
resulting from the use of the information contained herein!
Pu#lished #' -pen -#ect Press, Grand RosiLre, Belgium
Copyright 2013 Open Object Press - All rights reserved See license on page 12 p12!12

You might also like