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>

Sunday, December 6, 2020

open specific view from many2one field

 ODOO 



In this case we have many2one field for model that has more than one view and we want to open specific view from this field for this model

let us give an example :

- we have model "object.a" and model "object.b", in which we have object_a_id field as bellow 

object_a_id = fields.Many2one('object.a', string="Object A")

 

- model "object.a" has two form view with ids "object_a_form_view_1" and "object_a_form_view_2" and "object_a_form_view_1" id the default view and we want to show the other view from object_a_id field , so we can do it by add the field in the xml file as bellow

 

<field name="object_a_id" context="{'form_view_ref':'module_name.object_a_form_view_2',}" />

Thursday, December 3, 2020

OperationalError: FATAL: the database system is starting up

ODOO



The error above happen when the postgres database service can not start , so to fix it we have to restart the postgres by opening the terminal and write the command bellow 

sudo service postgresql restart

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