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

Wednesday, June 16, 2021

cached report in odoo

    Let us say that we have report in odoo and we print it for the first time and then made changes in the data and after we print the report again it still show the first time report 

    For an example : we create an invoice with 1000 usd and register payment with 400 usd and print the invoice and the report show the payment , then we made another payment with 450 usd and when we print the report again it still show the first payment only and review the code and there is no error ???

    Now to fix this we have to go to settings/technical/actions/reports and search for the invoice report and open it to find a field with the name "Reload from Attachment " and set it to false as in the image bellow


Wednesday, March 31, 2021

order recordset in odoo

 

 

In this blog we will explain how to order recordset in odoo with the search() function

      So let us say we have object "student.student" and we have to build function that must return all student with age = 12 years and sort the ids with the id of the record, so we can build it as bellow

def student_filter(self):
     student_ids = self.env['student.student'].search([(' age','=',12)], order='id')
     return student_ids

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