Saturday, July 20, 2019

fields attributes in odoo

ODOO

fields

attributes 

 

Here we are going to explain odoo field's attributes one by one , so let as start 

  • String

this attribute allow me to control the label of the field in the GUI 
Eg : name = fields.Char(string="Employee Name")// the label of this field will be Employee Name 

  • Required

this attribute defines that the field must be have an inputed value from the user or not in any created record , so it can be set for true or false
Eg :  name = fields.Char(string="Employee Name", required=True) // here we can't create record of this field if we don't insert a value for it 

  • Domain 

this with define the domain to insert a value for this field 
Eg : employee_id = fields.Many2one('employee.employee', string="Employee", domain=[('age','=',25)])// this will allows me to choose from employees with 25 years old only 

  • Default 

this attribute will give default value for the field 
Eg : gender = fields.Selection([('mail','Mail'),('femail','Femail')], default='mail', string="Gender") //  the make the gender = mail as default 

  • Readonly 

this attribute make the user cann't give a value the field , so it show the field just as label "uneditable" and it can take boolean value as true or false
Eg :  gender = fields.Selection([('mail','Mail'),('femail','Femail')], default='mail', string="Gender", readonly=True)// the user cann't choose the gender here

  • Digits 

this attribute is only use with float fields to control precision of a value to set how value will display 
Eg : price = fields.Float(string="Price", digits=(10,3)) // this will show the price as number of 10 integer digits and 3 decimal digits

  • Store

this attribute will save the value of the field forcefully in the database and it take boolean value "true or flase  

  • help

this attribute uesd to make the field more freindly by adding helping message which will show when the user put the mouse cursor over the field 

  •  Compute 

this attribute make the value of the field computed from a function
Eg : name = fields.Char(string="Name", compute="get_name") // this make the value of name field computed from get_name function which can be defined as 

@api.one
def get_name(self):
      self.name = "ABCD" // the function put ABCD as value for the field

  • Copy

this attribute  takes boolean value to control that if the value of the field will copy or not if we duplicate the record
  • Index

this attribute takes boolean value to control that if the field's index will create in the database or not " the field index help us to search for the field in the database directly "

  •  Inverse

this attribute help us to call function when the vlaue of the field changed 
Eg : age  = fields.Integer(string="Age", inverse="get_full_name") // that means the get_full_name function will call when we  change the value of the age field

  • translate

this attribute make you can translate the value of the field into another language 
Eg : name = fields.Char(string="Name", translate=True) 

No comments:

Post a Comment

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