Openerp contain different types of fields and these Fields are divided into three different categories, they are simple fields, relation fields and functional fields.
So lets discuss this one by one-
1. Simple Fields- The simple types are integers, floats, booleans, strings, etc.
2. relation fields- The relations between different objects (i.e- one2one, one2many, many2one) are represented by relation field.
3. Functional fields- These fields are special fields because they are not stored in the database but calculated in real time by given other fields of the view.
How to describe fields?->
def __init__(self, string=unknown, required=False, readonly=False,
domain=[], context="", states={}, priority=0, change_default=False, size=None,
ondelete="setnull", translate=False, select=False, **args) :
Type of Fields
->
1-Basic Types/ Simple Fields
fields.boolean(Field Name [, Optional Parameters])
integer
Syntax:
fields.integer(Field Name [, Optional Parameters])<br>
float
Syntax:
fields.float(Field Name [, Optional Parameters]),
char
Syntax:
fields.char(Field Name, size=n [, Optional Parameters]), # where n is an integer.
text
Syntax:
fields.text(Field Name [, Optional Parameters])
2-Relational Types
- one2one
one:to:one relation between two objects is expressed by one2one field. This filed is deprecated so use many2one instead.
syntax:
fields.one2one(other.object.name, Field Name)
many2one
Associates this object to a parent object via this Field. For example Department an Employee belongs to would Many to one. i.e Many employees will belong to a Department.
syntax:
fields.many2one(other.object.name, Field Name, optional parameter)
one2many
syntax:
fields.one2many(other.object.name, Field relation id, Fieldname, optional parameter)
many2many
syntax:
fields.many2many(other.object.name
relation object,
other.object.id,
actual.object.id,
Field Name)
3-Functional Field
A functional field is a field whose value is calculated by a function or in other words we can say that it is the field which is called by function and attribute.
Type- It is the field type name returned by the function. It can be any field type name except function.
Store- If you want to store field in database or not. Default is False.
Method, whether the field is computed by a method (of an object) or a global function.
fnct- It is the function or method that will compute the field value. It must have been declared before declaring the functional field.
If method is True, the signature of the method must be:
def fnct(self, cr, uid, ids, field_name, arg, context)
Example Of Functional Field-
Suppose we create a contract object which is :
class hr_contract(osv.osv):
_name = hr.contract
_description = Contract
_columns = {
name : fields.char(Contract Name, size=30, required=True),
employee_id : fields.many2one(hr.employee, Employee, required=True),
function : fields.many2one(res.partner.function, Function),
}
hr_contract()
0 Comment(s)