development odoo basic
TRANSCRIPT
![Page 1: Development Odoo Basic](https://reader034.vdocuments.us/reader034/viewer/2022042512/55ab7da01a28abd3048b46b0/html5/thumbnails/1.jpg)
Development Odoo Basic
by @mario21ic
![Page 2: Development Odoo Basic](https://reader034.vdocuments.us/reader034/viewer/2022042512/55ab7da01a28abd3048b46b0/html5/thumbnails/2.jpg)
Agenda ● Introducción ● Configuración de módulos ● Creación de un módulo ● Definición de menu, action, vista ● Fundamentos básicos de objetos ● Vistas bussiness document
![Page 3: Development Odoo Basic](https://reader034.vdocuments.us/reader034/viewer/2022042512/55ab7da01a28abd3048b46b0/html5/thumbnails/3.jpg)
¿Qué es? ● ERP + CMS ● MVC ● OpenObject ● Python ● PostgreSQL ● Flexible ● OpenSource
![Page 4: Development Odoo Basic](https://reader034.vdocuments.us/reader034/viewer/2022042512/55ab7da01a28abd3048b46b0/html5/thumbnails/4.jpg)
Arquitectura
![Page 5: Development Odoo Basic](https://reader034.vdocuments.us/reader034/viewer/2022042512/55ab7da01a28abd3048b46b0/html5/thumbnails/5.jpg)
Modelo MVC • Model: todo_model.py • View: todo_view.xml • Controller: ORM y métodos
![Page 6: Development Odoo Basic](https://reader034.vdocuments.us/reader034/viewer/2022042512/55ab7da01a28abd3048b46b0/html5/thumbnails/6.jpg)
● Debian/Ubuntu derivados: Descargar de: http://nightly.odoo.com/8.0/nightly/deb/odoo_8.0.latest_all.deb $ sudo dpkg –i odoo*.deb $ sudo apt-get install -f
● RedHat/CentOS/Fedora derivados: Descargar de: http://nightly.odoo.com/8.0/nightly/rpm/odoo_8.0.latest.noarch.rpm $ sudo rpm –Uvh odoo*.rpm
Instalación - Paquetería
![Page 7: Development Odoo Basic](https://reader034.vdocuments.us/reader034/viewer/2022042512/55ab7da01a28abd3048b46b0/html5/thumbnails/7.jpg)
Instalación - Docker ● PostgreSQL:
$ docker run -d -e POSTGRES_USER=odoo -e POSTGRES_PASSWORD=odoo --name db postgres
● Odoo: $ docker run -p 127.0.0.1:8069:8069 --name odoo --link db:db -
t odoo ● Acciones:
$ docker stop|start|restart odoo
![Page 8: Development Odoo Basic](https://reader034.vdocuments.us/reader034/viewer/2022042512/55ab7da01a28abd3048b46b0/html5/thumbnails/8.jpg)
Instalación - Docker-compose web: image: odoo:8 volumes: - ./todo_app:/mnt/extra-addons/todo_app links: - db ports: - "8069:8069" db: image: postgres:latest environment: POSTGRES_USER: odoo POSTGRES_PASSWORD: odoo
Luego ejecutar: $ docker-compose up
Crear archivo: docker-compose.yml
![Page 9: Development Odoo Basic](https://reader034.vdocuments.us/reader034/viewer/2022042512/55ab7da01a28abd3048b46b0/html5/thumbnails/9.jpg)
Creating database
![Page 10: Development Odoo Basic](https://reader034.vdocuments.us/reader034/viewer/2022042512/55ab7da01a28abd3048b46b0/html5/thumbnails/10.jpg)
Quick tour
![Page 11: Development Odoo Basic](https://reader034.vdocuments.us/reader034/viewer/2022042512/55ab7da01a28abd3048b46b0/html5/thumbnails/11.jpg)
Technical features
![Page 12: Development Odoo Basic](https://reader034.vdocuments.us/reader034/viewer/2022042512/55ab7da01a28abd3048b46b0/html5/thumbnails/12.jpg)
Technical features
![Page 13: Development Odoo Basic](https://reader034.vdocuments.us/reader034/viewer/2022042512/55ab7da01a28abd3048b46b0/html5/thumbnails/13.jpg)
Estructura de un módulo nombre_modulo/ security/ ir.model.access.csv i18n/ es_PE.po submodulo/ __init__.py submodulo.py modulo_view.xml modulo.py __init__.py __openerp__.py
![Page 14: Development Odoo Basic](https://reader034.vdocuments.us/reader034/viewer/2022042512/55ab7da01a28abd3048b46b0/html5/thumbnails/14.jpg)
__openerp__.py { 'name': 'To-Do Application', 'description': 'Maneja tus tareas personales', 'author': 'taller', 'depends': [’mail'], 'application': True, }
https://www.odoo.com/documentation/8.0/reference/module.html
![Page 15: Development Odoo Basic](https://reader034.vdocuments.us/reader034/viewer/2022042512/55ab7da01a28abd3048b46b0/html5/thumbnails/15.jpg)
Actualizando lista de módulos
![Page 16: Development Odoo Basic](https://reader034.vdocuments.us/reader034/viewer/2022042512/55ab7da01a28abd3048b46b0/html5/thumbnails/16.jpg)
Instalando module
![Page 17: Development Odoo Basic](https://reader034.vdocuments.us/reader034/viewer/2022042512/55ab7da01a28abd3048b46b0/html5/thumbnails/17.jpg)
Modelo: todo_model.py # -*- coding: utf-8 -*- from openerp import models, fields class TodoTask(models.Model): _name = 'todo.task' name = fields.Char('Description', required=True) is_done = fields.Boolean('Done?') active = fields.Boolean('Active?', default=True)
![Page 18: Development Odoo Basic](https://reader034.vdocuments.us/reader034/viewer/2022042512/55ab7da01a28abd3048b46b0/html5/thumbnails/18.jpg)
Importando model • Archivo __init__.py:
from . import todo_model
![Page 19: Development Odoo Basic](https://reader034.vdocuments.us/reader034/viewer/2022042512/55ab7da01a28abd3048b46b0/html5/thumbnails/19.jpg)
Actualizando module
![Page 20: Development Odoo Basic](https://reader034.vdocuments.us/reader034/viewer/2022042512/55ab7da01a28abd3048b46b0/html5/thumbnails/20.jpg)
Campos predefinidos • id • create_date • create_uid • write_date • write_uid
![Page 21: Development Odoo Basic](https://reader034.vdocuments.us/reader034/viewer/2022042512/55ab7da01a28abd3048b46b0/html5/thumbnails/21.jpg)
View - Structure • Archivo todo_view.xml: <?xml version="1.0"?> <openerp> <data>
<!-- Data --> </data> </openerp>
![Page 22: Development Odoo Basic](https://reader034.vdocuments.us/reader034/viewer/2022042512/55ab7da01a28abd3048b46b0/html5/thumbnails/22.jpg)
View - Action • Agregamos action: <!-- Action to open To-do Task list --> <act_window id="action_todo_task" name="To-do Task" res_model="todo.task" view_mode="tree,form" />
![Page 23: Development Odoo Basic](https://reader034.vdocuments.us/reader034/viewer/2022042512/55ab7da01a28abd3048b46b0/html5/thumbnails/23.jpg)
View - Menu • Agregamos menu: <!-- Menu item to open To-do Task list --> <menuitem id="menu_todo_task" name="To-Do Tasks" parent="mail.mail_feeds" sequence="20" action="action_todo_task" />
![Page 24: Development Odoo Basic](https://reader034.vdocuments.us/reader034/viewer/2022042512/55ab7da01a28abd3048b46b0/html5/thumbnails/24.jpg)
Activando todo_view.xml • Agregar en __openerp__.py ‘data': ['todo_view.xml'],
![Page 25: Development Odoo Basic](https://reader034.vdocuments.us/reader034/viewer/2022042512/55ab7da01a28abd3048b46b0/html5/thumbnails/25.jpg)
Vista - Tree
![Page 26: Development Odoo Basic](https://reader034.vdocuments.us/reader034/viewer/2022042512/55ab7da01a28abd3048b46b0/html5/thumbnails/26.jpg)
Vista - Form
![Page 27: Development Odoo Basic](https://reader034.vdocuments.us/reader034/viewer/2022042512/55ab7da01a28abd3048b46b0/html5/thumbnails/27.jpg)
Vista - Form personalizada • Agregar el siguiente record: <record id="view_form_todo_task" model="ir.ui.view”> <field name="name">To-do Task Form</field> <field name="model">todo.task</field> <field name="arch" type="xml"> <form string="To-do Task”> <field name="name"/> <field name="is_done"/> <field name="active" readonly="1"/> </form> </field> </record>
![Page 28: Development Odoo Basic](https://reader034.vdocuments.us/reader034/viewer/2022042512/55ab7da01a28abd3048b46b0/html5/thumbnails/28.jpg)
Vista - Form personalizada • Actualizar module y crear:
![Page 29: Development Odoo Basic](https://reader034.vdocuments.us/reader034/viewer/2022042512/55ab7da01a28abd3048b46b0/html5/thumbnails/29.jpg)
Vista - Bussines document <form> <header> <!-- Buttons go here --> </header> <sheet> <!-- Content goes here --> <field name="name"/> <field name="is_done"/> </sheet> </form>
![Page 30: Development Odoo Basic](https://reader034.vdocuments.us/reader034/viewer/2022042512/55ab7da01a28abd3048b46b0/html5/thumbnails/30.jpg)
Vista - Buttons • Agregar: <header> <button name="do_toggle_done" type="object" string="Toggle Done" class="oe_highlight" /> <button name="do_clear_done" type="object" string="Clear All Done" /> </header>
![Page 31: Development Odoo Basic](https://reader034.vdocuments.us/reader034/viewer/2022042512/55ab7da01a28abd3048b46b0/html5/thumbnails/31.jpg)
Vista - Grupos <sheet> <group name="group_top”> <group name="group_left”> <field name="name"/> </group> <group name="group_right”> <field name="is_done"/> <field name="active" readonly="1"/> </group> </group> </sheet>
![Page 32: Development Odoo Basic](https://reader034.vdocuments.us/reader034/viewer/2022042512/55ab7da01a28abd3048b46b0/html5/thumbnails/32.jpg)
Vista - Bussines document • Actualizar module y crear:
![Page 33: Development Odoo Basic](https://reader034.vdocuments.us/reader034/viewer/2022042512/55ab7da01a28abd3048b46b0/html5/thumbnails/33.jpg)
Vista - List <record id="view_tree_todo_task" model="ir.ui.view”> <field name="name">To-do Task Tree</field> <field name="model">todo.task</field> <field name="arch" type="xml”> <tree colors="gray:is_done==True”> <field name="name"/> <field name="is_done"/> </tree> </field> </record>
![Page 34: Development Odoo Basic](https://reader034.vdocuments.us/reader034/viewer/2022042512/55ab7da01a28abd3048b46b0/html5/thumbnails/34.jpg)
Vista - List • Actualizar y ver:
![Page 35: Development Odoo Basic](https://reader034.vdocuments.us/reader034/viewer/2022042512/55ab7da01a28abd3048b46b0/html5/thumbnails/35.jpg)
Vista - Search <record id="view_filter_todo_task" model="ir.ui.view”> <field name="name">To-do Task Filter</field> <field name="model">todo.task</field> <field name="arch" type="xml”> <search> <field name="name"/> <filter string="Not Done" domain="[('is_done','=',False)]"/> <filter string="Done" domain="[('is_done','!=',False)]"/> </search> </field> </record>
![Page 36: Development Odoo Basic](https://reader034.vdocuments.us/reader034/viewer/2022042512/55ab7da01a28abd3048b46b0/html5/thumbnails/36.jpg)
Vista - Search • Actualizar y buscar:
![Page 37: Development Odoo Basic](https://reader034.vdocuments.us/reader034/viewer/2022042512/55ab7da01a28abd3048b46b0/html5/thumbnails/37.jpg)
Agregando lógicade negocio • Agregar al inicio de todo_model.py from openerp import models, fields, api • Y como método: @api.one def do_toggle_done(self): self.is_done = not self.is_done return True
![Page 38: Development Odoo Basic](https://reader034.vdocuments.us/reader034/viewer/2022042512/55ab7da01a28abd3048b46b0/html5/thumbnails/38.jpg)
Agregando lógica de negocio @api.multi def do_clear_done(self): done_recs = self.search([('is_done', '=', True)]) done_recs.write({'active': False}) return True
![Page 39: Development Odoo Basic](https://reader034.vdocuments.us/reader034/viewer/2022042512/55ab7da01a28abd3048b46b0/html5/thumbnails/39.jpg)
Field - Tipos básicos • Char • Boolean • Integer • Float • Text • Selection • Date / Datetime • * Computed Mas info:
https://www.odoo.com/documentation/8.0/reference/orm.html#fields
![Page 40: Development Odoo Basic](https://reader034.vdocuments.us/reader034/viewer/2022042512/55ab7da01a28abd3048b46b0/html5/thumbnails/40.jpg)
Field - Agregando un Selection • En todo_model.py agregar: level = fields.Selection(( ('0', 'Urgente'), ('1','Alto'), ('2', 'Normal')), 'Prioridad') • En todo_view.xml agregar en form y tree: <field name="level"/>
![Page 41: Development Odoo Basic](https://reader034.vdocuments.us/reader034/viewer/2022042512/55ab7da01a28abd3048b46b0/html5/thumbnails/41.jpg)
Field - Selection Actualizar module, listar y crear:
![Page 42: Development Odoo Basic](https://reader034.vdocuments.us/reader034/viewer/2022042512/55ab7da01a28abd3048b46b0/html5/thumbnails/42.jpg)
Ejercicios • Agregarle un campo de tipo fecha. • Al módulo crearle un acceso desde el menú
principal • Agregarle un campo tipo selection que sea
generado dinamicamente.