Helloworld Module

A little example how to create a new module and introduction API reference

Tryton API Reference

Install Tryont Server

pip install trytond
or
python setup.py install

Run Tryton Server

python trytond -c /etc/trytond.conf

Example configuration file in etc directory

Install Tryton client (GTK Client)

pip install trytond
or
python setup.py install

Run Tryton Client

tryton

Install module

pip install helloword (available in Pypi or hg/git repo)
or
python setup.py install
or
cp helloworld trytond/modules/
  1. Reload modules list

python trytond -c /etc/tryton -u a_module -d databasename
  1. Install module using GTK client (or website client comming soon)

Module files

- CHANGELOG
- COPYRIGHT
| doc
| - index.rst
- helloworld.py
- helloworld.xml
| icons
- __init__.py
- INSTALL
- LICENSE
| locale
| - ca_ES.po
| - es_ES.po
- MANIFEST.in
- README
- setup.py
| tests
| - __init__.py
| - test_helloworld.py
- tryton.cfg

Configuration module

tryton.cfg

[tryton]
version=2.7.0
depends:
    ir
    res
xml:
    helloworld.xml

init file

from trytond.pool import Pool
from .helloworld import *

def register():
    Pool.register(
        Hello,
        module='helloword', type_='model')

Importat register class module

helloworld.py

Class

   1 __all__ = ['Hello']
   2 
   3 class Hello():
   4     'HelloWorld'
   5     __name__ = 'helloworld.hello'

Fields

   1 from trytond.model import ModelView, ModelSQL, fields
   2 
   3 class Hello(ModelSQL, ModelView):
   4     ...
   5     name = fields.Char('Name', required=True, translate=True)

Static method

   1 @staticmethod
   2 def default_date():
   3     Date = Pool().get('ir.date')
   4     return Date.today()

Class method

   1 @classmethod
   2 def delete(cls, hellos):
   3     # Cancel before delete
   4     cls.cancel(hellos)
   5     for hello in hellos:
   6         if hello.state != 'cancel':
   7             cls.raise_user_error('delete_cancel', hello.rec_name)
   8     super(Hello, cls).delete(hellos)

Transactions

   1 @classmethod
   2 @ModelView.button
   3 @Workflow.transition('confirmed')
   4 def confirm(cls, hellos):
   5     cls.set_hello_date(hellos)
   6     cls.store_cache(hellos)

helloword.xml

You can move views (tree/form) in view directory (the file name is view id)

Views

   1 <!-- Model Form -->
   2 <record model="ir.ui.view" id="hello_view_form">
   3     <field name="model">helloword.hello</field>
   4     <field name="type">form</field>
   5     <field name="arch" type="xml">
   6         <![CDATA[
   7         <form string="Hello" col="6">
   8             <label name="name"/>
   9             <field name="name"/>
  10         </form>
  11         ]]>
  12     </field>
  13 </record>
  14 
  15 <!-- Model Tree -->
  16 <record model="ir.ui.view" id="hello_view_tree">
  17     <field name="model">helloword.hello</field>
  18     <field name="type">tree</field>
  19     <field name="arch" type="xml">
  20         <![CDATA[
  21         <tree string="Hello">
  22             <field name="name"/>
  23         </tree>
  24         ]]>
  25     </field>
  26 </record>

Menu/Action

   1 <record model="ir.action.act_window" id="act_hello_form">
   2     <field name="name">Hellos</field>
   3     <field name="res_model">helloword.hello</field>
   4 </record>
   5 
   6 <record model="ir.action.act_window.view" id="act_hello_form_view1">
   7     <field name="sequence" eval="10"/>
   8     <field name="view" ref="hello_view_tree"/>
   9     <field name="act_window" ref="act_hello_form"/>
  10 </record>
  11 <record model="ir.action.act_window.view" id="act_hello_form_view2">
  12     <field name="sequence" eval="20"/>
  13     <field name="view" ref="hello_view_form"/>
  14     <field name="act_window" ref="act_hello_form"/>
  15 </record>
  16 
  17 <menuitem parent="menu_helloword" action="act_hello_form" id="menu_hello_form"/>

Group/User

   1 <record model="res.group" id="group_helloword_admin">
   2     <field name="name">HelloWord Administration</field>
   3 </record>
   4 <record model="res.user-res.group" id="user_admin_group_helloword_admin">
   5     <field name="user" ref="res.user_admin"/>
   6     <field name="group" ref="group_helloword_admin"/>
   7 </record>

Access

   1 <record model="ir.model.access" id="access_helloword_hello">
   2     <field name="model" search="[('model', '=', 'helloword.hello')]"/>
   3     <field name="perm_read" eval="True"/>
   4     <field name="perm_write" eval="True"/>
   5     <field name="perm_create" eval="True"/>
   6     <field name="perm_delete" eval="False"/>
   7 </record>

Wizards

   1 class TranslationExportStart(ModelView):
   2     "Export translation"
   3     __name__ = 'ir.translation.export.start'
   4     #TODO fields
   5 
   6 class TranslationExportResult(ModelView):
   7     "Export translation"
   8     __name__ = 'ir.translation.export.result'
   9     #TODO fields

   1 class TranslationExport(Wizard):
   2     "Export translation"
   3     __name__ = "ir.translation.export"
   4 
   5     start = StateView('ir.translation.export.start',
   6         'ir.translation_export_start_view_form', [
   7             Button('Cancel', 'end', 'tryton-cancel'),
   8             Button('Export', 'export', 'tryton-ok', default=True),
   9             ])
  10     export = StateTransition()
  11     result = StateView('ir.translation.export.result',
  12         'ir.translation_export_result_view_form', [
  13             Button('Close', 'end', 'tryton-close'),
  14             ])
  15 
  16     def transition_export(self):
  17         #TODO get export info
  18         return 'result'
  19 
  20     def default_result(self, fields):
  21         #TODO get field
  22         return {
  23             'file': file_,
  24             }

HelloworldModule (last edited 2013-01-28 21:52:50 by resteve)

Tryton ERP es una iniciativa de NaN-tic y Zikzakmedia para la implementación y divulgación de Tryton como ERP libre para la pequeña y mediana empresa.
Se trata de una iniciativa privada que no pretende reemplazar, ni comunicar en nombre del conjunto de la comunidad de Tryton.
Creative Commons By-NC-SA

PythonNAN-ticZikzakmedia