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