Skip to content

Commit 6829e80

Browse files
committed
[IMP] docome pep8, review create/read/write snippet, update raise snippet, add ref snippet
1 parent 1496167 commit 6829e80

File tree

1 file changed

+27
-29
lines changed

1 file changed

+27
-29
lines changed

snippets/python.snippets

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ snippet start
1616
# -*- coding: utf-8 -*-
1717
###############################################################################
1818
#
19-
# Module for OpenERP
20-
# Copyright (C) 2013 Akretion (http://www.akretion.com).
19+
# Module for OpenERP
20+
# Copyright (C) 2014 Akretion (http://www.akretion.com).
2121
# @author Sébastien BEAU <sebastien.beau@akretion.com>
2222
#
2323
# This program is free software: you can redistribute it and/or modify
@@ -171,11 +171,17 @@ snippet ondelete OnDelete Set Null
171171
ondelete='set null', ${1}
172172
snippet store
173173
store={
174-
'${1:Model}': (${2:get_model_ids_to_update}, [${3:fields}], ${4:Priority}),
174+
'${1:Model}': (
175+
${2:get_model_ids_to_update},
176+
[${3:fields}],
177+
${4:Priority}),
175178
},
176179
snippet store lambda
177180
store={
178-
'${1:Model}': (lambda self, cr, uid, ids, c={}: ids, [${2:fields}], ${3:Priority}),
181+
'${1:Model}': (
182+
lambda self, cr, uid, ids, c={}: ids,
183+
[${2:fields}],
184+
${3:Priority}),
179185
},
180186

181187
#
@@ -194,38 +200,26 @@ snippet func def search
194200
return res
195201
snippet func def read
196202
def read(self, cr, uid, ids, fields=None, context=None, load='_classic_read'):
197-
"""
198-
#TODO make doc string
199-
${2:Comment this}
200-
"""
201203
if context is None:
202204
context = {}
203-
res = super(${1:ClassName}, self).read(cr, uid, ids, fields, context=context)
204-
#TODO : process on result
205+
${1}
206+
res = super(${2:ClassName}, self).read(cr, uid, ids, fields, context=context)
205207
${3}
206208
return res
207209
snippet func def create
208-
def create(self, cr, uid, values, context=None):
209-
"""
210-
#TODO make doc string
211-
${2:Comment this}
212-
"""
210+
def create(self, cr, uid, vals, context=None):
213211
if context is None:
214212
context = {}
215-
#TODO : process on result
216-
id = super(${1:ClassName}, self).create(cr, uid, values, context=context)
217-
${3}
218-
return id
213+
${1}
214+
${3:record}_id = super(${2:ClassName}, self).create(cr, uid, vals, context=context)
215+
${4}
216+
return $3_id
219217
snippet func def write
220218
def write(self, cr, uid, ids, values, context=None):
221-
"""
222-
#TODO make doc string
223-
${2:Comment this}
224-
"""
225219
if context is None:
226220
context = {}
227-
#TODO : process on result
228-
res = super(${1:ClassName}, self).write(cr, uid, ids, values, context=context)
221+
${1}
222+
res = super(${2:ClassName}, self).write(cr, uid, ids, values, context=context)
229223
${3}
230224
return res
231225
snippet func def unlink
@@ -462,10 +456,10 @@ snippet . copy
462456
.copy(cr, uid, ${1:id}, ${2:default}, context=${3:context})${4}
463457
###
464458
## define exception
465-
snippet except raise osv.except_osv(title, message)
466-
raise osv.except_osv(_('${1:Error}'), _('${2:Message}'))
467-
snippet except raise wizard.except_wizard(title, message)
468-
raise wizard.except_wizard(_('${1:Error}'), _('${2:Message}'))
459+
snippet raise raise orm.except_orm(title, message)
460+
raise orm.except_orm(
461+
_('${1:Error}'),
462+
_('${2:Message}'))
469463
###
470464
## Cursor
471465
snippet cr cr.execute()
@@ -519,6 +513,10 @@ snippet log Error
519513
logger.error('${1}')
520514
snippet ctx
521515
ctx = context.copy()
516+
snippet ref
517+
__, ${1:erp_id} = self.pool['ir.model.data'].get_object_reference(
518+
cr, uid, '${2:module}', '${3:xml_id}')
519+
522520
#
523521
# Other python declaration
524522
#

0 commit comments

Comments
 (0)