Skip to content

Commit 5fefa15

Browse files
committed
[IMP] snippet improvement
1 parent 22d9e2f commit 5fefa15

File tree

2 files changed

+44
-30
lines changed

2 files changed

+44
-30
lines changed

UltiSnips/python.snippets

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@ snippet pdb
1010
import pdb; pdb.set_trace();
1111
endsnippet
1212

13+
snippet itest
14+
from odoo.tests import SavepointCase
15+
16+
17+
class ${1}(SavepointCase):
18+
19+
@classmethod
20+
def setUpClass(cls):
21+
super().setUpClass()
22+
${2}
23+
endsnippet
24+
1325
snippet imodel
1426
from odoo import models
1527
${1}
@@ -36,8 +48,11 @@ snippet iconfig
3648
from odoo.tools import config
3749
endsnippet
3850

39-
snippet start
51+
snippet header
4052
# -*- coding: utf-8 -*-
53+
endsnippet
54+
55+
snippet start
4156
# Copyright `date +%Y` Akretion (https://www.akretion.com).
4257
# @author `git config user.name` <`git config user.email`>
4358
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
@@ -114,15 +129,18 @@ ${3}
114129
endsnippet
115130

116131
snippet ffl "float"
117-
${1:fieldname} = fields.Float(digits_compute=dp.get_precision('${2:PrecisionName}')${3})${4}
132+
${1:fieldname} = fields.Float(digits=dp.get_precision('${2:PrecisionName}')${3})
133+
${4}
118134
endsnippet
119135

120136
snippet fbo "boolean"
121-
${1:fieldname} = fields.Boolean(${2:})${3}
137+
${1:fieldname} = fields.Boolean(${2:})
138+
${3}
122139
endsnippet
123140

124141
snippet fdt "date"
125-
'${1:fieldname}': fields.date('${2:Label}', ${4}help='${3:Help note}'),${5}
142+
${1:fieldname} = fields.Date(${2})
143+
${3}
126144
endsnippet
127145

128146
snippet fdti "datetime"
@@ -226,15 +244,7 @@ translate=True, ${1}
226244
endsnippet
227245

228246
snippet dp
229-
digits_compute=dp.get_precision('${1:PrecisionName}'), ${2}
230-
endsnippet
231-
232-
snippet digits "digits"
233-
digits=(${1:16}, ${2:2}), ${3}
234-
endsnippet
235-
236-
snippet digits "digits_compute"
237-
digits_compute=dp.get_precision('${1:PrecisionName}'), ${2}
247+
digits=dp.get_precision('${1:PrecisionName}'), ${2}
238248
endsnippet
239249

240250
snippet select
@@ -302,22 +312,18 @@ ${1}
302312
return res
303313
endsnippet
304314

305-
snippet func "def create"
306-
def create(self, cr, uid, vals, context=None):
307-
if context is None:
308-
context = {}
315+
snippet fcreate "def create"
316+
def create(self, vals):
309317
${1}
310-
${3:record}_id = super(${2:ClassName}, self).create(cr, uid, vals, context=context)
311-
${4}
312-
return $3_id
318+
record = super(${2:ClassName}, self).create(vals)
319+
${3}
320+
return record
313321
endsnippet
314322

315-
snippet func "def write"
316-
def write(self, cr, uid, ids, values, context=None):
317-
if context is None:
318-
context = {}
323+
snippet fwrite "def write"
324+
def write(self, vals):
319325
${1}
320-
res = super(${2:ClassName}, self).write(cr, uid, ids, values, context=context)
326+
res = super(${2:ClassName}, self).write(vals)
321327
${3}
322328
return res
323329
endsnippet
@@ -808,3 +814,11 @@ snippet context_get
808814
context = self.pool.get('res.users').context_get(cr, uid)
809815
endsnippet
810816

817+
snippet idt
818+
from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT
819+
endsnippet
820+
821+
snippet id
822+
from odoo.tools import DEFAULT_SERVER_DATE_FORMAT
823+
endsnippet
824+

UltiSnips/xml.snippets

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -529,33 +529,33 @@ snippet act_view
529529

530530
endsnippet
531531

532-
snippet xpath "after"
532+
snippet xpathaf "after"
533533
<xpath expr="//field[@${1:name}='${2:field}']" position="after">
534534
<field name="${3:name}"/>
535535
</xpath>
536536
endsnippet
537537

538-
snippet xpath "before"
538+
snippet xpathb "before"
539539
<xpath expr="//field[@${1:name}='${2:field}']" position="before">
540540
<field name="${3:name}"/>
541541
</xpath>
542542
endsnippet
543543

544-
snippet xpath "replace"
544+
snippet xpathr "replace"
545545
<xpath expr="//field[@${1:name}='${2:field}']" position="replace">
546546
<field name="$2"/>
547547
</xpath>
548548
endsnippet
549549

550-
snippet xpath "inside"
550+
snippet xpathi "inside"
551551
<xpath expr="//notebook" position="inside">
552552
<page string="${1:text}">
553553
<field name="${2:name}"/>
554554
</page>
555555
</xpath>
556556
endsnippet
557557

558-
snippet xpath "attribute"
558+
snippet xpathat "attribute"
559559
<xpath expr="//field[@${1:name}='${2:field}']" position="attributes">
560560
<attribute name="${3:required}">${4:1}</attribute>
561561
</xpath>

0 commit comments

Comments
 (0)