Technical Training - Exercises

Release 6.0.RC1

OpenERP
2010-12-06

Contents
1 Configuration 1.1 Open Source RAD with OpenObject . . . . . . . . . . . . . 1.2 Installing OpenERP . . . . . . . . . . . . . . . . . . . . . . OpenERP Architecture . . . . . . . . . . . . . . . . . . . . 1.3 Package installation . . . . . . . . . . . . . . . . . . . . . . 1.4 Installing from source . . . . . . . . . . . . . . . . . . . . . Typical bazaar checkout procedure (on Debian-based Linux) 1.5 Database creation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 3 3 3 4 4 4 4 5 5 5 6 6 6 6 6 7 7 7 7 8 8 8 8 9 10 11 11 11 12

2

Build an OpenERP module 2.1 Composition of a module . . . . . . . . . . . . . . . . . . . . . . . 2.2 Module Stucture . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.3 Menus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.4 Object Service - ORM . . . . . . . . . . . . . . . . . . . . . . . . Predefined osv.osv attributes for business objects . . . . . . . . . . 2.5 ORM field types . . . . . . . . . . . . . . . . . . . . . . . . . . . . Common attributes supported by all fields (optional unless specified) Simple fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.6 Special/Reserved field names . . . . . . . . . . . . . . . . . . . . . 2.7 Actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Action declaration . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

3

Building views: basics 3.1 Generic view declaration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.2 Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Form elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Objects Relations 4.1 Relational fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Inheritance 5.1 Inheritance mechanisms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Predefined osv.osv attributes for business objects . . . . . . . . . . . . . . . . . . . . . . . . . . 5.2 View inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4

5

6

ORM Methods 6.1 Functional fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6.2 Predefined osv.osv attributes for business objects . . . . . . . . . . . . . . . . . . . . . . . . . . Advanced Views 7.1 List & Tree . . 7.2 Calendars . . . 7.3 Search views . 7.4 Gantt Charts . . 7.5 (Charts) Graphs Workflows Security 9.1 Group-based access control mechanisms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ir.model.access.csv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

12 12 13 14 14 14 15 15 15 16 17 17 17 18 18 18 18 19 19 20 21 21

7

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

8 9

10 Wizards 10.1 Wizard objects (osv_memory) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10.2 Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10.3 Wizard execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Internationalization 12 Reports 12.1 Expressions used in OpenERP report templates . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 WebServices 13.1 Python example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

2

2 Installing OpenERP OpenERP is distributed as packages/installers for most platforms. Manufacturing.. and featuring CRM. this chapter covers: building an OpenERP module and its interface. Workflows. Tip: • • • • • • Useful links Main website.openerp.Client software. so make sure to always check the specific documentation (packaged & on website) for the latest procedures. Tip: Installation procedure The procedure for installing OpenERP is likely to evolve (dependencies and so on). combining power with clear syntax. Reports. 3 .org OpenERP E-Learning platform: edu. Inventory. a report generation system. 1 Configuration 1. Accounting.openerp. WebServices. with different pieces of software acting as client and server depending on the desired configuration. Rapid Application Development (RAD) and Performance Optimization.1 Open Source RAD with OpenObject OpenERP is a modern Enterprise Management Software.openerp. released under the AGPL license. and a web interface is also accessible using any modern browser. Security aspects..com Functional & technical documentation: doc. and a core kept small by design. ideal for RAD. See http://doc. Sales.openobject.Based on a real case. automated internationalization. with OpenERP downloads: www.launchpad.com Learning Python: doc. and intuitive Rapid Application Development (RAD) framework written in Python. Views.com/install.com Community resources: www. Wizards. Project Management. Internationalization. . a modular. OpenERP provides a thick desktop client (GTK+) on all platforms. template-based Model-View-Controller (MVC) interfaces. and much more. • Python is a high-level dynamic programming language.com 1. It is based on OpenObject. OpenERP Architecture OpenERP uses the well-known client-server paradigm.python. scalable. HR.net/open-object Integration server: test. • OpenObject features a complete and modular toolbox for quickly building applications: integrated ObjectRelationship Mapping (ORM) support.openerp. but can of course be installed from the source on any platform.

py # install bazaar version control # retrieve source installer # fetch code and perform setup 1./bzr_set.5 Database creation After installation.openerp. Synaptic on Ubuntu) OR using BaZaar bzr branch lp:openerp (or openerp/trunk for the trunk version) when identified on Launchpad. Note: OpenERP being Python-based.taktik.be) Mac 1. Typical bazaar checkout procedure (on Debian-based Linux) $ sudo apt-get install bzr $ bzr branch lp:openerp $ cd openerp && python ./bzr_set.py Look online for package installers for the GTK client.1.3 Package installation Windows Linux All-in-one installer. 2. Note: Demonstration data can also be included.g. client. Each database has its own modules and configuration. no compilation step is needed. and separate installers for server. devteam. and webserver are on the website openerp-server and openerp-client packages are available via corresponding package manager (e. then cd openerp (cd trunk in the trunk version) and . using a tarball provided on the website.com). You also need to install the required dependencies (PostgreSQL and a few Python libraries .g. 4 . use File / Databases / New Database to create a new database (default super admin password is admin). From the GTK client. run the server and the client. or directly getting the source using Bazaar (distributed Source Version Control). as well as tutorials for installing the server (e.4 Installing from source There are two alternatives: 1.see documentation on doc.

py file is the Python module descriptor. 2. to be merged with any kind of business data. The __init__. Note: It is possible to declare a personal addons directory in the configuration file of OpenERP (passed to the server with the -c option) using the addons_path option 5 . MAKO or OpenOffice report templates.2 Module Stucture Each module is contained in its own directory within the server/bin/addons directory in the server installation. because an OpenERP module is also a regular Python module. the persistence of these resource is completly managed by OpenObject.osv OpenObject class. • Data : XML/CSV files with meta-data (views and workflows declaration). ODT or PDF reports. and generate HTML. often available as contextual actions on resources. configuration data (modules parametrization) and demo data (optional bu recommended for testing).2 Build an OpenERP module 2.1 Composition of a module A module can contain the following elements : • Business object : declared as Python classes extending the osv. • Wizards : stateful interactive forms used to assist users. • Reports : RML (XML format).

which makes them part of the OpenObject Model. <menuitem id="menu_id" parent="parent_menu_id" name="label" icon="icon-code" action="action_id" groups="groupname1.context: ‘eggs’ Alternative field to use as name.osv attributes for business objects _name (required) _columns (required) _defaults business object name. relational.5 ORM field types Objects may contain 3 types of fields: simple.osv class. many2one. 2. with a corresponding menu entry in OpenERP 2.4 Object Service . used by osv’s name_get() (default: ‘name’) . the Object Service (OSV) implements a complete Object-Relational mapping layer. many2many).. etc. in dot-notation (in module namespace) • context : Dictionary with contextual parameters (for relational fields) 6 .ORM Key component of OpenObject.2. Predefined osv.. Common attributes supported by all fields (optional unless specified) • string : Field label (required) • required : True if mandatory • readonly : True if not editable • help : Help tooltip • select : 1 to include in search views and optimize for list filtering (with database index) business object name. Relational fields represent the relationships between objects (one2many.Module Creation Create the empty module Open Academy.model. _rec_name . Simple types are integers.data record. strings. floats. Functional fields are not stored in the database but calculated on-the-fly as Python functions. and magically persisted by the ORM layer.ui.cr. Business objects are declared as Python classes inheriting from the osv.groupname2" sequence="10"/> Exercise 1 .uid. in dot-notation (in module namespace) dictionary {field names > object fields declarations } dictionary: { field names > functions providing defaults } _defaults[’name’] = lambda self. and functional.menu record and connect it with a corresponding action via an ir. booleans. freeing developers from having to write basic SQL plumbing...3 Menus The menuitem entity is a shortcut for declaring an ir.

digits=None.Simple fields • boolean(. id unique system identifier for the object (created by ORM.graph</field> <field name="target">new</field> <field name="search_view_id" ref="search_view_id"/> </record> 7 .) [Floating-point value with arbitrary precision and scale] – digits: tuple (precision..model.. translate=False.size. If digits is not provided. .) text(string....act_window" id="action_id"> <field name="name">action.. by clicking on menu items linked to a specific action 2.date(‘Start Date’) – ‘active’: fields.actions.. as contextual actions on an object Action declaration 1 2 3 4 5 6 7 8 9 10 11 <record model="ir.calendar..tree...7 Actions Actions are declared as regular records and can be triggered in 3 ways: 1. 2.) – ‘start_date’: fields. by clicking on buttons in views..) datetime(... 2..) date(. if missing. ...name</field> <field name="view_type">form|tree</field> <field name="view_mode">form.) integer(. etc. Exercise 2 .name</field> <field name="view_id" ref="view_id"/> <field name="domain">[list of 3-tuples (max 250 characters)]</field> <field name="context">{context dictionary (max 250 characters)}</field> <field name="res_model">object.6 Special/Reserved field names A few field names are reserved for pre-defined behavior in OpenObject. set _rec_name to specify another field to use for this purpose . if these are connected to actions 3. do not add it) name defines the value used by default to display the record in lists. and in that case any field with that name will be ignored.) [Text-based fields] – translate: True if field values can be translated by users – size: maximum size for char fields (→41.) time(.integer(‘Priority’) • char(string.45) • float(string. Some of them are created automatically by the system.... scale) (→58) .Define a class Define a new class Course in the openacademy module. it’s a float..translate=False. not a decimal type.boolean(‘Active’) – ‘priority’: fields..

.Exercise 3 . --> </field> </record> 3.Customise a view through the view editor of the web interface Create a tree view for the Course object. 3. <graph>.graph. required based on search tuples on other field values 8 . and correspond to <form> elements.search. Several views of the same type can be declared on the same object. 3 Building views: basics Exercise 1 ..gantt <field name="priority" eval="16"/> <field name="arch" type="xml"> <!-.calendar.view" id="view_id"> <field name="name">view. and will be used depending on their priorities. invisible.name</field> <field name="model">object_name</field> <field name="type">form</field> # tree.1 Generic view declaration <record model="ir.view content: <form>. displaying the name of the course and its description.. <tree>.2 Forms Forms allow creation/edition or resources.form. one should be able to 1) display a list of all the courses and 2) create/modify new courses. Form elements Common attributes for all elements : • string: label of the element • nolabel: 1 to hide the field label • colspan: number of column on which the field must span • rowspan: number of rows on which the field must span • col: number of column this element must allocate to its child elements • invisible: 1 to hide this element completely • eval: evaluate this Python code as element content (content is string by default) • attrs: Python map defining dynamic conditions on these attributes: readonly.ui.Define new menu entries Define new menu entries to access courses and sessions under the OpenAcademy menu entry. By declaring an inherited view it is possible to add/remove features in a view. Views form a hierarchy.

the name and the description of the course. bottom. right) Exercise 2 . url.g. email. many2many. reference. left. the name of the course . 4 Objects Relations 9 . Attributes: • name: label for the tab/page • position: tabs position in notebook (inside. gtk-ok) separator newline label group notebook. also for search (overrides field name) • select: 1 to show the field in normal search. Attributes: • string: label of the field. Data displayed should be: • In the tree view. float_time. containg additional information. text_html. page horizontal separator line for structuring views. image. object.Notebooks In the Course form view. 2 for advanced only • nolabel: 1 to hide the field label • required: override required field attribute • readonly: override readonly field attribute • password: True to hide characters typed in this field • context: Python code declaring a context dictionary • domain: Python code declaring list of tuples for restricting values • on_change: Python method call to trigger when value is changed • completion: 1 to enable auto-completion of values when possible • groups: comma-separated list of group (id) allowed to see this field • widget: select alternative widget (one2many_list. display the description under a tab. Specific attributes: • type: type of button: workflow (default). or action • name: workflow signal. progressbar) properties button dynamic widget showing all available properties (no attribute) clickable widget associated with actions. with optional label place-holder for completing the current line of the view free-text caption or legend in the form used to organise fields in groups with optional label (adds frame) notebook elements are tab containers for page elements.Field Automatic widgets depending on the corresponding field type. such that it will be easy to add other tabs later. text_wiki. top. • In the form view.Customise tree and form views using XML Create your own tree and form views for the Course object. Exercise 3 . function name (without parentheses) or action to call (depending on type) • confirm: text of confirmation message when clicked • states: comma-separated list of states in which this button is shown • icon: optional icon (all GTK STOCK icons e.

Relations many2one.) (→56) : Bidirectional multiple relationship between objects – obj: _name of destination object (required) – rel: relationship table to use (required) – field1: name of field in rel table storing the id of the current object (required) – field2: name of field in rel table storing the id of the target object (required) Exercise 2 .. e. field2. ‘cascade’. . corresponding foreign key (required) • many2many(obj.g. modify the Course..) (→55) : Virtual relationship towards multiple objects (inverse of many2one) – obj: _name of destination object (required) – field_id: field name of inverse many2one.Exercise 1 .. field_id. 4.Create classes Create Session and Attendee classes and add a menu item and an action to display the sessions. . one2many Using ORM field types (one2many. field1... Session and Attendee classes to reflect their relations with other objects. rel.. ondelete=’set null’.1 Relational fields • Common attributes supported by relational fields – domain: optional restriction in the form of arguments for search (see search()) • many2one(obj. see PostgreSQL documentation • one2many(obj. ‘set null’.e. i. defined as follows: 10 . many2one)..) (→50) : Relationship towards a parent object (using a foreign key) – obj: _name of destination object (required) – ondelete: deletion handling.

the name of the session and the related course.1 Inheritance mechanisms Exercise 4 .Add an inheritance mechanism Add a “Partner” class which inherits of the existing “Partner” class. the name and the responsible on the top. • In the form view. as well as the description of the course in one tab and and the related sessions in a second tab. For the Session object: • In the tree view.osv attributes for business objects _inherit _inherits _name of the parent business object (for prototype inheritance) for multiple / instance inheritance mechanism: dictionary mapping the _name of the parent business objects to the names of the corresponding foreign key fields to use 11 . 5 Inheritance 5.Modify the views Modify the tree and form views for the Course object and create these views for the Session object. try to arrange the form views in such a way that information looks clear. all the fields of the Session object. for the Course object: • In the tree view. the name of the course and the responsible for that course. Since the amount of data to display is quite large. Data displayed should be. • In the form view. Predefined osv.Exercise 3 .

1 Functional fields function(fnct. computed rather than stored • fnct [function to compute the field value (required)] – def fnct(self.org/TR/xpath <!-. arg=None.list2</field> <field name="model">ir. cr.domain Add a mechanism allowing the Session form view to allow the user to choose the instructor only among the partners the “Instructor” field of which is set to “True”. An inherited view references its parent view using the inherit_id field.domain We now decide to create new categories among the partners: Teacher/Teacher Level 1 and Teacher/Teacher Level 2.) : Functional field simulating a real field. multi=False. .ui. specifying the appropriate position. Exercise 3 .w3. position • inside: placed inside match (default) • before: placed before match • replace: replace match • after: placed after match Tip: XPath reference can be found at www. fnct_inv=None. never directly.2 View inheritance Existing views should be modifying through inherited views.Add an inheritance mechanism Using class inheritance. field_name. Using views inheritance. arg.ui. and may add or modify existing elements in the view by referencing them through XPath expressions. fnct_inv_arg=None. store=False.view</field> <field name="inherit_id" ref="id_category_list"/> <field name="arch" type="xml"> <xpath expr="/tree/field[@name=’description’]" position="after"> <field name="idea_ids" string="Number of ideas"/> </xpath> </field> </record> Exercise 1 .improved idea categories list --> <record id="idea_category_list2" model="ir.5. Modify the domain defined in the previous exercise to allow the user to choose the instructor among the partners the “Instructor” field of which is set to “True” or those who are in one of the categories we defined.. ids.. modify the existing partners form view to display the new fields. fnct_search=None. type=’float’.category. create a “Partner” class which modifies the existing “Partner” class. context) returns a dictionary { ids→values } with values of type type 12 . Exercise 2 . method=False. 6 ORM Methods 6. obj=None.view"> <field name="name">id. uid.

) [Dynamic attribute with specific access rights] • obj : object (required) • type : type of equivalent field Exercise 1 . Exercise 4 . 6. type=’float’.) [Shortcut field equivalent to browsing chained fields] • f1. obj.. message).f2. name. id. name.Onchange methods Modify the Session form view and the Session class in such a way that the percentage of remaining seats refreshes whenever the number of available seats or the number of attendees changes. multi : optimization mechanisms (see usage in Performance Section) related(f1. f2. list of tuples defining the SQL constraints.[1. type=’float’. cr.... in the form (name. One it is done. [(‘id’.g. e. try to display it under the form of a progressbar. value. fields). fnct_inv_arg. that contains the percentage of remaining seats in a session.. sql_def.Add constraints Add a constraint which checks that the course description and the course title are not the same...osv attributes for business objects _constraints list of tuples defining the Python constraints. uid.• fnct_inv [function used to write a value in the field instead] – def fnct_inv(obj..Functional fields Add a functional field to the “Session” class.2 Predefined osv. . group_name=None. cr. message. : chained fields to reach target (f1 required) (→51) • type : type of target field property(obj.’in’. without having to save the modifications.Add an sql constraint Add an sql constraint to check that a Course has a unique name. context) • type : type of simulated field (any other type besides ‘function’) • fnct_search [function used to search on this field] – def fnct_search(obj. args) returns a list of tuples arguments for search()..5])] • obj : model _name of simulated field if it is a relational field • store. Exercise 2 .3. in the form (func_name.. uid. . . view_load=None. Display that percentage in the session tree and form views. 13 . _sql_constraints Exercise 3 .

are created with type tree. Attributes • colors: list of colors mapped to Python conditions • editable: top or bottom to allow in-place edit • toolbar: set to True to display the top level of object hierarchies as a side toolbar (example: the menu) field. and the ones lasting more than 15 days are colored red.Active objects – Default values Define the start_date default value as today.2 Calendars Views used to display date fields as calendar events (<calendar> parent).Add a duplicate option Since we added a constraint for the Course name uniqueness. Exercise 6 . Add an active field in the Session class and set the session as active by default. button.Exercise 5 . it is not possible to use the “duplicate” function anymore (Form > Duplicate). newline Allowed elements <tree string="Idea Categories" toolbar="1" colors="blue:state==draft"> <field name="name"/> <field name="state"/> </tree> Exercise 1 . Attributes • • • • • color: name of field for color segmentation date_start: name of field containing event start date/time day_length: length of a calendar day in hours (default: 8) date_stop: name of field containing event stop date/time OR date_delay: name of field containing event duration Allowed elements field (to define the label for each calendar event) 14 . group.List coloring Modify the Session tree view in such a way that sessions lasting less than 5 days are colored blue. Note: “duration” field Beware! If the “duration” field is not declared in the view. tree. That would result in an error. changing the original name into “Copy of [original name]”. Re-implement your own “copy” method which allows to duplicate the Course object. and have a <tree> parent element. the client will not be aware of its existence. 7 Advanced Views 7. filter. 7. separator.1 List & Tree Lists include field elements.

search.4 Gantt Charts Bar chart typically used to show project schedule (<gantt> parent element). group.3 Search views Search views are used to customize the search panel on top of list views. 7. filter.Gantt charts Add a Gantt Chart enabling the user to view the sessions scheduling linked to the Open Academy module. 15 .g. After defining a search view with a unique id.<calendar string="Ideas" date_start="invent_date" color="inventor_id"> <field name="name"/> </calendar> Exercise 2 . Attributes Allowed elements same as <calendar> field. level • level elements are used to define the Gantt chart levels. Make the latter selected by default. newline. with the enclosed field used as label for that drill-down level <gantt string="Ideas" date_start="invent_date" color="inventor_id"> <level object="idea. and a top-level <search> element.Search views Add a search view containing: 1) a field to search the courses based on their title and 2) a button to filter the courses of which the current user is the responsible. e. separator. properties • filter elements allow defining button for domain filters • adding a context attribute to fields makes widgets that alter the search context (useful for context-sensitive fields. add it to the action opening the list view using the search_view_id field in its declaration.Calendar view Add a Calendar view to the “Session” object enabling the user to view the events associated to the Open Academy. 7. pricelist-dependent prices) Exercise 3 . 7.5 (Charts) Graphs Views used to display statistical charts (<graph> parent element). The sessions should be grouped by instructor. Allowed elements field. and are declared with the search type.idea" link="id" domain="[]"> <field name="inventor_id"/> </level> </gantt> Exercise 4 . label.

the number of attendees under the fom of a bar chart.max) Allowed elements <graph string="Total idea score by Inventor" type="bar"> <field name="inventor_id" /> <field name="score" operator="+"/> </graph> Exercise 5 . and are entirely customizable. 3rd one is optional • group attribute defines the GROUP BY field (set to 1) • operator attribute sets the aggregation operator to use for other fields when one field is grouped (+. triggers. 8 Workflows Workflows are models associated to business objects describing the dynamics of the company. Confirmed and Done. and buttons to change the state in the Session form. for each course. and define transitions. etc. Workflows may be associated with any object in OpenERP.min. Add a (read-only) field to visualize the state. that displays.*. Exercise 1 .Attributes • type: type of chart: bar.Static Workflow Create a state attribute which will be used for defining a workflow for the “Session” object. with specific behavior: • first field in view is X axis. The valid transitions are: • Draft -> Confirmed • Confirmed -> Draft • Confirmed -> Done • Done -> Draft A sales order generates an invoice and a shipping order is an example of workflow used in Open ERP. A session can have three states: Draft (default). 3rd one is Z • 2 fields required.**.Graph view Add a Graph view for the session object. vertical field. Workflows are also used to track processes that evolve over time. pie (default) • orientation: horizontal. with 16 . Workflows are used to structure and manage the lifecycles of business objects and documents. 2nd one is Y.

write. so actual object-level permissions (create.group_user".1. Exercise 3 . They are usually inserted via CSV files inside modules.model. 9 Security Access control mechanisms must be combined to achieve a coherent security policy.vote"."base. Then create a group “OpenAcademy / SessionRead” with read access to the Session and Attendee objects. Exercise 2 .groups model.1.XML workflows Install the base_module_record module."perm_create"."model_idea_idea". create a “OpenAcademy / Manager” group. ir.group_user".graphical tools. 9.1."model_idea_vote"."perm_read". However even without a menu.Add access control through data files in your module Using a xml data file. Exercise 4 .0 Exercise 1 . It is also possible to restrict access to specific fields on a view or object using the field’s groups attribute. with no access rights defined yet (just create the empty group). activities (nodes or actions) and transitions (conditions) are declared as XML records. that you can incorporate in your module."model_id:id". Note: Workflow “on create” A workflow associated to a session is created during the creation of that session.access.idea". Transform the Session form view such that the buttons change the state in the workflow. 17 . and granted menu access via menu definitions. The tokens that navigate in workflows are called workitems.csv "id"."name".unlink) must be defined for groups. "perm_unlink" "access_idea_idea".Server actions Create server actions and modify the previous workflow in order to re-create the same behaviour as previously.Dynamic workflow editor Using the workflow editor. Use it to export the workflow created in the workflow editor into an XML file. but without using the Python methods of the Session class.1. objects may still be accessible indirectly."group_id:id". as usual.Add access control through OpenERP interface Create a new user “John Smith”. create the same workflow as the one defined earlier for the Session object.read.1 Group-based access control mechanisms Groups are created as normal records on the res."idea. There is therefore no workflow instance associated to session instances created before the definition of the workflow."base.1."idea. Exercise 2 ."perm_write".1. Workflows.0 "access_idea_vote".

Create methods Create the action_add_attendee method in the create_attendee_wizard class.Add access control through data files in your module Use a CSV file to add read. creation and deletion rights on the Course. Also add a “Cancel” button that closes the wizard window.Customise the form view Customise the form view in order to show all the fields of the class. Exercise 5 .3 Wizard execution Such wizards are launched via regular action records. 10.Add an onchange method Add an onchange method in order to display the list of existing attendees for a given session. Exercise 2 . once the session is selected. You can also create rights associated to no group. Exercise 3 .osv_memory.Define the wizard class Define the create_attendee_wizard class and implement its structure. with a special target field used to open the wizard view in a new window. write.2 Views Wizards use regular views and their buttons may use a special=”cancel” attribute to close the wizard window when clicked. Exercise 4 . Session and Attendees objects to the OpenAcademy / Manager group.Exercise 3 . 18 . Wizards make use of the osv_memory in-memory persistence to allow constructing wizards from regular business objects and views. 10.Make the wizard available through a menuitem Create a menuitem and the necessary action to use the wizard. 10 Wizards 10.1 Wizard objects (osv_memory) Wizards describe stateful interactive sessions with the user through dynamic forms. without storing them in the database. such as a read only access on Course and a read only access on Session. In-memory objects are created by extending osv. and add a button in the form view to call it. Exercise 1 .

Those reports are represented by business objects (ir. |.) # # # # # The module directory Translation files Translation Template (exported from OpenERP) French translation Brazilian Portuguese translation Tip: By default OpenERP’s POT export only extracts labels inside XML files or inside field definitions in Python code. 12 Reports Reports in OpenERP can be rendered in different ways: • Custom reports: those reports can be directly created via the client interface._ method (e. by having files named LANG.report.pot | .. then export the module terms using OpenERP’s gettext POT export feature (Administration>Translations>Export a Translation File without specifying a language). _(‘Label’) ) Exercise 1 .g. to create the module template POT file. Translations will be loaded automatically by OpenERP for all enabled languages. Developers always use English when creating a module.Bind the wizard to the context bar Bind the wizard to the context bar of the session model. Tip: The GNU gettext format (Portable Object) used by OpenERP is integrated into LaunchPad.idea.Exercise 6 .idea/ |. but any Python string can be translated this way by surrounding it with the tools. no programming required. Extra Exercise . pt. Many IDE’s have plugins or modes for editing and merging PO/POT files. and then derive the translated PO files.Wizard on multiple records Make the wizard able to add attendees to several sessions at once.po | .pt_BR.po).translate.custom) • High quality personalized reports using openreport: no programming required but you have to write 2 small XML files: – a template which indicates the data you plan to report – an XSL : RML stylesheet • Hard coded reports • OpenOffice Writer templates 19 . 11 Internationalization Each module can provide its own translations within the i18n directory.i18n/ | . or the language and country combination when they differ (e. Translate your module using the facilities provided by OpenERP.g.po or pt_BR..Translate a module Choose a second language for your OpenERP installation. making it an online collaborative translation platform.po | (.fr.po where LANG is the locale code for the language.

grouping=True. duration. Exercise 2 . Exercise 4 . date_time=False. percentage of completion. digits=2.1 Expressions used in OpenERP report templates [[ <content> ]] double brackets content is evaluated as a Python expression based on the following expressions Predefined expressions : • objects contains the list of records to print • data comes from the wizard launching the report • user contains the current user (as per browse()) • time gives access to Python time module • repeatIn(list.’tag’) repeats the current parent element named tag for each object in list. date.Create a new report Create a report for the Session object. displaying its name. responsible name and list of attendees. Exercise 3 .Install the OpenOffice plugin Install the report designer module and add the OpenOffice OpenERP plugin. percentage of completion. date.i18n Create a report for the Session object. 12. duration.RML Export the OpenOffice report to a RML file.’tag2’) replaces the parent RML tag1 with tag2 • removeParentNode(‘tag’) removes parent RML element tag • formatLang(value. add it to your module and add an action to the session object for printing the report. 20 .’var’. monetary=False) can be used to format a date. responsible name and list of attendees. displaying for each session its name.There are several report engines in OpenERP. making the object available as var during each loop • setTag(‘tag1’. date=False. time or amount according to the locale • setLang(‘lang_code’) sets the current language and locale for translations Exercise 1 . to produce reports from different sources and in many formats.

define HOST.PASS. DB. or your instructor’s).ServerProxy(url) args = { ’name’ : ’Another idea’.USER..PORT) sock = xmlrpclib. USER.’idea. for which libraries exist in many languages. This program should be display all the existing sessions and the corresponding number of seats.login(DB. ask the server to create “Session” objects. OpenERP is accessible through XML-RPC interfaces.PORT) sock = xmlrpclib. 21 .args) Exercise 1 .’create’.execute(DB.. and to create a new session for one of the courses.13 WebServices The web-service module offer a common interface for all web-services : • SOAP • XML-RPC • NET-RPC Business objects can also be accessed via the distributed object mechanism. 13.PASS) print "Logged in as %s (uid:%d)" % (USER. They can all be modified via the client interface with contextual views. PASS url = ’http://%s:%d/xmlrpc/common’ % (HOST.Add a new service to the client Write a Python program able to send XML-RPC requests to a PC running OpenERP (yours. PORT.uid. } idea_id = sock.idea’. In this case.1 Python example import xmlrpclib # .ServerProxy(url) uid = sock. ’inventor_id’: uid. ’description’ : ’This is another idea of mine’.uid) # Create a new idea url = ’http://%s:%d/xmlrpc/object’ % (HOST.

Sign up to vote on this title
UsefulNot useful