際際滷

際際滷Share a Scribd company logo
Agile Business Group - www.agilebg.com - info@agilebg.com
API V8 for Dummies
Guida rapida per apprendisti programmatori di Odoo V8
Nicola Malcontenti
Agile Business Group
Agile Business Group - www.agilebg.com - info@agilebg.com
Agile Business Group & Odoo V8
 Swiss Localisation - Bank Payment File (DTA)
 Italian Localisation - VAT Registries
 Account Move Template
 VAT on payment
Agile Business Group - www.agilebg.com - info@agilebg.com
Obbiettivi delle nuove API
 Maggior facilitdi scritturaeletturadel codice
Python
 Creazione di un modulo pi湛 python-oriented:

I felds diventano dei descrittori delle classi

Programmazione pi湛 object oriented
Per agevolare il portingdei vari moduli le api V7 e V8
sono totalmente compatibili
Agile Business Group - www.agilebg.com - info@agilebg.com
Record e RecordSet
 Rimpiazzai concetti di browse_recorde
browse_record_list
 Un RecordSet 竪 una collection
 RecordSet sono le istanze di ogni classe
 Un Record 竪 un RecordSet!
Agile Business Group - www.agilebg.com - info@agilebg.com
Record e RecordSet
 si pu嘆accederee modifcarei felddel recordin
maniera diretta:
 I metodi del modulopossonoessereinvocati
direttamente su di un RecordSet
partner.name = My_Partner
print partner.name
My_Partner
#Chiamata di metodo
def my_fun(self):

some stuff

def other_stuff(self):
self.my_fun()
Agile Business Group - www.agilebg.com - info@agilebg.com
Enviroment
 NO MORE (cr,uid,ids,...,context)
 env 竪 parte del RecordSet
 Chiamate di metodo pi湛 rapide:
self.search([('is_company', '=', True)])
res.partner(7, 18, 12, 14, 17, 19, 8, 31, 26, 16)
self.search([('is_company', '=', True)], limit=1).name
'My_Partner'
#accesso a env
self.env
cursor = self._cr
self.env.cr
self.env.user
self.env['res.partner'].with_context(tz=x).create(vals)
Agile Business Group - www.agilebg.com - info@agilebg.com
Modulo Presentation Talk
Fields and Methods
Agile Business Group - www.agilebg.com - info@agilebg.com
Fields
 Fields come descriptors
della classe
 Propriet Date e Datetime:

to_string

to_string in datetime

from_string

from_string in datetime

today

now in datetime

context_today

context_timestamp in datetime
name = fields.Char(string='Name')
description = fields.Text(
'Description')
user_id = fields.Many2one(
'res.partner',
string='Supervisor')
partner_id = fields.Many2Many(
'res.partner',
string='Subscribers')
buffet = fields.Boolean('Buffet')
prize = fields.Float(
string='Ticket Prize')
state = fields.Selection([
('draft', 'Draft'),
('paid', 'Paid'),
('cancel', 'Cancelled')])
date = fields.Date(string='Date')
Agile Business Group - www.agilebg.com - info@agilebg.com
Functional Fields
 felds.functionNO
MORE!
 storelimitatoaTruee
Falseeadundecorator
dedicato sul metodo
amount_total = fields.Float(
string='Subtotal',
store=True,
readonly=True,
compute='_compute_amount')
@api.one
@api.depends('buffet', 'projector', 'prize')
def _compute_amount(self):
if self.buffet:
self.amount_total = self.prize + 4
if self.projector:
self.amount_total = self.prize + 10
Agile Business Group - www.agilebg.com - info@agilebg.com
Method and Decorators
 I Decorator sonolafrmacheidentifca il tipodi
metodo
 @api.one: il decorator ciclasui recorddel recordset,
self 竪 un record
 @api.multi: self竪il RecordSetcorrentesenza
iterazioni
 @api.model: self gli viene passato dall'esterno
Agile Business Group - www.agilebg.com - info@agilebg.com
Method and Decorators
@api.multi
def pay_amount(self):
for talk in self:
talk.state = 'paid'
@api.one
def check_availability(self):
total = self.daily_total(fields.Date.today())
if total <= self.env.user.company_id.total_daily:
self.avaible = True
else:
self.avaible = False
@api.model
def daily_total(self, today):
daily_total = 0
for talk in self:
if talk.date.to_string == today:
daily_total += talk.amount_total
return daily_total
Agile Business Group - www.agilebg.com - info@agilebg.com
Method and Decorators
 @api.onchange: nonsi dichiaranopi湛gli onchange
nelleviste, bastausarequestodecorator sopraad
un modulo
 @api.returns:questodecoratorgarantisce
l'univocit del recordset ritornato dal metodo.
@api.onchange('fieldx'):
def do_stuff(self):
if self.fieldx == x:
self.fieldy = 'toto'
@api.returns('res.partner')
def afun(self):
...
return x # a RecordSet
Agile Business Group - www.agilebg.com - info@agilebg.com
Link Utili
 https://www.odoo.com/documentation/8.0/
 https://github.com/nbessi/odoo_new_api_guideli
ne
 http://www.slideshare.net/openobject/odoo-from
-v7-to-v8-the-new-api
Agile Business Group - www.agilebg.com - info@agilebg.com
Contatti:
 nicola.malcontenti@agilebg.com
 Twitter: twitter.com/Hurrinico
 GitHub: github.com/hurrinico
Agile Business Group - www.agilebg.com - info@agilebg.com
Grazie per l'attenzione!

More Related Content

09 API V8 for Dummies

  • 1. Agile Business Group - www.agilebg.com - info@agilebg.com API V8 for Dummies Guida rapida per apprendisti programmatori di Odoo V8 Nicola Malcontenti Agile Business Group
  • 2. Agile Business Group - www.agilebg.com - info@agilebg.com Agile Business Group & Odoo V8 Swiss Localisation - Bank Payment File (DTA) Italian Localisation - VAT Registries Account Move Template VAT on payment
  • 3. Agile Business Group - www.agilebg.com - info@agilebg.com Obbiettivi delle nuove API Maggior facilitdi scritturaeletturadel codice Python Creazione di un modulo pi湛 python-oriented: I felds diventano dei descrittori delle classi Programmazione pi湛 object oriented Per agevolare il portingdei vari moduli le api V7 e V8 sono totalmente compatibili
  • 4. Agile Business Group - www.agilebg.com - info@agilebg.com Record e RecordSet Rimpiazzai concetti di browse_recorde browse_record_list Un RecordSet 竪 una collection RecordSet sono le istanze di ogni classe Un Record 竪 un RecordSet!
  • 5. Agile Business Group - www.agilebg.com - info@agilebg.com Record e RecordSet si pu嘆accederee modifcarei felddel recordin maniera diretta: I metodi del modulopossonoessereinvocati direttamente su di un RecordSet partner.name = My_Partner print partner.name My_Partner #Chiamata di metodo def my_fun(self): some stuff def other_stuff(self): self.my_fun()
  • 6. Agile Business Group - www.agilebg.com - info@agilebg.com Enviroment NO MORE (cr,uid,ids,...,context) env 竪 parte del RecordSet Chiamate di metodo pi湛 rapide: self.search([('is_company', '=', True)]) res.partner(7, 18, 12, 14, 17, 19, 8, 31, 26, 16) self.search([('is_company', '=', True)], limit=1).name 'My_Partner' #accesso a env self.env cursor = self._cr self.env.cr self.env.user self.env['res.partner'].with_context(tz=x).create(vals)
  • 7. Agile Business Group - www.agilebg.com - info@agilebg.com Modulo Presentation Talk Fields and Methods
  • 8. Agile Business Group - www.agilebg.com - info@agilebg.com Fields Fields come descriptors della classe Propriet Date e Datetime: to_string to_string in datetime from_string from_string in datetime today now in datetime context_today context_timestamp in datetime name = fields.Char(string='Name') description = fields.Text( 'Description') user_id = fields.Many2one( 'res.partner', string='Supervisor') partner_id = fields.Many2Many( 'res.partner', string='Subscribers') buffet = fields.Boolean('Buffet') prize = fields.Float( string='Ticket Prize') state = fields.Selection([ ('draft', 'Draft'), ('paid', 'Paid'), ('cancel', 'Cancelled')]) date = fields.Date(string='Date')
  • 9. Agile Business Group - www.agilebg.com - info@agilebg.com Functional Fields felds.functionNO MORE! storelimitatoaTruee Falseeadundecorator dedicato sul metodo amount_total = fields.Float( string='Subtotal', store=True, readonly=True, compute='_compute_amount') @api.one @api.depends('buffet', 'projector', 'prize') def _compute_amount(self): if self.buffet: self.amount_total = self.prize + 4 if self.projector: self.amount_total = self.prize + 10
  • 10. Agile Business Group - www.agilebg.com - info@agilebg.com Method and Decorators I Decorator sonolafrmacheidentifca il tipodi metodo @api.one: il decorator ciclasui recorddel recordset, self 竪 un record @api.multi: self竪il RecordSetcorrentesenza iterazioni @api.model: self gli viene passato dall'esterno
  • 11. Agile Business Group - www.agilebg.com - info@agilebg.com Method and Decorators @api.multi def pay_amount(self): for talk in self: talk.state = 'paid' @api.one def check_availability(self): total = self.daily_total(fields.Date.today()) if total <= self.env.user.company_id.total_daily: self.avaible = True else: self.avaible = False @api.model def daily_total(self, today): daily_total = 0 for talk in self: if talk.date.to_string == today: daily_total += talk.amount_total return daily_total
  • 12. Agile Business Group - www.agilebg.com - info@agilebg.com Method and Decorators @api.onchange: nonsi dichiaranopi湛gli onchange nelleviste, bastausarequestodecorator sopraad un modulo @api.returns:questodecoratorgarantisce l'univocit del recordset ritornato dal metodo. @api.onchange('fieldx'): def do_stuff(self): if self.fieldx == x: self.fieldy = 'toto' @api.returns('res.partner') def afun(self): ... return x # a RecordSet
  • 13. Agile Business Group - www.agilebg.com - info@agilebg.com Link Utili https://www.odoo.com/documentation/8.0/ https://github.com/nbessi/odoo_new_api_guideli ne http://www.slideshare.net/openobject/odoo-from -v7-to-v8-the-new-api
  • 14. Agile Business Group - www.agilebg.com - info@agilebg.com Contatti: nicola.malcontenti@agilebg.com Twitter: twitter.com/Hurrinico GitHub: github.com/hurrinico
  • 15. Agile Business Group - www.agilebg.com - info@agilebg.com Grazie per l'attenzione!