Last active
March 12, 2019 08:56
-
-
Save ejabu/d556b21edce4e9e8ddd4894f5096ae95 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Django Models":{ | |
"prefix": "django", | |
"body": "django snippet here" | |
}, | |
"Basic model":{ | |
"prefix": "New Model (Basic)", | |
"body": [ | |
"from odoo import models, fields", | |
"", | |
"class ${1:KampusSiswa}(models.Model):", | |
" _name = '${2:kampus.siswa}'", | |
"", | |
" name = fields.Char(string='Name')" | |
] | |
}, | |
"Advance Model": { | |
"prefix": "New or Inherit (Advance)", | |
"body": [ | |
"from odoo import models, fields, api, _", | |
"from odoo.exceptions import UserError, ValidationError", | |
"", | |
"class $1(models.Model):", | |
" _new = '$2'", | |
" _inherit = '$2'", | |
"", | |
" name = fields.Char(string='Name')$0", | |
"", | |
] | |
}, | |
"Date Today": { | |
"prefix": "today", | |
"body": [ | |
"fields.Date.today()" | |
] | |
}, | |
"Training All Fields": { | |
"prefix": "Field All", | |
"body": [ | |
"name = fields.Char(string='Name')", | |
"alamat = fields.Text(string='Alamat')", | |
"tahun_masuk = fields.Integer(string='Tahun Masuk')", | |
"ipk = fields.Float(string='IPK')", | |
"", | |
"tanggal_lahir = fields.Date(string='Tanggal Lahir')", | |
"waktu_bangun = fields.Datetime(string='Waktu Bangun Tidur')", | |
"gender = fields.Selection([", | |
"\t('l', 'Laki-laki'),", | |
"\t('p', 'Perempuan'),", | |
"], string='Gender')", | |
"", | |
"is_exchange = fields.Boolean(string='Siswa Pertukaran ?')", | |
] | |
}, | |
"Odoo Field Related": { | |
"prefix": "fo_related", | |
"body": [ | |
"invoice_partner_id = fields.Many2one('res.partner', related='invoice_id.partner_id', string='Nama')", | |
] | |
}, | |
"Odoo Field Boolean": { | |
"prefix": "fo_bool", | |
"body": [ | |
"${1:is_full} = fields.Boolean(string='${2:Kelas Penuh ?}')" | |
] | |
}, | |
"Odoo Field Integer": { | |
"prefix": "fo_int", | |
"body": [ | |
"${1:kapasitas_siswa} = fields.Integer(string='${2:Kapasitas Siswa}', default=40)" | |
] | |
}, | |
"Odoo Field Date": { | |
"prefix": "fo_date", | |
"body": [ | |
"${1:tanggal_masuk} = fields.Date(string='${2:Tanggal Masuk}', default=fields.Date.today())" | |
] | |
}, | |
"state selection": { | |
"prefix": "state selection", | |
"body": [ | |
"${1:state} = fields.Selection([", | |
" ('draft', 'Draft'),", | |
" ('open', 'Open'),", | |
" ], string='${2:Status}', default='draft')", | |
] | |
}, | |
"m2o Field": { | |
"prefix": "Many2one Odoo Field", | |
"body": [ | |
"${1:invoice_id} = fields.Many2one('${2:account.invoice}', '${5:Invoice}', ondelete='cascade')", | |
"${3:line_ids} = fields.One2many('${4:account.invoice.line}', '${1:invoice_id}', 'Line')$0", | |
] | |
}, | |
"o2m Field": { | |
"prefix": "One2many Odoo Field", | |
"body": [ | |
"${1:line_ids} = fields.One2many('${2:account.invoice.line}', '${3:invoice_id}', 'Line')", | |
"${3:invoice_id} = fields.Many2one('${4:account.invoice}', '${5:Invoice}', ondelete='cascade')$0", | |
] | |
}, | |
"many2many Simple": { | |
"prefix": "Many2many (Simple)", | |
"body": [ | |
"customer_handle_ids = fields.Many2many(", | |
" comodel_name='res.partner',", | |
" string='Customer Handle',", | |
" )", | |
] | |
}, | |
"many2many Medium": { | |
"prefix": "Many2many (Medium)", | |
"body": [ | |
"customer_handle_ids = fields.Many2many(", | |
" comodel_name='res.partner',", | |
" relation='customer_handle_rel',", | |
" string='Customer Handle',", | |
" )", | |
] | |
}, | |
"many2many Complex": { | |
"prefix": "Many2many (Complex)", | |
"body": [ | |
"customer_handle_ids = fields.Many2many(", | |
" comodel_name='res.partner',", | |
" relation='customer_handle_rel',", | |
" column1='sales_id',", | |
" column2='customer_id',", | |
" string='Customer Handle',", | |
" copy=False,", | |
" )", | |
] | |
}, | |
"Search Query": { | |
"prefix": "search Query", | |
"body": [ | |
"search_query = [('$1', '$2', $3)]", | |
] | |
}, | |
"Track Visibility": { | |
"prefix": "Track Visibility", | |
"body": [ | |
"track_visibility='onchange'", | |
] | |
}, | |
"Mesaging Form View": { | |
"prefix": "messaging form view", | |
"body": [ | |
"_inherit = ['mail.thread']" | |
] | |
}, | |
"def super": { | |
"prefix": "def super", | |
"body": [ | |
"return super(AccountInvoice, self).finalize_invoice_move_lines(move_lines)" | |
] | |
}, | |
"def get sequence": { | |
"prefix": "def get sequence", | |
"body": [ | |
"doc.name = self.env['ir.sequence'].next_by_code('${1:payment.request}')" | |
] | |
}, | |
"Odoo Field Sequence": { | |
"prefix": "fo_sequence", | |
"body": [ | |
"_order = \"sequence\"", | |
"", | |
"sequence = fields.Integer('Sequence')" | |
] | |
}, | |
"IPDB": { | |
"prefix": "ipdb", | |
"body": [ | |
"import ipdb; ipdb.set_trace()" | |
] | |
}, | |
"pdb": { | |
"prefix": "pdb", | |
"body": [ | |
"import ipdb; ipdb.set_trace()" | |
] | |
}, | |
"Raise User Error": { | |
"prefix": "Odoo UserError", | |
"body": [ | |
"raise UserError('$1')" | |
] | |
}, | |
"def button": { | |
"prefix": "def button", | |
"body": [ | |
"def baca_ulang(self):", | |
"\t# Perhatian nama recompute sudah digunakan Odoo", | |
"\timport ipdb; ipdb.set_trace()", | |
"\tabc = 3", | |
"" | |
] | |
}, | |
"def compute": { | |
"prefix": "def compute", | |
"body": [ | |
"@api.depends('line_ids')", | |
"def baca_ulang(self):", | |
"\t# Perhatian nama recompute sudah digunakan Odoo", | |
"\timport ipdb; ipdb.set_trace()", | |
"\tabc = 3", | |
"" | |
] | |
}, | |
"Function": { | |
"prefix": "def Odoo", | |
"body": [ | |
"# Perhatian nama recompute sudah digunakan Odoo", | |
"@api.one", | |
"def baca_ulang(self):", | |
"\timport ipdb; ipdb.set_trace()", | |
"\tabc = 3", | |
"\treturn", | |
"" | |
] | |
}, | |
"QQ": { | |
"prefix": "qqq", | |
"body": [ | |
"qqq = 3", | |
] | |
}, | |
"required di Field": { | |
"prefix": "required", | |
"body": [ | |
"required=True, ", | |
] | |
}, | |
"Message 1 - One Line": { | |
"prefix": "message 1 - Simple", | |
"body": [ | |
"referensi_po = \"PO : %s\" % (self.origin)" | |
] | |
}, | |
"Message 2- Multi Line": { | |
"prefix": "message 2 - multi-line", | |
"body": [ | |
"message = '''", | |
" Journal ditemukan lebih dari satu", | |
"", | |
" %s", | |
"''' % (', '.join(account_move_doc.mapped('name')))", | |
] | |
}, | |
"api.depends": { | |
"prefix": "depends", | |
"body": [ | |
"@api.depends('${1:price}')", | |
] | |
}, | |
"manifest": { | |
"prefix": "manifest", | |
"body": [ | |
"{", | |
" 'name': '${1:Sale Order Discount}',", | |
" 'version': '11.1.0',", | |
" 'author': 'PT ${2:Google}',", | |
" 'license': 'OPL-1',", | |
" 'category': 'Tailor-Made',", | |
" 'website': 'http: //${3:www.google.com}/',", | |
" 'summary': 'Custom-built Odoo',", | |
" 'description': '''", | |
" ''',", | |
" 'depends': [", | |
" # 'account', # python", | |
" # 'sale', # python", | |
" ],", | |
" 'data': [", | |
" # 'views/_menu_item.xml',", | |
" ],", | |
" 'qweb': [", | |
" ],", | |
" 'auto_install': False,", | |
" 'installable': True,", | |
" 'application': True,", | |
"}", | |
] | |
}, | |
"domain field": { | |
"prefix": "domain field", | |
"body": [ | |
"domain=[('journal_id_type', '=', 'bank'), ('payment_type', '=', 'inbound')]", | |
] | |
}, | |
"buka wizard dari py": { | |
"prefix": "buka wizard dari py", | |
"body": [ | |
"def buka_wizard_transfer(self):", | |
" return {", | |
" 'name': 'Transfer',", | |
" 'view_type': 'form',", | |
" 'view_mode': 'form',", | |
" 'res_model': 'session.transfer.wizard',", | |
" 'target': 'new',", | |
" 'type': 'ir.actions.act_window',", | |
" 'context' : {'default_kasir_session_id' : self.id}", | |
" }", | |
"", | |
] | |
}, | |
"Wizard Dari Py": { | |
"prefix": "Wizard Dari Py", | |
"body": [ | |
"action = self.env.ref('account.view_account_supplier_payment_tree')", | |
"result = action.read()[0]", | |
"imd = self.env['ir.model.data']", | |
"list_view_id = imd.xmlid_to_res_id('account.view_account_supplier_payment_tree')", | |
"form_view_id = imd.xmlid_to_res_id('account.view_account_payment_form')", | |
"result['domain'] = \"[('id', 'in', \" + str(self.advance_ids.ids) + \")]\"", | |
"return {", | |
" 'name': 'Advances',", | |
" 'view_type': 'form',", | |
" 'view_mode': 'tree,form',", | |
" 'views': [[list_view_id, 'tree'], [form_view_id, 'form']],", | |
" 'domain' : result.get('domain'),", | |
" 'res_model': 'account.payment',", | |
" 'type': 'ir.actions.act_window',", | |
"}", | |
] | |
}, | |
"Wizard": { | |
"prefix": "wizard Odoo", | |
"body": [ | |
"from datetime import datetime, date", | |
"from odoo import fields, models, api, _", | |
"", | |
"class $1Wizard(models.TransientModel):", | |
"", | |
" _name = '$2.wizard'", | |
"", | |
" name = fields.Char('Name')", | |
"", | |
" def process_wizard(self):", | |
" ids_to_change = self._context.get('active_ids')", | |
" active_model = self._context.get('active_model')", | |
" doc_ids = self.env[active_model].browse(ids_to_change)", | |
" doc_ids.confirm_payment()", | |
" field_to_write = self.char_fields", | |
" # doc_ids.write(", | |
" # {", | |
" # 'state' : self.name", | |
" # }", | |
" # )", | |
"", | |
] | |
}, | |
"compute field": { | |
"prefix": "Compute Field", | |
"body": [ | |
"${1:price_subtotal} = fields.Float(compute='${2:_compute_subtotal}', string='Subtotal', store=False)", | |
"", | |
"@api.multi", | |
"def ${2:_compute_subtotal}(self):", | |
" for session_doc in self:", | |
" session_amount_total = sum(session_doc.payment_carfix_ids.mapped('amount_total'))", | |
" session_doc.session_amount_total = session_amount_total", | |
" import ipdb; ipdb.set_trace()", | |
" abc = 3", | |
" self.${1:price_subtotal} = 4$0", | |
"", | |
] | |
}, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment