Skip to content

Instantly share code, notes, and snippets.

self.env.cr.execute(""" CREATE TABLE IF NOT EXISTS your_table(
count decimal, mean decimal, std decimal, min decimal, twentyfive decimal,
fifty decimal, seventyfive decimal, max decimal, cv decimal,
uid integer, report_type text,name text)""")
self.env.cr.commit()
csv_file= open(filepath,"r")
columns=['count','mean','std','min','twentyfive','fifty','seventyfive','max','cv','uid','report_type','name']
self.env.cr.copy_from(csv_file, 'your_table', sep='|', columns=columns)
self.env.cr.commit()
@sehrishnaz
sehrishnaz / odoo_get_data_dir.py
Created October 3, 2019 04:49
How to get data directory that saved in odoo configuration file
from openerp.tools import config
config = tools.config
dir = config['data_dir']
@sehrishnaz
sehrishnaz / many2many_tips.py
Created February 17, 2020 06:16
How can i select only the users belongs to a particular group in a many2many field
user_ids = fields.Many2many('res.users', string='Recipients',
domain=lambda self: [("groups_id", "=",
self.env.ref("base.group_erp_manager").id)])
@sehrishnaz
sehrishnaz / action_button_xml_in_odoo.xml
Created January 8, 2020 03:39
Create Action Button in Odoo using XML
<button name="%(action_any_name_goes_here)d" string="Open Wizard" class="oe_edit_only" type="action"></button>
@sehrishnaz
sehrishnaz / window_action.xml
Created January 8, 2020 03:38
Create Window Action in Odoo
<record model="ir.actions.act_window" id="action_any_name_goes_here">
<field name="name">My Action</field>
<field name="res_model">your.model</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
@sehrishnaz
sehrishnaz / odoo_form_view.xml
Created January 8, 2020 03:37
Form View in Odoo
<record model="ir.ui.view" id="view_any_name_form">
<field name="name">any.name.form</field>
<field name="model">your.model</field>
<field name="groups_id"></field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="My Form">
<sheet>
<group>
<field name="field_1"/>
@sehrishnaz
sehrishnaz / odoo_server_action.py
Last active February 17, 2020 06:23
OdooServerAction Python Code
@api.multi
def get_filtered_record(self):
if self._context.get('params', False):
params = self._context.get('params', False)
if params.get('menu_id', False):
raise ValidationError(
"Attention:You are not allowed to access this page due to Security Policy. In case of any query, please contact ERP Admin or Configuration Manager.")
else:
return False
view_id_form = self.env['ir.ui.view'].search([('name', '=', 'your.form.view.name')])
@sehrishnaz
sehrishnaz / odoo_server_action.xml
Created January 2, 2020 07:50
OdooServerAction
<record id="server_action_any_name" model="ir.actions.server">
<field name="name">Any Name Goes Here</field>
<field name="condition">True</field>
<field name="type">ir.actions.server</field>
<field name="model_id" ref="model_your_model_name" />
<field name="state">code</field>
<field name="code">action=self.get_filtered_record(cr, uid, context.get('active_ids', []), context=context)</field>
</record>
<menuitem name="Your Menu Name" id="menu_any_name" action="server_action_any_name"/>
@sehrishnaz
sehrishnaz / openerp-server.conf
Last active February 17, 2020 06:28
openerp-server.conf
[options]
; This is the password that allows database operations:
; admin_passwd = admin
db_host = False
db_port = 5434
db_user = openpg
db_password = 123
dbfilter = .*
addons_path = D:\odoo-8.0-20171001\openerp\addons,D:\odoo-8.0-20171001\openerp\your_custom_addons
log_handler = [':INFO']
@sehrishnaz
sehrishnaz / odoo_get_addons_path.py
Created October 3, 2019 05:11
How to get addons path that saved in odoo configuration file
from openerp.tools import config
config = tools.config
dir = config['addons_path']