cd /odoo-installed folder
python3 odoo-bin shell -d db-name--addons-path=/your-addons-path
Then run the bleow Python script
For Install
self.env['ir.module.module'].search([('name', '=', 'moule-name')]).button_immediate_install()
For Unistall
self.env['ir.module.module'].search([('name', '=', 'moule-name')]).button_immediate_uninstall()
Flask WTForms DateField returning None
from wtforms import DateField
fromdate = DateField(‘From Date’,format=’%d-%m-%Y’,validators=[InputRequired()])
Solved. Remove remove the format
parameter.
like
fromdate = DateField(‘From Date’,validators=[InputRequired()])
Making Fields Visible and Invisible based on One2many field values in Odoo
Py File
from odoo import models, fields, api, _
from odoo.exceptions import UserError
class AccountPaymentRegister(models.TransientModel):
_inherit = ‘account.payment.register’
# == Inherit fields ==
cheque_date = fields.Date(String="Cheque Date", default=fields.Date.context_today)
cheque_no = fields.Char(String="Cheque No.")
rec_bank = fields.Char(String="Receive Bank")
payment_method_code = fields.Char(String="Payment Method code")
is_bank_selected = fields.Boolean(string="is bank selected")
# Journal ID - Many2one
# If Journal ID is Bank is is_bank_selected become TRUE.
@api.onchange('journal_id')
def _change_journal_id(self):
if self.journal_id.name == 'Bank':
self.is_bank_selected = True
else:
self.is_bank_selected = False
XML file
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record id="view_account_payment_register_mesco_inherit_form" model="ir.ui.view">
<field name="name">account.payment.register.mesco.inherit.form</field>
<field name="model">account.payment.register</field>
<field name="inherit_id" ref="account.view_account_payment_register_form"/>
<field name="arch" type="xml">
<field name="communication" position="after">
<field name="is_bank_selected" invisible="1"/>
<field name="cheque_date" attrs="{'invisible': [('is_bank_selected', '!=', True)]}"/>
<field name="cheque_no" attrs="{'invisible': [('is_bank_selected', '!=', True)]}"/>
<field name="rec_bank" attrs="{'invisible': [('is_bank_selected', '!=', True)]}"/>
</field>
</field>
</record>
</data>
</odoo>
Hide or remove Fields from Odoo Filter(Add Custom Filter) and Group By(Add Custom Group).
#You can easily hide or remove fields from odoo filter by inheriting function fields_get()
@api.model
def fields_get(self, fields=None):
show = ['file_name','partner_id','line_partner_ids','common_message','state','upload_type']
group = ['partner_id','state','upload_type']
res = super(SendDocument, self).fields_get()
for field in res:
res[field]['selectable'] = False
res[field]['sortable'] = False
for field in show:
res[field]['selectable'] = True
for field in group:
res[field]['sortable'] = True
return res
How to drop database(PostgreSQL) if there are active connections to it(PostgreSQL database is being accessed by other users)?
- PostgreSQL 9.2 and above:
SELECT pg_terminate_backend(pg_stat_activity.pid)
FROM pg_stat_activity
WHERE pg_stat_activity.datname = 'database_name' -- ← change this to your DB
AND pid <> pg_backend_pid();
OR
- PostgreSQL 9.1 and below:
SELECT pg_terminate_backend(pg_stat_activity.procpid)
FROM pg_stat_activity
WHERE pg_stat_activity.datname = 'database_name' -- ← change this to your DB
AND procpid <> pg_backend_pid();
sudo su postgres
psql
drop database database_name;
Get product.template ids from sale.order product.product
sale_order = self.env[‘sale.order’].browse(id)
products = sale_order.mapped(‘order_line.product_id.product_tmpl_id’)
Get product.template ids from sale.order
sale_order = self.env[‘sale.order’].browse(id)
products = sale_order.mapped(‘order_line.product_id.product_tmpl_id’)
Search(grep) Ubuntu, but only certain file extensions
grep -R “<sample search>” –include=*.js
Change menu name and action name in Odoo
<!– Delete the Purchase Agreements –>
<delete model=”ir.ui.menu” id=”menu_purchase_requisition_pro_mgt” />
<!– Create the menu the Material Request –>
<menuitem
name=”Material Request” id=”menu_purchase_requisition_pro_mgt”
sequence=”10″
parent=”purchase.menu_procurement_management”
action=”purchase_requisition.action_purchase_requisition” />
<!– Update the action name Material Request –>
<record id=”purchase_requisition.action_purchase_requisition” model=”ir.actions.act_window”>
<field name=”name”>Material Request</field>
</record>aterial Request Material Request