Showing posts with label python. Show all posts
Showing posts with label python. Show all posts

Thursday, 14 August 2025

ModuleNotFoundError: No module named 'psycopg2'

 Odoo 18: 

Traceback (most recent call last):

File "/home/bodedra/odoo18/demo/src/odoo/./odoo-bin", line 5, in <module>

import odoo

File "/home/bodedra/odoo18/demo/src/odoo/odoo/__init__.py", line 49, in <module>

_monkeypatches.patch_all()

File "/home/bodedra/odoo18/demo/src/odoo/odoo/_monkeypatches/__init__.py", line 28, in patch_all

from .lxml import patch_lxml

File "/home/bodedra/odoo18/demo/src/odoo/odoo/_monkeypatches/lxml.py", line 6, in <module>

from odoo.tools import parse_version

File "/home/bodedra/odoo18/demo/src/odoo/odoo/tools/__init__.py", line 10, in <module>

from . import template_inheritance

File "/home/bodedra/odoo18/demo/src/odoo/odoo/tools/template_inheritance.py", line 9, in <module>

from odoo.tools.translate import LazyTranslate

File "/home/bodedra/odoo18/demo/src/odoo/odoo/tools/translate.py", line 35, in <module>

from psycopg2.extras import Json

ModuleNotFoundError: No module named 'psycopg2'


Resolved with

pip3.12 install psycopg2-binary

 

Monday, 25 September 2017

ImportError: No module named googleapiclient

Recently, I have faced ImportError: No module named googleapiclient and I would like to share knowledge to fix that problem.

Open terminal and run following command to resolve it:

     sudo pip install --upgrade google-api-python-client

Tuesday, 7 February 2017

ImportError: No module named packaging.version

Recently, I face ImportError: No module named packaging.version  and I would like to share knowledge to fix that problem.

Terminal:

pip --version
pip 1.5.4 from /usr/lib/python2.7/dist-packages (python 2.7)



I am trying to upgrade pip

python -m pip install -U pip

    Traceback (most recent call last):
      File "<string>", line 3, in <module>
      File "setuptools/__init__.py", line 12, in <module>
        import setuptools.version
      File "setuptools/version.py", line 1, in <module>
        import pkg_resources
      File "pkg_resources/__init__.py", line 70, in <module>
        import packaging.version
    ImportError: No module named packaging.version
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):

  File "<string>", line 3, in <module>

  File "setuptools/__init__.py", line 12, in <module>

    import setuptools.version

  File "setuptools/version.py", line 1, in <module>

    import pkg_resources

  File "pkg_resources/__init__.py", line 70, in <module>

    import packaging.version

ImportError: No module named packaging.version



Solution:

sudo su root

apt-get purge -y python-pip


wget https://bootstrap.pypa.io/get-pip.py


python ./get-pip.py


apt-get install python-pip



Wednesday, 11 May 2016

How to find last day of current month and first day of current month in Python ?

For finding last day of current month, we need to use calendar and datetime python libraries.

Following is an example of it.

>>> import calendar
>>> import datetime

>>> calendar.mdays[datetime.date.today().month]
31

>>> datetime.datetime.today().replace(day=1)
It will replace today's date with starting date of month.

I hope you like this article. Share your views to improve content. Happy Learning !!!

Sunday, 27 September 2015

Email validation in Odoo

This article will help us to validate Email field on Partner form.

First of all, we need to understand argument of _constraints.

    _constraint has list of arguments in which

          1. Method is name,

          2. Warning/Error message and

          3. List of field name.

Method will be fire based on, change of field value given as third argument in _constraint.

Now we need to set constraint for Email field.

Here is code for constraint.
  
    _constraints = [
        (_validate_email, 'Please enter a valid email address.', ['email']),
    ]

Here is code for method.

    @api.multi
    def _validate_email(self):
        for partner in self:
            if re.match("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$", partner.email) == None:
                return False
        return True

NOTE:

         Warning/Error message will be populate, only when method will return False.

I hope you like this article. Share your views to improve content. Happy Learning !!!

Monday, 9 February 2015

How related field work in Odoo 8, 9, and 10?


Let's take an example of Sale Order Line. Scenario is like when we add Product in sale order line at time, the Product Category name should be fill up. For that we need to do two  things.

  1. add related field in 'sale.order.line' and give it in view at proper place
  2. need to override onchange of product, if we don't want to override the onchange than at the time of record save it will also save the product category name.

Here is .py code:

Old API:

class sale_order_line(osv.Model):
    _inherit = 'sale.order.line'

    _columns = {
        'product_categ_name': fields.related('product_id', 'categ_id', 'name', type='char', string='Product Category', store=True, readonly=True),
}

New API:

from openerp import api, fields, models, _

class SaleOrderLine(models.Model)
    _inherit = 'sale.order.line'

    product_categ_name = fields.Char(related='product_id.categ_id.name', string='Product Category', store=True, readonly=True)

Here is .xml file

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
   
        <record id="view_product_category_related_sale_line" model="ir.ui.view">
            <field name="name">view.product.category.related.sale.line</field>
            <field name="model">sale.order</field>
            <field name="inherit_id" ref="sale.view_order_form" />
            <field name="arch" type="xml">
                <xpath expr="//field[@name='order_line']/form/group/group/field[@name='product_id']" position="after">
                    <field name="product_categ_name"/>
                </xpath>
            </field>
        </record>

    </data>
</openerp>


Here is screen shot of it


More about on related field, take a look here

I hope you like this article. Share your views to improve content. Happy Learning !!!

Youtubde Video 

Wednesday, 10 December 2014

How to create constraints in OpenERP v7, Odoo 8,9, and 10 ?

This will help you to create a constraints in OpenERP.

_constraint is a pre-define field in OpenERP. It is used for adding a constraint on the object.

It takes list of tuple as its argument. The tuple inside the list contains three parameter.
  1. Method (to check the constraint)
  2. The Message (Pop-up message for End User)
  3. List of Fields (fields to apply the constraint)
_constraint will fire if the condition returns False on creation and updation of the record and display the message.

Here is an example of integer data-type. It's fire a constraint if length is not positive.

Here is .py side code:

Old API:
 
from openerp.osv import fields, osv
class res_partner(osv.Model):
    _inherit = 'res.partner'

    _columns = {       
        'length': fields.integer('Length', size=64),
    }

    def _check_number(self, cr, uid, ids, context=None):
        for partner in self.browse(cr, uid, ids, context=context):
            if partner.length < 0:
                return False
        return True    
   
    _constraints = [
        (_check_length, 'Length must be Positive.', ['length'])
    ]

New API:

from openerp.exceptions import ValidationError
from openerp import api, fields, models, _

class Partner(models.Model):
    _inherit = 'res.partner'

    @api.one
    @api.constrains('length')
    def _check_length(self):
        if self.length < 0:
            raise ValidationError("Length must be Positive.")

    length = fields.integer('Length', size=64)

Here is .xml side code:

<?xml version="1.0"?>
<openerp>
    <data>
        <!-- res partner form view-->
        <record id="view_res_partner_extended_form" model="ir.ui.view">
            <field name="name">res.partner.extended.form.view</field>
            <field name="model">res.partner</field>
            <field name="inherit_id" ref="base.view_partner_form"/>
            <field name="arch" type="xml">
                <field name="email" position="after">
                    <field name="length"/>
                </field>
            </field>
        </record>
    </data>
</openerp>


I hope you like this article. Share your views to improve content. Happy Learning !!!

Youtube Video 

Tuesday, 9 December 2014

How to install Wkhtmltopdf package in Odoo?

This will help for Ubuntu system.
 
Once we install Odoo v8 and try to print report. WE may see notice at right hand side in black box with message.

You should upgrade your version of Wkhtmltopdf to at least 0.12.0 in order to get a correct display of headers and footers as well as support for table-breaking between pages.
   
That means Odoo v8 support the 0.12.0 or greater  than version of Wkhtmltopdf. So need to just follow the below steps:

cd /tmp
wget http://sourceforge.net/projects/wkhtmltopdf/files/archive/0.12.0/wkhtmltox-linux-amd64_0.12.0-03c001d.tar.xz

tar -xvf wkhtmltox-linux-amd64_0.12.0-03c001d.tar.xz
cd wkhtmltox
cd bin/
mv wkhtmltopdf /usr/bin/

mv wkhtmltoimage /usr/bin/
cd ..
cd lib/
mv libwkhtmltox.so.0 /lib64
mv libwkhtmltox.so.0.12 /lib64
mv libwkhtmltox.so.0.12.0 /lib64

cd /usr/bin/
sudo chown root:root wkhtmlto*
cd /lib64
sudo chown root:root libwkhtmlto*
sudo chown -h root:root libwkhtmlto*

Now reboot the system using this command.

sudo reboot

After than we need to start the Odoo server, Login in database and follow the below GUI step:

Configuration -> Parameter -> Parameters Systems
Create a new record like :

    Tipe : webkit_path
    Value : /usr/bin/wkhtmltopdf
   
If you show above record in your Odoo System that means now everything is fine.

I hope you like this article. Share your views to improve content. Happy Learning !!!

Youtube Video

Monday, 8 December 2014

How to install OpenERP/Odoo from Github?


I would like to share with you, how to Install Odoo(formerly OpenERP) from github on Ubuntu system.

Odoo Github

1. First we need to install git in our Ubuntu system, for that open our terminal or or hit Ctrl+Alt+t

 a) First we need to update apt source list
  
     sudo apt-get update

 b) Upgrade apt source package

     sudo apt-get upgrade

c) Now install git

    sudo apt-get install git

2. Install Python packages  which required for Odoo installation

sudo apt-get install graphviz ghostscript postgresql-client \
python-dateutil python-feedparser python-matplotlib \
python-ldap python-libxslt1 python-lxml python-mako \
python-openid python-psycopg2 python-pybabel python-pychart \
python-pydot python-pyparsing python-reportlab python-simplejson \
python-tz python-vatnumber python-vobject python-webdav \
python-werkzeug python-xlwt python-yaml python-imaging


sudo apt-get install gcc python-dev mc bzr python-setuptools python-babel \
python-feedparser python-reportlab-accel python-zsi python-openssl \
python-egenix-mxdatetime python-jinja2 python-unittest2 python-mock \
python-docutils lptools make python-psutil python-paramiko poppler-utils \
python-pdftools antiword postgresql


3. Install PostgreSQL database

    sudo apt-get install postgresql

4. Install Pgadmin

    sudo apt-get install pgadmin

5. Create User into Postgres Database Odoo

    sudo -u postgres createuser -s odoo

6. Download Odoo from Github to your system

a) make directory in home

    sudo mkdir home/openerp-v8

b) move to  directory

    cd home/openerp-v8

c) Download odoo from Github

    sudo git clone https://github.com/odoo/odoo.git

7. Once finish a download need to run odoo server 

a) Go to oddo path

   cd home/openerp-v8/odoo

b) Run a odoo server

./openerp-server


8. To check Odoo installation is perfectly work  on your system so for that  just open browser type http://localhost:8069

9. Odoo login screen. Currently it will show below screen because first time we don't have database. 

Odoo Database Manager

I hope you like this article. Share your views to improve content. Happy Learning !!!

ModuleNotFoundError: No module named 'psycopg2'

  Odoo 18:  Traceback (most recent call last): File "/home/bodedra/odoo18/demo/src/odoo/./odoo-bin", line 5, in ...