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") 

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