Création 2ème module OpenERP 7.0

Nous allons créer un module un peu plus complexe avec 2 objets "book" et "author".
Nous ne mettrons pas en place la traduction en français.

Le résultat à obtenir sera :
* Ecran "Author" :

* Ecran "Book":

Le module s'appelle "Mylibrary".

Voici les 4 fichiers habituels :

__init__.py :
import mylibrary

__openerp__.py :
# -*- coding: utf-8 -*-

{
    'name': 'mylibrary',
    'version': '0.1',
    'category': 'Generic Modules/Others',
    'description': """ Test creation module
    """,
    'author': 'PM',
    'depends': ['base'],
    'data': ['mylibrary_view.xml'],
    'installable': True,
    'auto_install': False,
}

mylibrary.py :
# -*- coding: utf-8 -*-

from openerp.osv import fields, osv

class mylibrary_author(osv.osv):
    _name = 'mylibrary.author'

    _rec_name='lastname'
    _columns = {
        'firstname': fields.char('FirstName',size=64),
        'lastname': fields.char('LastName',size=64),
        'book_ids': fields.one2many('mylibrary.book','author_id','Books'),
    }
mylibrary_author()

class mylibrary_book(osv.osv):
    _name = 'mylibrary.book'
    _columns = {
        'title': fields.char('Title',size=64),
        'genre': fields.char('Genre',size=64),
        'author_id': fields.many2one('mylibrary.author','Author',ondelete='cascade'),
    }

mylibrary_book() 

mylibrary_view.xml :
<?xml version="1.0" ?>

<openerp>
        <data>

    <record model="ir.ui.view" id="author_form">
        <field name="name">author.form</field>
        <field name="model">mylibrary.author</field>
        <field name="type">form</field>
        <field name="arch" type="xml">
            <form string="Author" >
                <field name="firstname"/> 
                <field name="lastname"/> 
                <notebook colspan="3">
                    <page string="Books">
                      <field name="book_ids"/>
                    </page>
                </notebook>
            </form>
        </field>
    </record>

    <record model="ir.ui.view" id="author_tree">
        <field name="name">author.tree</field>
        <field name="model">mylibrary.author</field>
        <field name="type">tree</field>
        <field name="arch" type="xml">
            <tree string="Author" >
                <field name="firstname"/>
                <field name="lastname"/>
                <field name="book_ids"/>
            </tree>
        </field>
    </record>

     <record model="ir.actions.act_window" id="action_author">
        <field name="name">Author</field>
        <field name="res_model">mylibrary.author</field>
        <field name="view_type">form</field>
        <field name="view_mode">tree,form</field>
    </record>

    <record model="ir.ui.view" id="book_form">
        <field name="name">book.form</field>
        <field name="model">mylibrary.book</field>
        <field name="type">form</field>
        <field name="arch" type="xml">
            <form string="Book" >
                <field name="title"/>
                <field name="genre"/>
                <field name="author_id"/>
            </form>
        </field>
    </record>

    <record model="ir.ui.view" id="book_tree">
        <field name="name">book.tree</field>
        <field name="model">mylibrary.book</field>
        <field name="type">tree</field>
        <field name="arch" type="xml">
            <tree string="Book" >
                <field name="title"/>
                <field name="genre"/>
                <field name="author_id"/>
            </tree>
        </field>
    </record>

    <record model="ir.actions.act_window" id="action_book">
        <field name="name">Book</field>
        <field name="res_model">mylibrary.book</field>
        <field name="view_type">form</field>
        <field name="view_mode">tree,form</field>
    </record>

    <menuitem id="mylibrary" name="Mylibrary"/>
       <menuitem name="Mylibrary" id="section_main_menu_mylibrary" parent="mylibrary" />
        <menuitem name="Authors" id="choix_author" parent="section_main_menu_mylibrary" action="action_author"/>
       <menuitem name="Books" id="choix_book" parent="section_main_menu_mylibrary" action="action_book"/>

    </data>
</openerp>

3 réflexions au sujet de « Création 2ème module OpenERP 7.0 »

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *