Monday, July 4, 2022

Load image from url in odoo


In this blog we will give an example how to load image from url in odoo using http controller function

    so let us say that we made an integration with external api to get new customer data with is include image_url field and we want to save this image into odoo database , so first we must create function that takes the image_url as an input and return the image as data , second we can pass the image data to image field in res.partner object in odoo to create new customer with image , and the function can be just as bellow 

 

def load_image_from_url(self, url):
        data = base64.b64encode(requests.get(url.strip()).content).replace(b'\n', b'')
        return data

current url in odoo


 

if we want to get the server URL for the current odoo module we can get it as below
 

#for python model 

server_url = self.env['ir.config_parameter'].get_param('web.base.url')

 

#for http.controller

1/ from odoo.http import request

2/ server_url = request.env['ir.config_parameter'].get_param('web.base.url')

Saturday, April 16, 2022

TypeError: Object of type datetime is not JSON serializable

 

This error "TypeError: Object of type datetime is not JSON serializable" happens when we try to convert data with date time into json dictionary , so to fix this error we have to convert the data to string first then put it in the dictionary and then we can convert the dictionary to json format
...
for example if we want to create api with odoo to return the data for sale order , so we can put the sale order data as bellow 

order_data = {
            'id':order_id.id,
            'name':order_id.name,
            'customer':{'id':order_id.partner_id.id,'name':order_id.partner_id.name},
            'salesperson':{'id':order_id.user_id.id,'name':order_id.user_id.name},
            'date_order':str(order_id.date_order),
            'state':order_id.state,
            'products':order_products,
            'untaxed_amount':order_id.amount_untaxed,
            'total_tax': order_id.amount_tax,
            'total_amount':order_id.amount_total,
     }

return Response(json.dumps(order_data),headers=headers)

ssh

In this blog we will explain some commands to deal with remote server from ubuntu terminal using SSH

1: Connect to remote server using ssh by the command bellow 

     sudo ssh remote_user_name@remote_ip

 

2: Connect to remote server with key.pem using ssh by the command bellow

    sudo ssh remote_user_name@remote_ip -i /path/key.pem

 

3/ copy folder with it's content from the remote server to local device

    sudo scp -r remote_user@remote_server_ip:/opt/example /home/local_folder

    sudo scp -i /path/key.pem -r remote_user@remote_server_ip:/opt/example /home/local_folder

Monday, September 20, 2021

ModuleNotFoundError: No module named 'psycopg2'


 I got this error when I'm trying to run odoo server 


ModuleNotFoundError: No module named 'psycopg2'


so to fix it , I run the commands bellow

sudo apt-get update
sudo apt-get install libpq-dev
sudo pip3 install psycopg2-binary
 & for runing odoo 15.0 with python 3.8 we can use 
sudo python3.8 -m pip install --upgrade psycopg2-binary 

The style compilation failed


When I'm trying to run odoo server , I'm facing this error The style compilation 

failed, see the error below. Your recent actions may be the cause, please try reverting the changes you made

So to fix it I run the commands bellow

sudo pip3 install libsass==0.12.3
sudo apt install python3-libsass

Monday, August 30, 2021

Display current company data

 In this blog we will explain how to display current company data in web page in odoo 14


First we can get the current company in the web page template by using
request.env.user.company_id


so we can show the current company logo by using 

<img t-if="request.env.user.company_id.logo" t-att-src="image_data_uri(request.env.user.company_id.logo)" style="max-height:45pt;max-width:90%" alt="Company Logo"/>
 
and we can show the current company name by using

<span t-esc="request.env.user.name"/>

and so on to display each field in the model res.company

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