Tuesday, November 26, 2019

calculate age from birthdate in odoo

ODOO 



here we know the birth date of the user (birth_date) and we want to calculate his age so let's do it 
  • add the birth date field and age field in your model as 
birth_date = fields.Date(string="Birth Date")
age_year = fields.Float(string="Years", compute='calculate_age')
age_month = fields.Float(string="Months", compute='calculate_age') 
age_day = fields.Float(string="Days", compute='calculate_age')
 

  • the add calculate_age() function to calculate the age and store it in age field 
@api.one 
def calculate_age(self):
        """
        function to calcolate the age of he user

        """

        if self.birth_date :

            birth_date = str(self.birth_date)

            current_date = str(fields.Date.today())



            birth_date_year_as_int =     int(birth_date[0]+birth_date[1]+birth_date[2]+birth_date[3])

            birth_date_month_as_int = int(birth_date[5]+birth_date[6])

            birth_date_day_as_int = int(birth_date[8]+birth_date[9])



            current_date_year_as_int = int(current_date[0]+current_date[1]+current_date[2]+current_date[3])

            current_date_month_as_int = int(current_date[5]+current_date[6])

            current_date_day_as_int = int(current_date[8]+current_date[9])



            period_years = current_date_year_as_int-birth_date_year_as_int

            period_months = current_date_month_as_int-birth_date_month_as_int

            period_days = current_date_day_as_int-birth_date_day_as_int



            months_list_1 = ['04','06','09','11']

            months_list_2 = ['01','03','05','07','08','10','12']



            if period_days < 0:

                if str(current_date_month_as_int) == '02':

                    if current_date_year_as_int%4 == 0:

                        period_days = 29+period_days

                    if current_date_year_as_int%4 != 0:

                        period_days = 28+period_days

                for index in range(0,4):

                    if current_date_month_as_int == int(months_list_1[index]):

                        period_days = 30+period_days

                for index in range(0,7):

                    if current_date_month_as_int == int(months_list_2    [index]):

                        period_days = 31+period_days

                period_months = period_months-1

            if period_months < 0:

                period_months = 12+period_months

                period_years = period_years-1



            self.age_year = period_years

            self.age_month = period_months

            self.age_day = period_days

Monday, November 25, 2019

Run odoo server

ODOO

configurations

   
 In this step we will see how to run Odoo server , change add-ons path , change default odoo port , create new database from the browser and from pg admin too 

how to run odoo server ?
  -open your terminal and enter the odoo server folder by the command (in my pc the odoo server is in the desktop )

   cd Desktop/odoo11 

  -then we have to run the command bellow to run odoo server  
  
   ./odoo-bin 

now we run the server as in the image bellow 



how to change addons path and why ? 

    by default odoo is call the standard modules which are located in odoo server folder/addons so when we run the server by the command above we can only see and install the standard modules , by what about installing our own modules ?
    to do that we only have two ways :
  • create our modules and put theme with the standard modules in the same path (odoo sever/addons) , of course the way is so easy but it's not right so we will not use it 
  • create our modules and put them in one folder and then call this folder with the standard modules folder (addons) as bellow 
let us say that we created folder by name custom_addons which is located in the desktop so to call this folder we must run odoo server by the command bellow

     ./odoo-bin --addons-path=/home/student/Desktop/odoo-11.1.1/addons,Desktop/custom_addons

how to change the default port (8069) for odoo server ? 

     as we know the odoo server is run on 8069 as default port , but can we change this port ?
 of course we can change it by any port we want by adding --xmlrpc-port= to the command above to become as  

     ./odoo-bin --addons-path=/home/student/Desktop/odoo-11.1.1/addons,Desktop/custom_addons -- xmlrpc-port=8080 

* here we had change the default port to 8080  

how to create new data base from the browser ?

    after running the odoo server we have to open our browser and write down localhost:8069 in the url "in we run the server in the default port" and press enter to get the page as in the image bellow 


then we have to write the name email and the password for our database (and demo data if we want ) , "I will write database : test , email:admin , password:123 and I will not load demo data"

how to create new database from pg admin ?

    to create database from the pg admin you have to follow the steps bellow 
  1. open the pg admin
  2. connect the pg admin to odoo server
  3. over the databases menu right click and chose new database 
  4. write down the name of the data base and owner of it (postgres role) as in the image bellow   

Watch onYouTube



PREVIOUS STEP         NEXT STEP

introduction to technical odoo


ODOO

introduction

 

    Before start our lessons to explain how we can use odoo to build ERP system for our organizations we have to have to know
  • What is odoo ?  
      Odoo is stand for On-Demand Open Object , and it's open source , web base  ERP  framework , built with Python , designed for small and medium-size companies with many standard modules like (account , hr , crm , stock , sale , purchase ...) which can be customize as you want , and also you can create your own modules from scratch .
  • What is ERP ? 
      ERP is stand for Enterprise Resource Planning and it's type of software that is used by the organizations to manage their activities in all levels inside the organization 
  • What is Python ? 
      Python is object-oriented, high-level programming language with dynamic semantics (ref) 
Now to start technical odoo first you have to have some knowledge with 
  • Python (Necessary)
  • xml (Necessary)
  • html , css and js (As possible)
Now let us start by install Odoo in Ubuntu 

to install odoo 9 in ubuntu  

to install odoo 11 in ubuntu   

* we will work with odoo 11 


Watch on YouTube


NEXT STEP 


Thursday, November 7, 2019

ValueError: cannot determine region size; use 4-item box




ODOO

pillow

     
This error you can find when you try to install new module in openerp 7 and it can be caused by pip pillow package version , so you have to uninstall the current version an din install 3.4.2 version by the following commands 

$ pip uninstall pillow
$ pip install Pillow==3.4.2

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