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


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