Your browser doesn't support the features required by impress.js, so you are presented with a simplified version of this presentation.

For the best experience please use the latest Chrome, Safari or Firefox browser.

Introduzione

Odoo History

Tiny ERP

  • 1.0 February 2005 First release GNU GPL
  • 2.0 May 2005
  • 3.0 September 2005
  • 4.0 December 2006

OpenERP

  • 5.0 April 2009
  • 6.0 January 2011 First web client GNU AGPL
  • 6.1 February 2012 First Ajax web client, discontinued GTK client
  • 7.0 December 22, 2012 Improved web client and usability

Odoo

  • 8.0 September 18, 2014 Website builder, e-commerce, point of sale and business intelligence, New API syntax
  • 9.0 October 1, 2015 Odoo Community split from Odoo Enterprise, GNU LGPL v3
  • 10.0 October 5, 2016 Removed support for old API

Come funziona Odoo

  • ORM
  • I tipi di file:
    • *.py
    • *.xml
    • *.csv
    • altri file
  • Workflows

Moduli aggiuntivi

  • l10n-italy
  • server-tools
  • web

inherit, inherits

  • inheritance
  • prototype inheritance
  • delegation

Modifiche di base

Aggiungere un campo

Due modalità di modificare Odoo:

  • Modifica da interfaccia (quando può essere utile, quando evitarla)
  • Modifica da codice

Scrittura del modulo

Modifiche di base riguardano i model e i view.

  • Creare cartella per gli Addon Custom
  • Modificare file di configurazione
  • Creare un modulo nuovo
    • Struttura modulo
      • __init__.py
      • __openerp__.py
      • models/
      • views/
      • README.rst
  • Estendere il Model
    • Nota: richiede riavvio
  • Estendere il View
    • Nota: richiede l’aggiornamento

Aggiungere e collegare una tabella

Tabella Animals:

  • Name
  • Type
  • Sex
  • Age
  • owner_id
  • owner_phone
  • active

L’esempio si può scaricare da:
https://github.com/andreinl/vet_clinic

Funzioni standard

Funzioni standard di un Model

  • create(self, values)
  • write(self, values)
  • copy(self, defaults)
  • copy_data(self, default=None)
  • unlink(self)
  • onchange_field_name(self, variable)
  • search(self, cr, uid, args, offset=0, limit=0, order=None, context=None, count=False)
    name_search(self, name, args=None, operator=’ilike’, context=None, limit=100)
  • name_get(self)
  • default_get(self, fields)
  • get_object_reference(self, cr, uid, module, xml_id)
  • browse(self, object_id)
  • La funzione “Old style”
  • Operatori del domain:
    • List of Domain operators: ! (Not), | (Or), & (And)
    • List of Term operators: ‘=’, ‘!=’, ‘<=’, ‘<’, ‘>’, ‘>=’, ‘=?’, ‘=like’, ‘=ilike’, ‘like’, ‘not like’, ‘ilike’, ‘not ilike’, ‘in’, ‘not in’, ‘child_of’

Creare / aggiornare record con le connessioni One2many (Ex: Sale Order con Sale Order Lines):

  • (0, False, { values }) link to a new record that needs to be created with the given values dictionary
  • (1, ID, { values }) update the linked record with id = ID (write values on it)
  • (2, ID) remove and delete the linked record with id = ID (calls unlink on ID, that will delete the object completely, and the link to it as well)
  • (3, ID) cut the link to the linked record with id = ID (delete the relationship between the two objects but does not delete the target object itself)
  • (4, ID) link to existing record with id = ID (adds a relationship)
  • (5) unlink all (like using (3, ID) for all linked records)
  • (6, False, [IDs]) replace the list of linked IDs (like using (5) then (4, ID) for each ID in the list of IDs)

Wizard

The most frequent reason for changing a view is the necessity to show newly created record. In this example we pass to a new view the invoice_id:

view = self.env['ir.model.data'].get_object_reference('account', 'invoice_form')
view_id = view and view[1] or False

return {
    'type': 'ir.actions.act_window',
    'name': _('Customer Invoices'),
    'res_model': 'account.invoice',
    'view_type': 'form',
    'view_mode': 'form',
    'view_id': [view_id],
    'target': 'current',
    'res_id': invoice_id,
    'context': "{'type':'out_invoice'}",
}

Debug

Debug con standard Python debugger

import pdb
pdb.set_trace()

Debug dentro PyCharm

  • Setup PyCharm Editor per eseguire e debuggare Odoo
  • Modifica file openerp/__init__.py per essere eseguito dentro PyCharm. Commentare il codice (line: 30):

      if sys.modules.get("gevent") is not None:
          evented = True

Logging

  • debug
      --log-level debug
  • debug_sql
  • debug_rpc
  • debug_rpc_answer
  • info
  • warn
  • error
  • critical

Utilizzo del JSON-RPC per testare le funzioni

Q-Web

  • Layout (Formato carta, posizione header)
  • *.css
  • Translation
  • main template

addons/sale/views/report_saleorder.xml

Apertura report da browser:

Tecniche avanzate

  • Passare una variabile dentro context
  • Impostare il valore di default