Thursday, September 14, 2023

python function to return multi views in odoo

In this blog we will explain how to create python function to return multi views in odoo for one model

For an example created custom tree view , custom form view and custom kanban view for the "res.partner" model with the bellow ids

tree view id = "res_partner_custom_tree_view"
form view id = "res_partner_custom_form_view"
kanban view id = "res_partner_custom_kanban_view"

and we created smart button on another model view which must call python function to open "res.partner" model with the previous views , so this function can be just like bellow  

def display_partners(self):
        tree_view_id = self.env.ref('module_name.res_partner_custom_tree_view')
        form_view_id = self.env.ref('module_name.res_partner_custom_form_view')
        kanban_view_id = self.env.ref('module_name.res_partner_custom_kanban_view')

        return {
            'type': 'ir.actions.act_window',
            'name': "string",
            'res_model': 'res.partner',
            'domain': [('id', 'in',self.get_partner_ids().ids)],
            'view_mode': 'tree,form',
            'views':[(tree_view_id.id,'tree'),(form_view_id.id,'form'),(,(form_view_id.id,'form').id,'kanban')],
            'target': 'current',
        }

Thursday, August 31, 2023

specific view for many2one field in odoo

 


In this blog we will explain how to add specific view for many2one field in odoo 

so to explain that let us say we created custom form view for the product unit of measure and we want to open it from uom_id field in product view just like at the image , so we must inherit the product from view , then add context attribute to uom_id field , just like bellow 

<xpath expr="//field[@name='uom_id']" position="attributes">
     <attribute name="context">
          {'form_view_ref':'custom_module_name.custom_form_view_id'}
     </attribute>
</xpath>


default view filter in odoo

 

 

In the blog we will explain how to add default view filter in odoo , just like the apps default filter in odoo apps view

Firstly :  inside the search view you must define your default filter with the right domain , for example let us say we want to add default filter in product view to display products that can be sold only , just as bellow

<filter name="can_be_sold" string="Can Be Sold" domain="[('sale_ok', '=', ture)]"/>

Secondly : pass you filter to view you want using context , just as bellow

<field name="context">{'search_default_can_be_sold':1}</field>

Thursday, August 24, 2023

ModuleNotFoundError: No module named 'psutil'

 
 I got this problem (ModuleNotFoundError: No module named 'psutil') when I was trying to run Odoo so I run the command bellow in-order to fix it
python -m pip install psutil

How to set postgresql password

 

In this blog we will explain How to set postgresql password

In order to set password for postgresql you have to open the terminal and run the comands bellow 

First :

    sudo -u postgres psql

Second

    \password postgres

Third : it will ask you to enter password then to enter it again , just like in         the image bellow 


 

 

multi views for one model in odoo

To explain how to create multi views for one model in Odoo

let us say that we create estate module which is depends on the project standard module and we want to store the estate project data inside the 'project.project' model from project module but it has different fields and view than the standard projects so 

first : we will inherit the "project.project" model and add selection field which we will use as domain inside the actions views 

# -*- coding: utf-8 -*-
from odoo import fields, models, api, _

class projectProject(models.Model):
    _name = 'project.project'
    _inherit = ['project.project','mail.thread']
    _description = 'Project models inherit'

    project_type = fields.Selection([
        ('project','Project'),
        ('estate_project','Estate Project')],
        default='project',
        string="Type"
    )

 

second : we will over write the standard projects action view to add domain in-order to display the records with "project_type = "project"

<record id="project.open_view_project_all" model="ir.actions.act_window">
            <field name="name">Projects</field>
            <field name="res_model">project.project</field>
            <field name="domain">[('project_type','=','project')]</field>
            <field name="context">{'default_project_type':'project'}</field>
            <field name="view_mode">kanban,form</field>
            <field name="view_id" ref="project.view_project_kanban"/>
            <field name="search_view_id" ref="project.view_project_project_filter"/>
            <field name="target">main</field>
            <field name="help" type="html">
                <p class="o_view_nocontent_smiling_face">
                    No projects found. Let's create one!
                </p><p>
                    Projects regroup tasks on the same topic and each have their own dashboard.
                </p>
            </field>
        </record> 


Third : we will create the estate project own views as bellow 

<record id="estate_project_form_view" model="ir.ui.view">
            <field name="name">auction.form</field>
            <field name="model">project.project</field>
            <field name="arch" type="xml">
                <form string="Estate Project">
                </form>
            </field>
        </record>

        <record id="estate_project_tree_view" model="ir.ui.view">
            <field name="name">estate.project.tree</field>
            <field name="model">project.project</field>
            <field name="arch" type="xml">
                <tree string="Estate Projects">
                </tree>
            </field>
        </record>

        <record model="ir.ui.view" id="estate_project_kanban_view">
            <field name="name">project.project.kanban</field>
            <field name="model">project.project</field>
            <field name="arch" type="xml">
                <kanban>
                </kanban>
            </field>
        </record>

        <record id="estate_project_act_window" model="ir.actions.act_window">
            <field name="name">Estate Projects</field>
            <field name="res_model">project.project</field>
            <field name="view_mode">kanban,tree,form</field>
            <field name="view_ids" eval="[(5, 0, 0),
                (0, 0, {'view_mode': 'tree', 'view_id': ref('estate_project_tree_view')}),
                (0, 0, {'view_mode': 'kanban', 'view_id': ref('estate_project_kanban_view')}),
                (0, 0, {'view_mode': 'form', 'view_id': ref('estate_project_form_view')})]"/>
            <field name="help" type="html">
                <p class="oe_view_nocontent_create">
                    There is no examples click here to add new Auction.
                </p>
            </field>
            <field name="domain">[('project_type','=','estate_project')]</field>
            <field name="context">{'default_project_type':'estate_project'}</field>
        </record>

        <menuitem
            name="Estate Projects"
            id="estate_project_menu"
            action="estate_project_act_window"
        />


ImportError: cannot import name 'utils'


 

     if you face this problem (ImportError: cannot import name 'utils') when you try to run odoo , you can fix it by using the commands bellow

pip install checkov

pip3 install checkov

python3.9 -m pip install checkov // for specific python version "3.9 as an example"

Odoo Invoice Qr code issues

There are two main issues must of us facing with the QR code in Odoo invoice & these issues are 1/ QR code displayed as broken image w...