Monday, September 14, 2020

postgres database backup

postgres database backup

We can make backup for postgres database backup by many ways 

  • from the browser by opening the database manager , and click to backup the database that we want to make a backup for as in the image bellow
 
 

  • pgadmin

connecting to the database server as bellow 


then go to the database that you want to make backup for , and right click and then select backup from the menu as in the image bellow 


then you have to define the name for the backup file and the folder which will contain it, and the other information as in the image bellow and then click on the backup button


  • Also we can make database backup from the terminal by writing these commands 
      su - postgres /// to login as postgres user 
      pg_dump dbname > dbname.bak /// to make backup to your database with the name "dbnam" , 
      so don't forget to right the right name of your database 
      psql -f infile postgres ///  to make resulting dump can be restored with psql 
 
#hope this is useful :) 

Sunday, September 13, 2020

overwrite unlink function in odoo

ODOO


 

unlink() function

To explain how we can overwrite the unlink() function in odoo we must understand some points

  • any object in odoo has it's own unlink() function which is enable the user to delete any record from this object with out any condition
  • we overwrite the unlink() function when we want to put some conditions on to delete records from the object , or if we want to make the any record unable to be deleted when it created 
Now let us give an example and let us say that we have an object by name "sas.admission" with class name "sas_admission", and in this object we have state field as 

state = fields.Selection([('draft','Draft'),('request','Request'),('done','Done')], string="State", default='draft')

and we want to make any record on this object can to deleted only if it's state is "draft" so we can overwrite the unlink() function as bellow 

@api.multi
    def unlink(self):
        """
        overwrite the unlink function to make user can delete the record if it's state is draft only
        """
        if self.state != 'draft':
            raise ValidationError(_('You cannot delete this record because it state is not draft'))
        return super(sas_admission, self).unlink()

the validation error message will look like 



* don't forget to import ValidationError on your class as bellow 
 
    from odoo.exceptions import ValidationError

Saturday, September 12, 2020

create constrains function in odoo

ODOO

 

constrains

to explain this let us say that we have four-digit name as we explain how we can create it in this topic how to Add a four-digit name in odoo 

now let us say that we have to create validation function that make the user can not save any name that contain any letter or mark than English letters , and to do this we must create constraint function that looping in the name of the employee and show validation error message if the name contain some non English letters or numbers , so the function can be as bellow 

@api.constrains('first_name','second_name','third_name','fourth_name')
    def _arabic_name_validity(self):
        """
        verifies if  name for the employee .
        """
        arabic_letters_list = [
                                'a','s','d','f',
                                'k','j','h','g',
                                'l','z','x','c',
                                'm','n','b','v',
                                'q','w','e','r',
                                't','y','u','i',
                                'p','o',' ',
                            ]
        if self.first_name and self.second_name and self.third_name and self.fourth_name:
            for index in range(0,len(self.first_name)):
                if self.first_name[index] not in arabic_letters_list:
                    raise ValidationError(_('the first name of the employee name must contain english letters only'))
            for index in range(0,len(self.second_name)):
                if self.second_name[index] not in arabic_letters_list:
                    raise ValidationError(_('the first name of the employee name must contain english letters only'))
            for index in range(0,len(self.third_name)):
                if self.third_name[index] not in arabic_letters_list:
                    raise ValidationError(_('the first name of the employee name must contain english letters only'))
            for index in range(0,len(self.fourth_name)):
                if self.fourth_name[index] not in arabic_letters_list:
                    raise ValidationError(_('the first name of the employee name must contain english letters only'))


the validation message will look like the image bellow 

Add a four-digit name in odoo

four-digit name

Some organizations ask to create four-digit name for it's employees when we enter the data for them , and to do that we have to create the four-digit name as bellow as in the image bellow 


  • create five char fields in the employee model which are 
first_name , second_name , third_name , fourth_name and the complete name which is contain all the other names and  defined theme as bellow 

    name = fields.Char("Name", required=True, compute='get_full_name')
    first_name = fields.Char("First Name", required=True)
    second_name = fields.Char("Second Name", required=True)
    third_name = fields.Char("Third Name", required=True)
    fourth_name = fields.Char("Fourth Name", required=True)

the get_full_name() function use to concatenate the complete name for the employee and it must be as bellow 

@api.one
    @api.depends('first_name','second_name','third_name','fourth_name')
    def get_full_name(self):
        """
        the method compute the full name for the employee
        """

        if self.first_name and self.second_name and self.third_name and self.fourth_name:
            self.name = self.first_name+" "+self.second_name+" "+self.third_name+" "+self.fourth_name


  • create the view as bellow 
<group colspan="2" col="2">
                            <field name="name" style="font-size:30px;color:#7c7bad;"/>
                        </group>
                        <group colspan="12" col="12">
                            <field name="first_name" nolabel="1" placeholder="First Name" attrs="{'readonly':[('state','!=','draft')]}"/>
                            <field name="second_name" nolabel="1" placeholder="Second Name" attrs="{'readonly':[('state','!=','draft')]}"/>
                            <field name="third_name" nolabel="1" placeholder="Third Name" attrs="{'readonly':[('state','!=','draft')]}"/>
                            <field name="fourth_name" nolabel="1" placeholder="Fourth Name" attrs="{'readonly':[('state','!=','draft')]}"/>
                        </group>

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