ODOO
fields
attributes
Here we are going to explain odoo field's attributes one by one , so let as start
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
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
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
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
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
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
this attribute will save the value of the field forcefully in the database and it take boolean value "true or flase
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
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
this attribute takes boolean value to control that if the value of the field will copy or not if we duplicate the record
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 "
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
this attribute make you can translate the value of the field into another language
Eg : name = fields.Char(string="Name", translate=True)