Odoo How to install or uninstall a Odoo module from command line or using python

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()

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)?

  1. 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

  1. 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;

Odoo – Hide Cost Price and Sale Price of product from Product master form,tree and kanban views – for sales user.

<record id="ep_product_template_form_view" model="ir.ui.view">            
	<field name="inherit_id" ref="product.product_template_form_view"/>
	<field name="model">product.template</field>            
	<field name="arch" type="xml">
		<xpath expr="//field[@name='list_price']" position="attributes">
			<attribute name="groups">sales_team.group_sale_manager</attribute>		
			
		</xpath>
		<xpath expr="//label[@for='standard_price']" position="attributes">
			<attribute name="groups">sales_team.group_sale_manager</attribute>		
			
		</xpath>
		<xpath expr="//div[@name='standard_price_uom']" position="attributes">
			<attribute name="groups">sales_team.group_sale_manager</attribute>	
			
		</xpath>
		<xpath expr="//div[@name='standard_price_uom']" position="attributes">
			<attribute name="groups">sales_team.group_sale_manager</attribute>	
			
		</xpath>     
	</field>
</record> 

<record id="ep_product_template_tree_view_cost_price" model="ir.ui.view">			
	<field name="model">product.template</field>
	<field name="inherit_id" ref="product.product_template_tree_view" />
	<field name="arch" type="xml">
		<xpath expr="//field[@name='standard_price']" position="attributes">
			<attribute name="groups">sales_team.group_sale_manager</attribute>		
			
		</xpath>
	</field>
</record>
<record id="ep_view_template_property_form" model="ir.ui.view">            
	<field name="model">product.supplierinfo</field>
	<field name="inherit_id" ref="product.product_supplierinfo_form_view"/>
	<field name="arch" type="xml">
		<xpath expr="//label[@for='price']" position="attributes">
			<attribute name="groups">sales_team.group_sale_manager</attribute>	
			
		</xpath>
			
	</field>
</record>
<record id="ep_product_supplierinfo_tree_view" model="ir.ui.view">            
	<field name="model">product.supplierinfo</field>
	<field name="inherit_id" ref="product.product_supplierinfo_tree_view"/>
	<field name="arch" type="xml">
		<xpath expr="//field[@name='price']" position="attributes">
			<attribute name="groups">sales_team.group_sale_manager</attribute>	
			
		</xpath>
			
	</field>
</record>
<record id="ep_product_template_kanban_view" model="ir.ui.view">            
	<field name="model">product.template</field>
	<field name="inherit_id" ref="product.product_template_kanban_view"/>
	<field name="arch" type="xml">
		<xpath expr="//div[@class='oe_kanban_details']/ul/li" position="attributes">
			<attribute name="groups">sales_team.group_sale_manager</attribute>                    
		</xpath>                    
	</field>
</record>

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