Initial commit

This commit is contained in:
Guillem Barba 2013-08-15 14:11:41 +02:00
commit 999064bfdf
4 changed files with 810 additions and 0 deletions

2
README Normal file
View File

@ -0,0 +1,2 @@
Clone this repository as 'UltiSnips' directory inside .vim to has these
snippets available.

116
all.snippets Normal file
View File

@ -0,0 +1,116 @@
snippet nan_tryton_license "tryton licese" b
Copyright (C) `!v strftime("%Y")` NaN Projectes de Programari Lliure S.L.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
endsnippet
snippet tryes_tryton_license "tryton licese with Tryton ERP copyright" b
Copyright (C) `!v strftime("%Y")` NaN Projectes de Programari Lliure S.L.
Copyright (C) `!v strftime("%Y")` Zikzakmedia S.L.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
endsnippet
snippet try_copy_head "Tryton Copyright Header" b
#This file is part of Tryton. The COPYRIGHT file at the top level of
#this repository contains the full copyright notices and license terms.
endsnippet
snippet nan_open_license "OpenERP License" b
##############################################################################
#
# Copyright (c) `!v strftime("%Y")` NaN Projectes de Programari Lliure, S.L.
# All Rights Reserved.
# http://www.NaN-tic.com
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU Affero General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
${1}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
endsnippet
snippet gui_open_license "OpenERP License" b
##############################################################################
#
# Copyright (c) `!v strftime("%Y")` Guillem Barba Domingo
# All Rights Reserved.
# http://www.guillem.alcarrer.net
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU Affero General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
${1}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
endsnippet

487
python.snippets Normal file
View File

@ -0,0 +1,487 @@
snippet utf8-header "Header encoding UTF-8" b
# -*- encoding: utf-8 -*-
endsnippet
snippet __openerp__ "OpenErp Module Definition" b
{
"name": "${1:name}",
"version": "0.1",
"author": "NaN·tic",
"category": "${2:category}",
"website": "http://www.nan-tic.com",
"description": """
${3:This module provide:}
""",
"depends": [
'${4:base}',
],
"init_xml": [],
"update_xml": [${5}
],
"demo_xml": [],
"active": False,
"installable": True,
}
endsnippet
snippet _columns "OpenErp Field definition Dict Model" b
_columns = {
${1}
}
endsnippet
snippet _constraints "OpenErp Constraints" b
def ${1:_check_metho}(self, cr, uid, ids, context=None):
#TODO: check condition and return boolean accordingly
return True
_constraints = [
($1, '', ['${2:field_name}']),
]
endsnippet
snippet _defaults "OpenErp defaults dict" b
_defaults = {
'${1:datee}': ${2:lambda *a: time.strftime('%Y-%m-%d')},${3}
}
endsnippet
snippet _description "_description" b
_description = '${__doc__}' ${cr}
endsnippet
snippet _inherit "Openerp Inheritance type 1" b
_inherit = '${1:openerpmodel}'
#Do not touch _name it must be same as _inherit
#_name = '${1:openerpmodel}' ${cr}
endsnippet
snippet _inherits "_inherits" b
_inherits = {'${1:openerpmodel}': '${2:model_id}' ${cr} }
endsnippet
snippet _name "_name" b
_name = '${1:name}' ${cr}
endsnippet
snippet _order "_order" b
_order = '${1:id}' ${cr}
endsnippet
snippet _parent_store "_parent_store" b
_parent_store = ${1:False} ${cr}
endsnippet
snippet _rec_name "_rec_name" b
_rec_name = '${1:name}' ${cr}
endsnippet
snippet _sql_constraints "_sql_constraints" b
_sql_constraints = [
('${1:fieldname}_uniq', 'unique ($1)',
"The ${2:fieldLabel} of the ${3:OpenERPModel} must be unique"),
]
endsnippet
snippet _table "_table" b
_table = '${1:openerp_model}' ${cr}
endsnippet
snippet def_action_workflow "def action_workflow" b
def action_cancel(self, cr, uid, ids, *args):
#TODO: Business Process return result ${cr}
result = True
endsnippet
snippet def_copy "def copy" b
def copy(self, cr, uid, id, default=None, context=None):
res_id = super(${1:ModelName}, self).copy(cr, uid, id, default, context)
return res_id ${cr}
endsnippet
snippet def_create "def create" b
def create(self, cr, uid, vals, context=None):
res_id = super(${1:ModelName}, self).create(cr, uid, vals, context)
return res_id ${cr}
endsnippet
snippet def_default_get "def default_get" b
def default_get(self, cr, uid, fields_list, context=None):
values = {}
${cr}
return values
endsnippet
snippet def_fields_get "def fields_get" b
def fields_get(self, cr, uid, fields=None, context=None):
return super(${1:ModelName}, self).fields_get(cr, uid, fields, context, read_access)
${cr}
endsnippet
snippet def_fields_view_get "def fields_view_get" b
def fields_view_get(self, cr, user, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
res = super(${1:ModelName}, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar, submenu)
return res
endsnippet
snippet def_name_get "def name_get" b
def name_get(self, cr, uid, ids, context=None):
#TODO: search on name field or _res_name fields
#and make a result [(id, name), (id, name), ...]
res = self.read(cr, uid, ids, [self._rec_name], context, load='_classic_write')]
return res ${cr}
endsnippet
snippet def_name_search "def name_search" b
def name_search(self, cr, uid, name, args=None, operator='ilike', context=None, limit=80):
#TODO: make a search on specific fields and get ids
if not args:
args=[]
if not context:
context={}
ids = []
if name:
ids = self.search(cr, uid, [('code','ilike',name)]+ args, limit=limit)
if not ids:
ids = self.search(cr, uid, [('name',operator,name)]+ args, limit=limit)
self.name_get(cr, uid, ids, context=context)${cr}
endsnippet
snippet def_onchange "def onchange" b
def onchange_${1:fields}(self, cr, uid, ids, ${2:$1}, context=None):
#TODO: compute new values from the db/system
${3}
return {
'value': {
'field_1': res1,
'field_2': res,
},
'domain': {
'field_3': [],
},
'warning': {
'title': _(""),
'message': _(""),
}}
endsnippet
snippet def_read "def read" b
def read(self, cr, uid, ids, fields=None, context=None, load='_classic_read'):
res = super(${1:ModelName}, self).read(cr, uid, ids, fields, context)
#TODO: process on result
return res ${cr}
endsnippet
snippet def_search "def search" b
def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False):
#TODO: process on args before search
res = super(${1:ModelName}, self).search(cr, uid, args, offset, limit, order, context, count)
#TODO: process
endsnippet
snippet def_unlink "def unlink" b
def unlink(self, cr, uid, ids, context=None):
#TODO: process before delete resource
res = super(${1:ModelName}, self).unlink(cr, uid, ids, context)
return res ${cr}
endsnippet
snippet def_write "def write" b
def write(self, cr, uid, ids, vals, context=None):
#TODO: process before updating resource
res = super(${1:ModelName}, self).write(cr, uid, ids, vals, context)
return res ${cr}
endsnippet
snippet field_attribute_domain "Field Attribute: domain" b
domain=[('${1:state}','=','${2:done}'), ${cr}]
endsnippet
snippet field_attribute_help "Field Attribute: help" b
help='${1:HelpAboutField}', ${cr}
endsnippet
snippet field_attribute_ondelete "Field Attribute: ondelete" b
, ondelete="cascade"${cr}
endsnippet
snippet field_attribute_readonly "Field Attribute: readonly" b
readonly=True, ${cr}
endsnippet
snippet field_attribute_required "Field Attribute: required" b
required=True, ${cr}
endsnippet
snippet field_attribute_select "Field Attribute: select" b
select = True, ${cr}
endsnippet
snippet field_attribute_store "Field Attribute: store" b
store={
#TODO: define model and function call for store field
'${1:field_name}': (_get_invoice_from_line, None, 50),
}
endsnippet
snippet field_attribute_states "Field States" b
states={'${1:draft}':[('readonly',${2:False})${cr}]}
endsnippet
snippet fields.binary "fields.binary" b
'${1:file}': fields.binary('${2:Label}', filters=${3:None}), ${cr}
endsnippet
snippet fields.boolean "fields.boolean" b
'${1:field_name}': fields.boolean("${2:String}", required=${3:True}),
endsnippet
snippet fields.char "fields.char" b
'${1:name}': fields.char("${2:Label}", size=${3:64}, required=${4:False}, readonly=${5:False}),
endsnippet
snippet fields.date "fields.date" b
#TODO: import time required to get currect date
'${1:d_ate}': fields.date('${2:Date}'), ${cr}
endsnippet
snippet fields.datetime "fields.datetime" b
#TODO: import time required to get currect datetime
'${1:datetime}': fields.datetime('${2:Date}'), ${cr}
endsnippet
snippet fields.float "fields.float" b
#import decimal_precision as dp
'${1:number}': fields.float('${2:Label}', digits_compute=dp.get_precision('${3:Account}')), ${cr}
endsnippet
snippet fields.function "fields.function" b
'${1:field_name}': fields.function(${2:_function_call}, method=True, type='${3:float}', string='${4:Label}', ${5:store=True}),
endsnippet
snippet def_calc_field "Functional field method" b
def ${1:_calc_field}(self, cr, uid, ids, fieldname, args, context=None):
${2:res = {}.fromkeys(ids, 0.0)}
${3}
${4:return res}
endsnippet
snippet fields.integer "fields.integer" b
'${1:number}': fields.integer('${2:Label}') ${cr}
endsnippet
snippet fields.integer_big "fields.integer_big" b
'${1:number}': fields.integer_big('${2:Label}') ${cr}
endsnippet
snippet fields.many2many "fields.many2many" b
'${1:OtherObject}_ids': fields.many2many('${2:OpenerpModel}', '${3:ModuleName}_${4:FirstObject}_${5:SecondObject}_rel', '${6:ThisObject}_id', '${7:OtherObject}_id', '${8:Label}'), ${cr}
endsnippet
snippet fields.many2one "fields.many2one" b
'${1:data}_id': fields.many2one('${2:OpenerpModel}', "${3:Label}", required=${4:False}),${5}
endsnippet
snippet fields.one2many "fields.one2many" b
'${1:data}_ids': fields.one2many('${2:OpenerpModel}', '${3:field}_id', "${4:Label}", required=${5:False}),${6}
endsnippet
snippet fields.property "fields.property" b
'property_${1:name}': fields.property(
'${2:OpenerpModel}',
type='${3:many2one}',
relation='${4:openerpmodel}',
string='${5:Label}',
method=True,
view_load=True,
domain='[('${6:state}','=','${7:done}')]',
help="${8:Helpdescrip}"
required=${9:True}),
endsnippet
snippet fields.reference "fields.reference" b
'${1:ref}': fields.reference('${2:Document}',
selection=[
#TODO: define list of model and Label that will be work as a reference
('account.account', 'Account'),
${cr} ], size=${3:128}),
endsnippet
snippet fields.related "fields.related" b
'${1:field}_id': fields.related('${2:relation_field}', '${3:field}_id', type='${4:many2one}', relation='${5:openerpmodel}', string=${6:Label}'), ${cr}
endsnippet
snippet fields.selection "fields.selection: [(draft, Draft)]" b
'${1:state}':fields.selection([
('draft','Draft'),
('done','Done'),
${cr} ], '${2:State}', select=True, readonly=${3:True}),
endsnippet
snippet fields.selection_function "fields.selection [def _select_data]" b
'${1:state}': fields.selection(${2:_get_states}, '${3:data}', required=${4:True}), ${cr}
endsnippet
snippet fields.text "fields.text" b
'${1:note}': fields.text('${2:Description}'), ${cr}
endsnippet
snippet fields.time "fields.time" b
#TODO: import time required to get currect time
'${1:date}': fields.time('${2:Time}'), ${cr}
endsnippet
snippet log-netsvc "log netsvc" b
netsvc.Logger().notifyChannel(self._name, netsvc.${1:LOG_DEBUG}, "${2:log_message}")${3}
endsnippet
snippet odef "New OpenERP Method" b
def ${1:method_name}(self, cr, uid, ids):
result = None
#TODO: OpenERP Business Process
${2}
return result
endsnippet
snippet oclass "OpenERP: model" b
from osv import osv, fields
class ${1:ClassName}(osv.osv):
_name = '${2:openerpmodel}'
_description = '${3:model_description}'
_columns = {
'${4:name}': fields.char('${5:data}', size=${6:64}, required=${7:True},
readonly=${8:False}),
${9}
}
$1()
endsnippet
snippet oinclass "OpenERP: inherit model" b
from osv import osv, fields
class ${1:ClassName}(osv.osv):
_inherit = '${2:openerpmodel}'
_columns = {
${3}
}
$1()
endsnippet
snippet omemclass "OpenERP: Memory model" b
from osv import osv, fields
class ${1:ClassName}(osv.osv_memory):
_name = '${2:openerpmodel}'
_description = '${3:model_description}'
_columns = {
'${4:name}': fields.char('${5:data}', size=${6:64}, required=${7:True},
readonly=${8:False}),
${9}
}
$1()
endsnippet
snippet oinmemclass "OpenERP: inherit memory model" b
from osv import osv, fields
class ${1:ClassName}(osv.osv_memory):
_inherit = '${2:openerpmodel}'
_columns = {
${3}
}
$1()
endsnippet
snippet owizard "OpenERPwizard" b
import wizard
import pooler
class ${1:SendEmail}(wizard.interface):
'''
OpenERP Wizard
'''
${2:form} = '''
<?xml version="1.0"?>
<form string="Process Form">
<field name="${3:field}"/>
</form> '''
${4:fields} = {
'${5:field}': {'string': '${6:Label}', 'type': 'many2one', 'relation': 'res.company'},
}
def ${7:_get_defaults}(self, cr, uid, data, context):
#TODO: initlize required data
${8:cr}
return data['form']
def ${9:_do_duplicate}(self, cr, uid, data, context):
pool = pooler.get_pool(cr.dbname)
return {}
states = {
'init': {
'actions': [${7}],
'result': {'type': 'form', 'arch': ${11:form}, 'fields': ${12:fields}, 'state': (('end', 'Cancel'), ('${13:process}', 'Process'))},
},
'${14:process}': {
'actions': [${9}],
'result': {'type': 'state', 'state': 'end'},
},
}
${1}('${14:modelprocess}')
endsnippet
snippet wizard.state.end "wizard state: end" b
'${1:check}': {
'actions': [],
'result': {'type':'choice','next_state':self.${2:_check_condition}}
#TODO: define def ${2}(self, cr, uid, data, context):
},
${cr}
endsnippet
snippet wiztad.state.choice "wizard States: choice" b
'${1check}': {
'actions': [],
'result': {'type':'choice','next_state':self.${2:_check_condition}}
#TODO: define def ${2}(self, cr, uid, data, context): }, ${cr}
endsnippet
snippet wizard.state.form "wizard States: form" b
'${1:form}': {
'actions': [],
'result': {'type': 'form', 'arch': form, 'fields': fields, 'state': (('end', 'Cancel'), ('process', 'Process'))},
}, ${cr}
endsnippet
snippet wizard.state.print "wizard States: print" b
'${1:report}':{
'actions': [],
'result': {'type':'print', 'report':'${2:modelreportname}', 'state':'${3:end}'}
}, ${cr}
endsnippet

205
xml.snippets Normal file
View File

@ -0,0 +1,205 @@
snippet tryheader "Tryton XML header" b
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
endsnippet
snippet tryton "Tryton base tab" b
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<tryton>
<data>
${1}
</data>
</tryton>
endsnippet
snippet tryformview "Tryton form view record" b
<record model="ir.ui.view" id="${1:model_id}_form_view">
<field name="model">${2:model_name}</field>
<field name="type">form</field>
<field name="name">$1_form</field>
</record>
endsnippet
snippet trylistview "Tryton list view record" b
<record model="ir.ui.view" id="${1:model_id}_list_view">
<field name="model">${2:model_name}</field>
<field name="type">tree</field>
<field name="name">$1_list</field>
</record>
endsnippet
snippet tryactwindow "Tryton Action Window record" b
<record model="ir.action.act_window" id="act_${1:model_id}">
<field name="name">${2:plural_title}</field>
<field name="res_model">${3:model_name}</field>
<field name="search_value"></field>
<field name="domain"></field>
<field name="context"></field>
</record>
endsnippet
snippet tryactformview "Tryton Action Window List View record" b
<record model="ir.action.act_window.view" id="act_${1:model_id}_view1">
<field name="sequence" eval="10"/>
<field name="view" ref="$1_list_view"/>
<field name="act_window" ref="act_$1"/>
</record>
endsnippet
snippet tryactformview "Tryton Action Window List View record" b
<record model="ir.action.act_window.view" id="act_${1:model_id}_view2">
<field name="sequence" eval="20"/>
<field name="view" ref="$1_form_view"/>
<field name="act_window" ref="act_$1"/>
</record>
endsnippet
snippet trycompleteview "Tryton Complete view" b
<record model="ir.ui.view" id="${1:model_id}_form_view">
<field name="model">${2:model_name}</field>
<field name="type">form</field>
<field name="name">$1_form</field>
</record>
<record model="ir.ui.view" id="$1_list_view">
<field name="model">$2</field>
<field name="type">tree</field>
<field name="name">$1_list</field>
</record>
<record model="ir.action.act_window" id="act_$1">
<field name="name">${3:plural_title}</field>
<field name="res_model">$2</field>
<field name="search_value"></field>
<field name="domain"></field>
<field name="context"></field>
</record>
<record model="ir.action.act_window.view" id="act_$1_view1">
<field name="sequence" eval="10"/>
<field name="view" ref="$1_list_view"/>
<field name="act_window" ref="act_$1"/>
</record>
<record model="ir.action.act_window.view" id="act_$1_view2">
<field name="sequence" eval="20"/>
<field name="view" ref="$1_form_view"/>
<field name="act_window" ref="act_$1"/>
</record>
endsnippet
snippet openerp "OpenErp base tag" b
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
${1}
</data>
</openerp>
endsnippet
snippet oform "OpenERP Form View" b
<record id="${1:model_id}_form" model="ir.ui.view">
<field name="name">${2:model.name}.form</field>
<field name="model">$2</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="${3:Model Single Label}">
${4}
</form>
</field>
</record>
endsnippet
snippet oinform "OpenERP Inherit Form View" b
<record id="${1:model_id}_form" model="ir.ui.view">
<field name="name">${2:model_name}.${3:specific_name}.form</field>
<field name="model">$2</field>
<field name="type">form</field>
<field name="inherit_id" ref="${4:inherit_module}.${5:inherit_view}"/>
<field name="arch" type="xml">
${6}
</field>
</record>
endsnippet
snippet otree "OpenERP Tree View" b
<record id="${1:model_id}_tree" model="ir.ui.view">
<field name="name">${2:model.name}.tree</field>
<field name="model">$2</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="${3:Model Plural Label}">
${4}
</tree>
</field>
</record>
endsnippet
snippet ointree "OpenERP Inherit Tree View" b
<record id="${1:model_id}_tree" model="ir.ui.view">
<field name="name">${2:model_name}.${3:specific_name}.tree</field>
<field name="model">$2</field>
<field name="type">tree</field>
<field name="inherit_id" ref="${4:inherit_module}.${5:inherit_view}"/>
<field name="arch" type="xml">
${6}
</field>
</record>
endsnippet
snippet osearch "OpenERP Search View" b
<record id="${1:model_id}_search" model="ir.ui.view">
<field name="name">${2:model.name}.search</field>
<field name="model">$2</field>
<field name="type">search</field>
<field name="arch" type="xml">
<search string="${3:Model Plural Label}">
${4}
</search>
</field>
</record>
endsnippet
snippet oinsearch "OpenERP Inherit Tree View" b
<record id="${1:model_id}_search" model="ir.ui.view">
<field name="name">${2:model_name}.${3:specific_name}.search</field>
<field name="model">$2</field>
<field name="type">search</field>
<field name="inherit_id" ref="${4:inherit_module}.${5:inherit_view}"/>
<field name="arch" type="xml">
${6}
</field>
</record>
endsnippet
snippet oactwindow "OpenERP act_window" b
<record id="action_${1:model_id}" model="ir.actions.act_window">
<field name="name">${2:Model Plurarl Label}</field>
<field name="res_model">${3:model_name}</field>
<field name="view_type">form</field>
<field name="view_mode">${4:tree,form}</field>
<field name="search_view_id" ref="$1_search"/>
${5:<field name="context">{"search_default_draft":1}</field>}
${6:<field name="help">Featured Help Message.</field>}
</record>
endsnippet
snippet osearchfilter "OpenERP search filter" b
<filter name="${1:name}" string="${2:label}"
domain="[${3:('state','=','draft')}]"
icon="${4:terp-icon}" ${5:help="Help message"}/>
endsnippet
snippet ogroupbyfilter "OpenERP group_by filter" b
<filter name="${1:name}" string="${2:label}"
${3:domain="[('state','=','draft')]"}
context="{'group_by':'${4:state}'}"
icon="${5:terp-stock_effects-object-colorize}" ${6:help="Help message"}/>
endsnippet