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

Friday, March 26, 2021

java test for beginners

 


In this blog we will give some questions in java for beginners

what is programming ?
________________________________________________________________________________
________________________________________________________________________________

what is program ?

________________________________________________________________________________
________________________________________________________________________________

what is machine language ?
________________________________________________________________________________
________________________________________________________________________________

what is assembly language ?
________________________________________________________________________________
________________________________________________________________________________

what is assembler ?
________________________________________________________________________________
________________________________________________________________________________

what is variable ?
________________________________________________________________________________
________________________________________________________________________________

what is the compiler ?
________________________________________________________________________________
________________________________________________________________________________

define package , class and method ?
________________________________________________________________________________
________________________________________________________________________________

how can we define the programming language as high level programming language ?
________________________________________________________________________________
________________________________________________________________________________

mention all error types in java and explain each one ?
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________

mention data types in java and group them ?
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________

explain why can’t store number greater than 127 in integer variable ?
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________

explain variable scope ?
________________________________________________________________________________
________________________________________________________________________________

explain type casting with 3 examples ?
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________

explain OOP ?
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________

what is the scanner , and what it use for ?
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________

Is java sensitive case ?
________________________________________________________________________________

What is JVM?
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________
________________________________________________________________________________

mention 5 words of java’s keywords ?
________________________________________________________________________________
________________________________________________________________________________

what does Object-Oriented Programming means ?
________________________________________________________________________________
________________________________________________________________________________

what are the bellow principles stand for ?
JVM ___________________________________________________________________________
JDK ____________________________________________________________________________
JRE ____________________________________________________________________________
JavaC __________________________________________________________________________
OOP ___________________________________________________________________________
JIN ____________________________________________________________________________
SDK ___________________________________________________________________________

Choose the right answer :

What do you mean by JRE?
   a. java runtime environment
   b. java runtime exception
   c. java runtime execution
   d. none of these

Java is a _____________language.
   a. object oriented 
   b. procedural oriented
   c. system oriented
   d. platform oriented

Previously Java was known as ________.
   a. Java onlyb. apple
   c. jdk
   d. oak

What is the extension of the Java program?
   a. .java
   b. .class
   c. .doc
   d. .txt

Which of the following operation(s) is/are required to convert the java source code into output form
   a. Compilation
   b. interpretation
   c. both a and b
   d. none of these

Is java 100% object oriented language?
   a. yes
   b. no
   c. can’t say

Java _________the program first and then __________it.
   1) compile
   2) interpret
   3) assemble
   4) debug
  
   a. 1 and 2
   b. 2 and 1
   c. 3 and 4
   d. 1 and 4

Java is developed by___________
   a. Microsoft
   b. Oracle
   c. Sun
   d. Google

What is JDK?
   a. java development kit
   b. java deployment kit
   c. java demo kit
   d. java distributed kit

In order to run Java program, we need to install __________application program.
   a. jdk
   b. sdk
   c. dbk
   d. all of the above

what is the correct syntax of rmain method in java ?
   a. public void main(String[] gars)
   b. public static void main(string []agrs)
   c. public static void main(String [] args)
   d. public static void Main(String []args)

what is an assignment statement ?
   a. adding a number to an integer
   b. assigning a multiplication
   c. assigning a name to a variable
   d. assigning a value to a variable

which of the flowing is not java keyword ?
   a. static
   b. try
   c. Integer
   d. new

choose the best data type to store this value 5.69
   a. int
   b. double
   c. boolean
   d. String

choose the appropriate data type for this field : isSwimmer
   a. double
   b. boolean
   c. string
   b. int

if you want your condition to depend upon two conditions Both begin true , What is the proper notation to put between the two Boolean statements
   a. =
   b. !=
   c. ||
   d. &&
   e. &

An object can be

   a. class
   b. anything
   c. program
   d. method 


                                              



Tuesday, March 23, 2021

kanban view in odoo




In this blog we will give and example to design kanban view in odoo
so the code can be just as bellow


<!-- """Create Kanban View""" -->

  <record id="view_ssc_projects_kanban" model="ir.ui.view">
    <field name="name">ssc.projects.kanban</field>
    <field name="model">ssc.projects</field>
    <field name="arch" type="xml">
      <kanban class="o_hr_employee_kanban">
        <field name="id"/>
        <templates>
          <t t-name="kanban-box">
            <div class="oe_kanban_global_click">

              <div class="o_kanban_image">
                <img t-att-src="kanban_image('ssc.projects','image',record.id.raw_value)" alt="Image"/>
              </div>

              <div class="oe_kanban_details">
                <h2>
                  <a type="open">
                    <field name="name" />
                  </a>
                </h2>
                <h4>
                  <a type="open" style="color:#04025e ! important;">
                   <field name="customer_id"/>
                 </a>
               </h4>
             </div>

           </div>
         </t>
       </templates>
     </kanban>
   </field>
 </record>


and the kanban view can look like bellow 
 

 

Tuesday, March 9, 2021

rounding in odoo


 In this blog we will explain how we can make rounding in odoo for float numbers
         

          as we know 10/3 = 3.333333333333X , and we can make rounding for this value as 3.34 or 3.334 or 3.33 or 3.3 or 3.333 , that is means we have more than one way to make rounding in math , so how can we make rounding in odoo ?

To make rounding in odoo we can use round() function id takes 2 arguments the first one it the float number that we want to round it  ,and the second one is the number of rounding index so the Rule as

num = round(float_number,index_number)

so if we want to round 10/3 for 2 index with will be 3.34 we can do it as bellow

num = round(10/3,2)


Another way to make rounding in odoo is by using float_round() function with can takes 4 arguments as bellow

num = float_round(10/3,precision_digits=2, precision_rounding=None, precision_method='up' )

Saturday, March 6, 2021

less porblem with odoo 10


 

I had some problem with odoo 10 UI after installing some theme module , and I tried many ways to fix it , and only one way worked with me , which by running the command bellow in the terminal

sudo npm install -g less@3.0.4 less-plugin-clean-css


report color from user in odoo

 


In this blog we will explain how read report color from user in odoo . so let us make an example 


First : we have to define char field that will contain the color rbg as bellow

color = fields.Char(string="Color")

Second : create the view for this field as bellow 

<field name="color" widget="colorpicker"/>

or
<field name="color" widget="color"/>

after that the view will look like bellow 


 

Third : we can read our color in the report template as bellow

background-color:<t t-esc="color"/>!important; // to make it as back groud color for some element 

color:<t t-esc="color"/>!important; // to make it as text color

...

Eg : say we want to add it as back ground color for td in a table so we can do it as bellow

&lt;td style="width:100px;font-size:14px; border: 1px solid black;padding-top:2px; padding-bottom:2px;background-color:<t t-esc="color"/>!important; font-size: 14px; text-align:center;font-weight:bold;"
      <span t-esc="field_name"/>

&lt;/td &gt;



I used this with odoo 11 , and it worked :)

Thursday, February 11, 2021

One2many field in odoo


 In this blog we will explain how to control the line in one2many fields in odoo

 
(0, 0,  { values }) link to a new record that needs to be created with the given value
dictionary

(1, ID, { values }) update the linked record with id = ID (write *values* on it)
 
(2, ID) remove and delete the linked record with id = ID (calls unlink on ID,
that will delete the object completely, and the link to it as well)
 
(3, ID) cut the link to the linked record with id = ID (delete the relationship between
 the two objects but does not delete the target object itself)
 
(4, ID) link to existing record with id = ID (adds a relationship)
 
(5) remove all (like using (3,ID) for all linked records)
 
(6, 0, [IDs]) replace the list of linked IDs (like using (5) then (4,ID) for each ID in the list of IDs)

Sunday, February 7, 2021

postgresql from treminal

 
In this blog we will explain many ways that help us to control postgresql from terminal
 
 
Connect To Postgresql 
psql postgres
  

restore dump backup database in postgresql
pg_restore -U postgres -d coffee -1 /home/user_name/Downloads/db_backup_name.dump

or
pg_dump DB_name  > /home/user/Desktop/db_backup_name.dump

 

restore ZIP backup database in postgresql 

curl -X POST -F 'master_pwd=1234' -F 'name=DB_name' -F 'backup_format=zip' -o /home/user/Desktop/back_up.zip http://localhost:8069/web/database/backup 

 

Create new database

CREATE DATABASE DB_name;


Connect one database
psql db_name user_name

 

Delete database 

DROP DATABASE DB_name


Rename database
ALTER DATABASE DB_name RENAME TO DB_new_name

 

Copy database
CREATE DATABASE New_DB_name
WITH TEMPLATE Existed_DB_name;


Thursday, February 4, 2021

get caller function in odoo

 

 
    Let us say that we built a function in odoo and we want to get data of any function call this function , such as we want to make logging for any caller function fo our function , so we want to get

caller function name
caller function file
calling line in the caller function


and put all of these data in logging file , we can get all of these data as bellow

caller function name :

caller_function = sys._getframe(1).f_code.co_name

 

caller function file :

caller_filename = sys._getframe(1).f_code.co_filename 


calling line in the caller function :

caller_line_number = sys._getframe(1).f_lineno


#Note
we can get the current function name as
current_function = sys._getframe(1).f_code.co_name

and we can add them to logging file from here

logging in odoo


Logging in odoo is very important thing in order to know what is happening in odoo server and to tracking any process in the server , and to make logging in odoo we have 2 steps

  • Import logging in odoo class just like
    _logger = logging.getLogger(__name__)
  • use type of logging in odoo which has many types just as

    INFO Logging : to log info message
    _logger.info("Any thing you want to log it")

    WARNING Logging : to log WARNING message
    _logger.warring
    ("Any thing you want to log it")

    DEBUG Logging : to log DEBUG message
    _logger.debug
    ("Any thing you want to log it")

    ERROR Logging : to log ERROR message
    _logger.error
    ("Any thing you want to log it")

    CRITICAL Logging : to log CRITICAL message
    _logger.critical
    ("Any thing you want to log it")


    Now let us Give an example and say that we want to log the current company name and the current user name , so
    we will inherit res.company name and add our logger in it as bellow



    class LoggerLogger(models.Model):
        _inherit = 'res.company'

        def odoo_logger(self,current_company,current_user):
            """
                Function To make logging for company and uers
            """
            _logger.info("Current Company : "+
    current_company+", The Current User : "+current_user)


    and when we call this function we have to pass company and user such as


       def logger_caller(self):
            current_company = self.env.user.company_id.name
            current_user = self.env.user.name

            self.env.user.company_id.odoo_logger(current_company,
    current_user)


    Note :
    to know how to put file name , function name and calling line in the logging file from here


Wednesday, January 27, 2021

set security group for all users in odoo

 


Set security group for all users

Here we will explain how to set security group for all users in odoo from xml file , so to do that we will add all users to the specific group by adding the bellow line to group xml tag

            <field model="res.users" name="users" search="[('id', '!=', 0)]"/>

EG :
    

    <record id="group_api_tap" model="res.groups">
            <field name="name">APIs</field>
            <field model="res.users" name="users" search="[('id', '!=', 0)]"/>
            <field name="category_id" ref="validator.module_validator"/>
        </record>

scanner in java


Scanner in java

 To understand Scanner in java and start using it we have to know some principles

  • The Scanner class is used to get user input
  • Scanner is found in the java.util package
  • To use scanner we have to make an object from scanner class
In other we if we want to use scanner we have to make and object for it , and to make and object for it first we have to import it first , so let us to do this in a code

1/ import scanner 

    import java.util.*;   Or
    import java.util.Scanner;

2/ make object for scanner

    as we know the rule to make an object for any class is 

    class_name object_name = new class_name();
    
    and to create scanner object we can do it as bellow

    Scanner scan = new Scanner(System.in);
    
    scan is the object name , system.in to define that we will read some values form the user

3/ use the scanner to get variable's value from the user

    we can define the variable and then get it's value from the user as bellow

    EG :
        int num;
        num = scan.nextInt();

    or define a variable and get it's value from the user in one line as bellow

    EG : 
        int num = scan.nextInt();

    *Note
 
     we can define (byte , short , long , int , double , float , boolean) with scanner as bellow
 
    byte variable_name = scan.nextByte();
    short variable_name = scan.nextShort();
    int variable_name = scan.nextInt();
    long variable_name = scan.nextLong();
 
    double variable_name = scan.nextDouble();   
    float variable_name = scan.nextFloat(); 
 
    boolean variable_name = scan.nextBoolean(); 
 
and we can (define char , string ) variables as bellow 
      
    Char
 
    char variable_name = scan.next().charAt(0);  Or  
    char variable_name = scan.nextLine().charAt(0);
 
 
    String
 
    String variable_name = scan.nextLine(); Or
    String variable_name = scan.next();  

edit odoo setting

 


In this blog we will explain how to edit setting object and view in odoo to add new setting so let us give an example

let us say that we want to add three fields to odoo setting (res.config.settings) object so we have to know some important things

  • res.config.settings is Transient Model , so it will not save data
  • we have specific way to save all fields one the model
  • relational fields have different way to make them savable at setting 
Eg : 
we want to add name field which is char field , age which is integer field and account_id with is many2one field so 

first define the fields in the class as bellow

class ResConfigSettings(models.TransientModel):
    _inherit = 'res.config.settings'

    name = fields.Char(string="Name")
    age = fields.Integer(string="Age")
    account_id = fields.Many2one('account.account', string="Account")

second make the non relational fields savable by adding the methods bellow 
 
@api.model
    def get_values(self):
        res = super(ResConfigSettings, self).get_values()
        ICPSudo = self.env['ir.config_parameter'].sudo()
        name = ICPSudo.get_param('module_name.name')
        res.update(name=name)
        age = ICPSudo.get_param('module_name.age')
        res.update(age=age) 
 
 
def set_values(self):
        super(ResConfigSettings, self).set_values()
        for rec in self:
            ICPSudo = rec.env['ir.config_parameter'].sudo()
            ICPSudo.set_param('module_name.name',str(rec.name))
            ICPSudo.set_param('
module_name.age',rec.age) 
 
Third make relational fields savable through 2 steps 
 
1/ inherit res.company object and add same relational fields inside it just as

class Company(models.Model):
    _inherit = "res.company"
 
    account_id = fields.Many2one('account.account', string="Account")
 
2/ edit the relational fields that you had defined in the setting object by makeing them related fields just as 
 
account_id = fields.Many2one('account.account', string="Account", related="company_id.account_id") 

Friday, January 22, 2021

pdf report creator



Here we will explain how his module works

Module Menus :
After you giving the current user all permissions you can fine new root menu with
the name Reports Creator with has two submenus with name Create new report
and Templates , as in the image bellow
 

Templates Menu :
By going to reports Creator/Templates you will fine view with 20 templates in
many models and you can create your new templates as you want


Create Template :
From reports Creator/templates click on create and enter
name: with will be the name of your template
model : that is the model that you want to create the template for
Apply to models : which is allows you create the current template for more than
one template that you choose by duplicating the current template for each one of
them
Use as sample template : which is allows you to use the current template as
sample that you can choose it to create another template just by editing it
Sample image : the image that will descripting the template



Content : here we will design the report template body it self as we are writing
text file , and we can read a value for one field for the model that we had choose
just by writing S{object.field_name} , here you can check the20 examples


Paper format : this page gives you many options to define the page format such
as , margins and orientations


Available fields : in this page you can fine all fields from the model you choose ,
and you can get the value of any one of them as we say above



Samples : here you can choose one of the sample template , then it’s content will
be written in the current template content area , and the you can edit it as you
want


 
Create Report :
 
To create and print new report go to reports creator/ create new report and then
click on create button and add the fields

Date : the date of creating this report which is take the current date as default
model : the model that you want to print report from it
Template : select one template form all templates that’s designed for the model
you choose
Record field : this field depends on the models you choose , for eg if you choose
employee model this field will by employee so you have to choose one employee
to print the report for him



Print button : to print the report after filling all fields just click on the print button
on the top menu , you will get popup window , then revise the report and click on
the print button on the bottom of the window which will create the pdf file



 
 
Watch demo




Download module
👍












Friday, January 1, 2021

sequence in odoo 14

 

Add sequence to odoo object

 
we can add sequence in odoo 14 by following the example bellow 
 
now let us say that we have objects by the name "shilal.object" and we want to 
create sequence field for this objects as "S_O000001" , so to do that 

1/ add char field in this model as 
 
sequence  = fields.Char(string="Sequence")
 
 
2/add the function that will generate the value for this field as bellow
 
@api.model
    def create(self, vals):
       if vals.get('sequence', 'New') == 'New':
           vals['sequence'] = self.env['ir.sequence'].next_by_code(
               'shilal.object') or 'New'
       result = super(ShilalObject, self).create(vals)
       return result

3/ create the xml code for this sequence as bellow

<record id="shilal_object_sequence" model="ir.sequence"> // define sequence record
          <field name="name">Shilal Object Sequence</field> // define sequence name
          <field name="prefix">s_O </field>
          <field name="padding">6</field>
          <field name="code">input.fields</field>
</record>

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