Tuesday, December 3, 2019

create module in odoo

ODOO

odoo mdule

 

 In this step we will explain how to build simple empty module and the data types in odoo

how to start build your module

odoo module is afolder that contain two files , so to create new module me must start with the steps bellow 

    - create new folder with name "module_name"
    - inside it create file with name "__init__.py"
    - inside it create another file with name "__manifest__.py"
now create  __manifest__.py as bellow 
    # -*- coding: utf-8 -*-
{
    'name' : 'clinic
',
    'version' : '1.1',
    'summary': 'clinic
erp system',
    'sequence': 10,
    'description': """
        manage
patient data 
        doctors data
        Patient dormitory data
     """,
    'category': 'Health',
    'author': 'Shilal,
    'website': 'https://shilalg.blogspot.com',
    'images' : [],
    'depends' : [],
    'data': [
    ],
    'demo': [
    ],
    'installable': True,
    'active': True,
}

 
Now let us explain what that is mean  
first __manifest__ file is contain the data of the module so 
  'name' : 'clinic', is define the name for our module
  'version' : '1.1', the current version for this module , I use it when I have more than one version for my module 
 'summary': short description for your module
 'description': description for your module and the tasks that your module do  
 'category': the category that your module belong to 
 'author': the company or the engineer who build the module
 'website': EG  the web site of the company or the engineer who build the module 
 'images' : the image for your module
 'depends' : any other module that must be installed in the system to make your module work (other modules name)
 'data': here we call the xml files in which we made our views 

now we will create empty file by name __init__.py , then our module will be created then we can install it by following the steps bellow 
  • restart the Odoo server (be sure that you call the directory which contain your modules with the run command by editing the addons path just like we explain) 
  • go to your browser and login to your database 
  • then go to setting to activate the developer mode 
  • the go to apps menu and click on update app list menu (load your module )
  • the search for your module by it's name in apps view and install it 


Data types :
Numeric : on which we are storing numbers and it has two types
     Integer > on which we store integers
     Float > on which we can store numbers with decimal part
Textual : on which we can store text data, and it has three types
     Char : on which we can store string maximum 255 characters
     Text : on which we can store string and it view as text area with unlimited characters
     Html : on which we can store string but it view as text editor
Date : on which we can store date and it has two types
     Date : on this field we can enter the date only without the time (month, day ,year)
     Datetime : on this field we can enter date and time too(month , day ,year hours ,minutes , seconds)
Boolean : has one type by name Boolean which can has True or False vale only
Binary : has one type too my name Binary in which we can store binary date (docs , images , sounds , videos …)
Selection : it also has one type by name selection and in it the user will select one value from the values in this field
Relational Fields : on this type we store the relation between objects , and we have three types of relational fields
    One2many > just when we say there are one record in object A will has relations with many records in object B just like (in the table of doctors one doctor will take care of more than one patient)
    Many2one > the reverse of One2many
    Many2many > in this type many records in object A will has relation with many records in object B just like (more than one medication will be given for many patients)
Now what is the syntax to define fields ?
All fields have one syntax just as
Field_name = fields.datatype(field attributes)

Watch On YouTube 
 

PREVIOUS STEP             NEXT STEP

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

Wednesday, October 23, 2019

remove menu in odoo

ODOO


 

menus 

 

we can add new menu to the parent view by xpath , also we can remove it by xpath just by add 

<delete model="ir.ui.menu" id="module_name.menu_id"/>

Sunday, October 20, 2019

phone field in odoo


 
we can make phone field just as char field but we have to control (validate) the user’s 
input for the phone number just as below


Create two fields for the phone (the key field and the number field) just like

("phone_num = fields.Char(string="Phon
("phone_key = fields.Char(string="Key")

then create their view to show them just like in the image

<"group colspan="4" col="4>
    <";table style="width:40%>
         <";tr style="width:100%>
             < td style="fonte-size:13px;width:25;>
                 <b>
                      Phone
                 </b>
             </td>
             <td style="fonte-size:13px;width:15%;">
                 <field name="phone_key" nolabel="1" placeholder="+249"/>
             </td>
             <td style="fonte-size:13px;width:60%;">
                  <field name="phone_num" nolabel="1" placeholder="912312312"/>
             </td>
         </tr>
     </table>
</group>

and finally we have to create the validation function for the phone fields , just like

@api.one
    @api.constrains('phone_num','phone_key')
    def validate_phone(self):
        """
        fuction to validate the input phone number for the user
        """
        if len(str(self.phone_key)) != 4:
            raise ValidationError(_("Wrong Phone Key"))
        if len(str(self.phone_num)) != 9:
            raise ValidationError(_("Wrong Phone Number"))

        for index in range(0,len(str(self.phone_key))):
            if index == 0:
                if str(self.phone_key)[index] != '+':
                    raise ValidationError(_("Wrong Phone Key (It Must Begin With + )"))
            if index != 0:
                if str(self.phone_key)[index] not in ['0','1','2','3','4','5','6','7','8','9']:
                    raise ValidationError(_("Wrong Phone Key (It's Conatin Char )"))
        for index in range(0,len(str(self.phone_num))):
            if str(self.phone_num)[index] not in ['0','1','2','3','4','5','6','7','8','9']:
                raise ValidationError(_("Wrong Phone Number (It's Conatin Char )"))
# before creating this function you have to import ValidationError in you model just as

from odoo.exceptions import ValidationError

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