├── lib └── main.coffee ├── CHANGELOG.md ├── package.json ├── LICENSE.md ├── README.md └── snippets ├── odoo-python-snippets.cson └── odoo-xml-snippets.cson /lib/main.coffee: -------------------------------------------------------------------------------- 1 | module.exports = 2 | activate: (state) -> 3 | 4 | deactivate: -> 5 | 6 | serialize: -> 7 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.4.0 2 | 3 | * Change prefix to `odoo_` 4 | 5 | ## 0.3.2 6 | 7 | * Fix HTML field (issue #6) 8 | 9 | ## 0.3.1 10 | 11 | * Minor fix 12 | 13 | ## 0.3.0 14 | 15 | * Global improvements for Python snippets (placeholders, better relational fields...) 16 | 17 | ## 0.2.0 18 | 19 | * Remove useless xpath 20 | 21 | ## 0.1.0 22 | 23 | * Initial release 24 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "odoo-snippets", 3 | "main": "./lib/main", 4 | "version": "0.5.0", 5 | "description": "Snippets for the Odoo software development", 6 | "keywords": [ 7 | "snippets", 8 | "odoo", 9 | "python", 10 | "xml" 11 | ], 12 | "activationCommands": {}, 13 | "repository": "https://github.com/DocMarty84/atom-odoo-snippets", 14 | "license": "MIT", 15 | "engines": { 16 | "atom": ">0.50.0" 17 | }, 18 | "dependencies": {} 19 | } 20 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Nicolas Martinelli 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # atom-odoo-snippets 2 | 3 | Add snippets for the Odoo software development to the Atom editor. Snippets are 4 | provided for Python and XML sources. All snippets start with prefix 'odoo_'. 5 | 6 | Python snippets: 7 | - Create new Odoo object 8 | - Inherit/Extend existing Odoo object 9 | - Add new field of type Integer, Char, Text, Many2one, One2many, Many2many, 10 | Boolean, HTML, Float, Date, DateTime, Selection, Binary 11 | - Call to search and name_search 12 | - Create method for compute, onchange, constrains 13 | - Add a computed field with appropriate methods 14 | 15 | XML snippets: 16 | - Create the main tags 17 | - Create Form/Tree/Search view 18 | - Inherit existing Form/Tree/Search view 19 | - Add Form's header with 'state' and buttons 20 | - Create action 21 | - Create menu item for any of the 3 levels (upper bar, category, action) 22 | - Add nested groups, notebook and page, page 23 | - Add domain to a field 24 | - Create security category 25 | - Create group, then assign new permissions 26 | - Create security rules 27 | - Create workflow 28 | - Add transition or activity to an existing workflow 29 | - Add social messaging and followers 30 | 31 | Inspired by the project odoo-pycharm-templates: 32 | https://github.com/mohamedmagdy/odoo-pycharm-templates 33 | -------------------------------------------------------------------------------- /snippets/odoo-python-snippets.cson: -------------------------------------------------------------------------------- 1 | '.source.python': 2 | 3 | # Odoo objects 4 | 5 | 'Create New Odoo Object': 6 | 'prefix': 'odoo_object' 7 | 'body': """ 8 | class ${10:NewModule}(models.Model): 9 | _name = "${20:module.name}" 10 | _rec_name = "${30:module.rec_name}" # optional 11 | _description = "${40:Module description}" 12 | _order = "${50:field1}, ${60:field2}, " # optional 13 | 14 | name = fields.Char()$70 15 | """ 16 | 17 | 'Inherit/Extend Existing Odoo Object': 18 | 'prefix': 'odoo_object_inherit' 19 | 'body': """ 20 | class ${10:NewModule}(models.Model): 21 | _name = "${20:module.name}" # optional 22 | _inherit = "${30:module.name}" 23 | 24 | name = fields.Char()$40 25 | """ 26 | 27 | # Odoo fields 28 | 29 | 'Integer Field': 30 | 'prefix': 'odoo_field_integer' 31 | 'body': '${5:new_field} = fields.Integer(string="${10:Field name}", )' 32 | 33 | 'Float Field': 34 | 'prefix': 'odoo_field_float' 35 | 'body': '${5:new_field} = fields.Float(string="${10:Field name}", )' 36 | 37 | 'Char Field': 38 | 'prefix': 'odoo_field_char' 39 | 'body': '${5:new_field} = fields.Char(string="${10:Field name}", )' 40 | 41 | 'Text Field': 42 | 'prefix': 'odoo_field_text' 43 | 'body': '${5:new_field} = fields.Text(string="${10:Field name}", )' 44 | 45 | 'Many2one Field': 46 | 'prefix': 'odoo_field_many2one' 47 | 'body': ''' 48 | ${10:new_field_id} = fields.Many2one( 49 | string="${20:Field name}", 50 | comodel_name="${30:res.partner}", 51 | domain="[('${40:field}', '${41:=}', ${42:other})]", 52 | context={"${50:key}": ${51:"value"}\\}, 53 | ondelete="${60:set null}", 54 | help="${70:Explain your field}.", 55 | )$80 56 | ''' 57 | 58 | 'One2many Field': 59 | 'prefix': 'odoo_field_one2many' 60 | 'body': ''' 61 | ${10:new_field_ids} = fields.One2many( 62 | string="${20:Field name}", 63 | comodel_name="${30:res.partner}", 64 | inverse_name="${40:inverse_name_id}", 65 | domain="[('${50:field}', '${51:=}', ${52:other})]", 66 | context={"${60:key}": ${61:"value"}\\}, 67 | help="${70:Explain your field}.", 68 | )$80 69 | ''' 70 | 71 | 'Many2many Field': 72 | 'prefix': 'odoo_field_many2many' 73 | 'body': ''' 74 | ${10:new_field_ids} = fields.Many2many( 75 | string="${20:Field name}", 76 | comodel_name="${30:res.partner}", 77 | relation="${40:relation_table_name}", 78 | column1="${50:column_this}", 79 | column2="${60:column_other}", 80 | domain="[('${70:field}', '${71:=}', ${72:other})]", 81 | context={"${80:key}": ${81:"value"}\\}, 82 | help="${90:Explain your field}.", 83 | )$100 84 | ''' 85 | 86 | 'Boolean Field': 87 | 'prefix': 'odoo_field_boolean' 88 | 'body': '${5:is_new_field} = fields.Boolean(string="${10:Field name}", )' 89 | 90 | 'HTML Field': 91 | 'prefix': 'odoo_field_html' 92 | 'body': '${5:new_field} = fields.Html(string="${10:Field name}", )' 93 | 94 | 'Date Field': 95 | 'prefix': 'odoo_field_date' 96 | 'body': '${5:new_field} = fields.Date(string="${10:Field name}", )' 97 | 98 | 'DateTime Field': 99 | 'prefix': 'odoo_field_datetime' 100 | 'body': '${5:new_field} = fields.Datetime(string="${10:Field name}", )' 101 | 102 | 'Selection Field': 103 | 'prefix': 'odoo_field_selection' 104 | 'body': ''' 105 | ${5:new_field} = fields.Selection( 106 | string="${10:Field name}", 107 | selection=[ 108 | (\'${20:value1}\', \'${21:description1}\'), 109 | (\'${30:value2}\', \'${31:description2}\'), 110 | ],$40 111 | )$50 112 | ''' 113 | 114 | 'Binary Field': 115 | 'prefix': 'odoo_field_binary' 116 | 'body': '${5:new_field} = fields.Binary(string="${10:Field name}", )' 117 | 118 | # Call to common Odoo methods 119 | 120 | 'Search': 121 | 'prefix': 'odoo_search' 122 | 'body': 'self.search([(\'$1\', \'=\', $2), ...], offset=0, limit=None, order=None, count=False)' 123 | 124 | 'Name search': 125 | 'prefix': 'odoo_search_name' 126 | 'body': 'self.name_search(name=\'$1\', args=None, operator=\'ilike\', limit=100)' 127 | 128 | # Creation of common Odoo methods 129 | 130 | 'Compute method': 131 | 'prefix': 'odoo_method_compute' 132 | 'body': """ 133 | @api.multi 134 | @api.depends("${10:field1}", "${20:field2}", ) 135 | def _compute_${30:field}(self): 136 | for s in self: 137 | ${40:pass} 138 | """ 139 | 140 | 'Onchange method': 141 | 'prefix': 'odoo_onchange_method' 142 | 'body': """ 143 | @api.onchange("${10:field1}", "${20:field2}", ) 144 | def _onchange_${30:field}(self): 145 | vals = {} 146 | 147 | # Remove warning if necessary 148 | vals['warning'] = { 149 | 'title': _('$40') 150 | 'message': _('$50') 151 | } 152 | 153 | # Remove domain if necessary 154 | vals['domain'] = { 155 | "${60:field}": [("$61", "${62:=}", ${63:value})], 156 | } 157 | 158 | return vals$70 159 | """ 160 | 161 | 'Constrains method': 162 | 'prefix': 'odoo_constrains_method' 163 | 'body': """ 164 | @api.multi 165 | @api.constrains("${10:field1}", "${20:field2}", ) 166 | def _check_${30:field}(self): 167 | for s in self: 168 | if s.${40:field} == ${50:value}: 169 | raise ValidationError(_("$60"))$70 170 | """ 171 | 172 | # Complex Odoo fields 173 | 174 | 'Compute field': 175 | 'prefix': 'ododoo_field_compute' 176 | 'body': """ 177 | ${10:new_field} = fields.${20:Float}( 178 | string="${30:Field string}", 179 | compute='_compute_${10:new_field}', 180 | inverse='_inverse_${10:new_field}', 181 | search='_search_${10:new_field}', 182 | help="$50", 183 | ) 184 | 185 | @api.multi 186 | @api.depends("${60:field1}", "${70:field2}", ) 187 | def _compute_${10:new_field}(self): 188 | for s in self: 189 | ${80:pass} 190 | 191 | @api.multi 192 | def _inverse_${10:new_field}(self): 193 | for s in self: 194 | ${90:pass} 195 | 196 | @api.multi 197 | def _search_${10:new_field}(self, operator, value): 198 | if operator == 'like': 199 | operator = 'ilike' 200 | return [('${100:new_field}', operator, value)]} 201 | """ 202 | -------------------------------------------------------------------------------- /snippets/odoo-xml-snippets.cson: -------------------------------------------------------------------------------- 1 | '.text.xml': 2 | 'Create the main tags': 3 | 'prefix': 'odoo_data' 4 | 'body': """ 5 | 6 | 7 | $1 8 | 9 | """ 10 | 11 | # Form, tree and search view creation 12 | 13 | 'Create form view': 14 | 'prefix': 'odoo_form' 15 | 'body': """ 16 | 17 | $2.form 18 | $2 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 |
27 |
28 |
29 | """ 30 | 31 | 'Create tree view': 32 | 'prefix': 'odoo_tree' 33 | 'body': """ 34 | 35 | $2.tree 36 | $2 37 | 38 | 39 | 40 | 41 | 42 | 43 | """ 44 | 45 | 'Create search view': 46 | 'prefix': 'odoo_search' 47 | 'body': """ 48 | 49 | $2.search 50 | $2 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | """ 62 | 63 | 'Inherit existing form view': 64 | 'prefix': 'odoo_form_inherit' 65 | 'body': """ 66 | 67 | 68 | $2.form 69 | $2 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | """ 78 | 79 | 'Inherit existing tree view': 80 | 'prefix': 'odoo_tree_inherit' 81 | 'body': """ 82 | 83 | $2.tree 84 | $2 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | """ 93 | 94 | 'Inherit existing search view': 95 | 'prefix': 'odoo_search_inherit' 96 | 'body': """ 97 | 98 | $2.search 99 | $2 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | """ 108 | 109 | 'Add Form\'s header with \'state\' and buttons': 110 | 'prefix': 'odoo_form_header' 111 | 'body': """ 112 |
113 |
116 | """ 117 | 118 | # Action 119 | 120 | 'Create new action': 121 | 'prefix': 'odoo_action' 122 | 'body': """ 123 | 124 | $2 125 | $3 126 | tree,form 127 | 128 |

129 | 130 |

131 |

132 | 133 |

134 |
135 |
136 | """ 137 | 138 | # Menuitem 139 | 140 | 'Create menu item in the upper bar': 141 | 'prefix': 'odoo_menuitem_root' 142 | 'body': '' 143 | 144 | 'Create menu item for category': 145 | 'prefix': 'odoo_menuitem_category' 146 | 'body': '' 147 | 148 | 'Create menu item for actions': 149 | 'prefix': 'odoo_menuitem_action' 150 | 'body': '' 151 | 152 | # Common structures 153 | 154 | 'Add nested groups': 155 | 'prefix': 'odoo_nested_group' 156 | 'body': """ 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | """ 166 | 167 | 'Add notebook and a page': 168 | 'prefix': 'odoo_notebook' 169 | 'body': """ 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | """ 178 | 179 | 'Add page': 180 | 'prefix': 'odoo_page' 181 | 'body': """ 182 | 183 | 184 | 185 | 186 | 187 | """ 188 | 189 | 'Add domain to a field': 190 | 'prefix': 'odoo_domain' 191 | 'body': 'domain="[(\'$1\', \'=\', $2), ]"' 192 | 193 | # Security 194 | 195 | 'Create security category': 196 | 'prefix': 'odoo_security_category' 197 | 'body': """ 198 | 199 | $2 200 | $3 201 | 202 | """ 203 | 204 | 'Create group, then assign new permissions': 205 | 'prefix': 'odoo_security_group' 206 | 'body': """ 207 | 208 | $2 209 | 210 | 211 | 212 | """ 213 | 214 | 'Create security rules': 215 | 'prefix': 'odoo_security_rule' 216 | 'body': """ 217 | 218 | $2 219 | 220 | [(\'$4\', \'=\', $5), ] 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | """ 230 | 231 | # Workflow 232 | 233 | 'Create workflow': 234 | 'prefix': 'odoo_wkf' 235 | 'body': """ 236 | 237 | $2 238 | $3 239 | True 240 | 241 | """ 242 | 243 | 'Add transition to workflow': 244 | 'prefix': 'odoo_wkf_transition' 245 | 'body': """ 246 | 247 | 248 | 249 | $4 250 | 251 | """ 252 | 253 | 'Add activity to workflow': 254 | 'prefix': 'odoo_wkf_activity' 255 | 'body': """ 256 | 257 | 258 | $3 259 | 260 | 261 | function 262 | $4 263 | 264 | """ 265 | 266 | # Misc 267 | 268 | 'Add Social Messaging and followers': 269 | 'prefix': 'odoo_form_social' 270 | 'body': """ 271 |
272 | 273 | 274 |
275 | """ 276 | --------------------------------------------------------------------------------