Wednesday, October 21, 2020

How to use many2one field in demo data

Odoo

Demo Data

 

 

 In this blog we will explain how to add value for many2one field in the xml demo data file in odoo , so let us start 

First let us say we have python object by the name 'report.create' which is contain the model_id field which is many2one field from 'ir.model' as bellow 

class ReportCreater(models.Model):
    _name = 'report.creater'

    model_id = fields.Many2one(
        'ir.model', string='Model', required=True, ondelete="cascade",
        help="The type of document this template can be used with")

and we want to create demo data for this object and the records from the demo data must contain the model_id field , so we can do it as bellow 

<odoo>
  <data noupdate="0">
    <record id="simple_contract_template" model="desined.report.template">
      <field model="ir.model" name="model_id" search="[('model', '=', 'res.partner')]"/>
    </record>
  </data>
</odoo>

 

*NOTES

  • 'ir.model' this object contain all models in the data base
  • search="[('model', '=', 'res.partner')] in this step we made search in the 'ir.model' object to return record from it , and in that record the value of model field must be 'res.partner'
  • 'ir.model' contain the model field which is char field

Monday, October 19, 2020

defined as ondelete='restrict'

I face the error bellow we I tried to install some module in odoo 14 , the error is 

ValueError: Field mark_id of model rep.template is defined as ondelete='restrict 

 

of course ! , I have model by name 'rep.template', in which that I have many2one file defined as bellow 

mark_id = file.Many2one('rep.mark', string='Mark')

and I face the error above because of this field , so to fix this error I rewrite this field as bellow

mark_id = file.Many2one('rep.mark', string='Mark', ondelete="cascade")



github from terminal

GitHub

 

 

 On this topic we will explain how to deal with github from terminal 

First : if you don't have account on github , you can create it from here , then follow me :)

 

Login to git hub from terminal by the command 

git config --global user.email "your_email_address@example.com" 

 

Initialized empty git repository 

git init


Remove the initialized empty repository 

rm -rf .git


Show repository activity log

git log


Clone files from the repository in the current folder 

git clone repo_url . // the . means that we want to clone files in the current directory

 

View the information about the repository 

git remote -v 


List all branches in the repository 

git branch -a


Show the changes that we had made to the code 

git diff

 

Add all working files to the staging

git add -A


Commit the add files in the local device 

git commit - m "Some Message :)"


Push the committed changes locally to the remote repository at git.com (2 steps < pull and push >)

git pull origin branch_name // to check if any other developer make any changes in the repository (origin is the name of the remote repository)

git push origin branch_name // to push our changes to the repository (branch)

 

Create new branch 

 git branch branch_name  // this will create new branch in the current repository 

 

Switch the current working with branch 

git checkout branch_name 


Push changes to specific specific branch in the remote repository

git push -u origin branch_name // #not : we can to pull by this way too

 

Merge a  branch with the current branch 

git branch --merged

git merge branch_name


Delete Branch

git branch -d branch_name // this will delete the branch from the local 

git push origin --delete branch_name // this will push the deleted branches to the remote repository 



Note :

you can download the ref form here




Sunday, October 18, 2020

nginx with odoo 14

Odoo

Nginx 


 


I this topic we will explain how to configure nginx for localhost odoo server by steps, but before that you need to install nginx and running odoo server and then follow the steps 

First : go to /etc/nginx/enable-sites and add new configuration file by the name odoo14.localhost which will configure your nginx for odoo local server

Second : open the file /etc/hosts and add the localhost (127.0.0.1) to the file as bellow 

Third : add the ssl certification by going to etc/ssl and create new folder by name nginx and inside it run the command bellow 

openssl req -x509 -new -newkey rsa:2048 -nodes -keyout odoo.key -days 9999 -out odoo.crt

###

 

odoo14.localhost file will be as

#odoo server
  upstream odoo {
   server 127.0.0.1:8069;
  }
  upstream odoochat {
   server 127.0.0.1:8072;
  }
  # http -> https
  server {
     listen 80;
     #server_name odoo.mycompany.com;
     rewrite ^(.*) https://$host$1 permanent;
    }
  server {
   listen 443;
   #server_name odoo.mycompany.com;
   proxy_read_timeout 720s;
   proxy_connect_timeout 720s;
   proxy_send_timeout 720s;
   # Add Headers for odoo proxy mode
   proxy_set_header X-Forwarded-Host $host;
   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
   proxy_set_header X-Forwarded-Proto $scheme;
   proxy_set_header X-Real-IP $remote_addr;
# SSL parameters
   ssl on;
   ssl_certificate /etc/ssl/nginx/odoo.crt;
   ssl_certificate_key /etc/ssl/nginx/odoo.key;
   ssl_session_timeout 30m;
   ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
   ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA';
   ssl_prefer_server_ciphers on;
  # log
   access_log /var/log/nginx/odoo.access.log;
   error_log /var/log/nginx/odoo.error.log;
   # Redirect longpoll requests to odoo longpolling port
   location /longpolling {
   proxy_pass http://odoochat;
   }
   # Redirect requests to odoo backend server
   location / {
     proxy_redirect off;
     proxy_pass http://127.0.0.1:8069;
   # common gzip
   gzip_types text/css text/less text/plain text/xml application/xml application/json application/javascript ;
}
}

 

The hosts file will be as

127.0.0.1    localhost
127.0.1.1    ahmed-HP-EliteBook-8460p
172.0.0.1       localhost.odoo

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

 

The odoo configuration file will be as 

[options]
; This is the password that allows database operations:
admin_passwd = Ahmmar
db_host = False
db_port = 5432
db_name = False
db_user = ahmed
xmlrpc_port = 8069
longpolling_port = 8072
db_password = False
addons_path = /home/ahmed/Desktop/Odoo_14/addons, /home/ahmed/Desktop/Odoo_14/addons/custom_addons
proxy_mode = True
dbfilter = ^%h$
logfile = /var/log/odoo14/odoo14-service.log


###

Here are some important commands

nginx -t >> to test if the nginx conf files are okay

systemctl restart nginx.service >> to restart nginx 

sudo su -- >> to login as root user


*NOTE

after doing the above configuration you have to restart the odoo server and go to your browser and open https://localhost which will open the creation page for new database

Tuesday, October 13, 2020

Integurate Odoo with Nginx

Nginx


 

We use nginx with odoo as reverse proxy act as an intermediary between the clients and the Odoo server , and in this topic we will explain how to use nginx , ssl and reverse proxy to odoo 

Now as we know , odoo is web base and that means we can access the odoo server from the internet if it has  public ip address , so why we use Nginx as reverse proxy ?

Answer : because of

Reverse proxy benefits

  • Load Balancing
  • SSL Termination
  • Caching
  • Compression
  • Serving Static Content

 

Before configure nginx to be reverse proxy to odoo you have to check the following points 

  • you have domain pointing to your odoo server 
  • you have installed nginx on your computer 
  • you have ssl certification installed for your domain 
 

so to configure your odoo server with nginx follow the steps bellow 


  • Edit nginx configuration file

    open the file bellow and change odoo.example.com to your domain
    /etc/nginx/sites-enabled/odoo.example.com
     
upstream odoo {
 server 127.0.0.1:8069;
}

upstream odoo-chat {
 server 127.0.0.1:8072;
}

server {
    server_name odoo.example.com;
    return 301 https://odoo.example.com$request_uri;
}

server {
   listen 443 ssl http2;
   server_name odoo.example.com;

   ssl_certificate /path/to/signed_cert_plus_intermediates;
   ssl_certificate_key /path/to/private_key;
   ssl_session_timeout 1d;
   ssl_session_cache shared:SSL:50m;
   ssl_session_tickets off;

   ssl_dhparam /path/to/dhparam.pem;

   ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
   ssl_ciphers 'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-
AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-
AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-
AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:
ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-
SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:
ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:
AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS';
   ssl_prefer_server_ciphers on;

   add_header Strict-Transport-Security max-age=15768000;

   ssl_stapling on;
   ssl_stapling_verify on;
   ssl_trusted_certificate /path/to/root_CA_cert_plus_intermediates;
   resolver 8.8.8.8 8.8.4.4;

   access_log /var/log/nginx/odoo.access.log;
   error_log /var/log/nginx/odoo.error.log;

   proxy_read_timeout 720s;
   proxy_connect_timeout 720s;
   proxy_send_timeout 720s;
   proxy_set_header X-Forwarded-Host $host;
   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
   proxy_set_header X-Forwarded-Proto $scheme;
   proxy_set_header X-Real-IP $remote_addr;

   location / {
     proxy_redirect off;
     proxy_pass http://odoo;
   }

   location /longpolling {
       proxy_pass http://odoo-chat;
   }

   location ~* /web/static/ {
       proxy_cache_valid 200 90m;
       proxy_buffering    on;
       expires 864000;
       proxy_pass http://odoo;
  }

  # gzip
  gzip_types text/css text/less text/plain text/xml application/xml application/json application/javascript;
  gzip on;
}

  • restart nginx server

sudo systemctl restart nginx
  •  Change the binding interface

this step is optional but it's good for security , and we make it because odoo server by default listening of port 8069 on all interfaces , and by adding this step we will disable direct access to odoo server , and we can do that by adding the lines bellow inside odoo configuration file 
xmlrpc_interface = 127.0.0.1
netrpc_interface = 127.0.0.1
 
  • Restart the odoo server

###
 
read aslo 
 
 

Nginx

 
 

Before explain Nginx we have to explain many things , now let us say we want to visit google.com so we will open our browser and type the URL www.google.com and but actually what is happening ?

when we visit any web site we actually visit a computer or a WEB SERVER , so the web server is the computer that has a public ip and domain and it can provides web pages , so any web site that we visit can be a computer (server) or more than on computer (servers) 
 
 
Web server 
    is a computer that can deliver requested web pages , and it has ip address and domain name  
 

now how to make my computer work as web server ?

To make any computer works as a web server we have to do two main things 
     _ Use web server software , which is that software make your computer act as web server , and these software can be (XAMPP , Nginx, microsoft IIS ... etc)
     _ connect your computer to the global network  

 

What is Nginx ?

NGINX is open source software for web serving, reverse proxying, caching, load balancing, media streaming, and more. It started out as a web server designed for maximum performance and stability. In addition to its HTTP server capabilities, NGINX can also function as a proxy server for email (IMAP, POP3, and SMTP) and a reverse proxy and load balancer for HTTP, TCP, and UDP servers. (ref)


How to install nginx on ubuntu ?

open your terminal and write down the commands bellow 

       sudo apt-get update

       sudo apt install nginx

 after install it , you can check it by open "localhost" on your browser , and if it open the page on the image above that means it installed successfully 


Create your website with nginx

Default page is placed in /var/www/html/ location. You can place your static pages here, or use virtual host and place it other location


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