Tutorial Openerp Basic Code

  • Home
  • About
  • Template
  • Design
  • Blogger
  • Tips Tricks
Home » openerp » source code » Relational Types on Openerp

Relational Types on Openerp

one2one:
A one2one field expresses a one:to:one relation between two objects. It is deprecated. 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 parameters)
Optional parameters:
  • ondelete: What should happen when the resource this field points to is deleted.
    • Predefined value: “cascade”, “set null”, “restrict”, “no action”, “set default”
    • Default value: “set null”
  • required: True
  • readonly: True
  • select: True - (creates an index on the Foreign Key field)
Example
'commercial': fields.many2one(
        'res.users',
        'Commercial',
        ondelete='cascade'),
one2many:
TODO
Syntax:
fields.one2many(
        'other.object.name',
        'Field relation id',
        'Fieldname',
        optional parameter)
Optional parameters:
  • invisible: True/False
  • states: ?
  • readonly: True/False
Example
'address': fields.one2many(
        'res.partner.address',
        'partner_id',
        'Contacts'),
many2many:
TODO
Syntax:
fields.many2many('other.object.name',
                 'relation object',
                 'actual.object.id',
                 'other.object.id',
                 'Field Name')
Where:
  • other.object.name is the other object which belongs to the relation
  • relation object is the table that makes the link
  • actual.object.id and other.object.id are the fields’ names used in the relation table
Example:
'category_ids':
   fields.many2many(
    'res.partner.category',
    'res_partner_category_rel',
    'partner_id',
    'category_id',
    'Categories'),
To make it bidirectional (= create a field in the other object):
class other_object_name2(osv.osv):
    _inherit = 'other.object.name'
    _columns = {
        'other_fields': fields.many2many(
            'actual.object.name',
            'relation object',
            'actual.object.id',
            'other.object.id',
            'Other Field Name'),
    }
other_object_name2()
Example:
class res_partner_category2(osv.osv):
    _inherit = 'res.partner.category'
    _columns = {
        'partner_ids': fields.many2many(
            'res.partner',
            'res_partner_category_rel',
            'category_id',
            'partner_id',
            'Partners'),
    }
res_partner_category2()
related:
Sometimes you need to refer to the relation of a relation. For example, supposing you have objects: City -> State -> Country, and you need to refer to the Country from a City, you can define a field as below in the City object:
'country_id': fields.related(
    'state_id',
    'country_id',
    type="many2one",
    relation="res.country",
    string="Country",
    store=False)
Where:
  • The first set of parameters are the chain of reference fields to follow, with the desired field at the end.
  • type is the type of that desired field.
  • Use relation if the desired field is still some kind of reference. relation is the table to look up that reference in.
f
Share
t
Tweet
g+
Share
?
Unknown
18.07

Belum ada komentar untuk "Relational Types on Openerp"

Posting Komentar

Posting Lebih Baru Posting Lama Beranda
Langganan: Posting Komentar (Atom)
Find Us :

Entri Populer

  • Functional Fields On Openerp
    A functional field is a field whose value is calculated by a function (rather than being stored in the database). Parameters: fnct, ar...
  • Relational Types on Openerp
    one2one: A one2one field expresses a one:to:one relation between two objects. It is deprecated. Use many2one instead. Syntax: fields ...
  • Basic Type Fields On Openerp
    boolean: A boolean (true, false). Syntax: fields.boolean('Field Name' [, Optional Parameters]), integer: An integer. S...
  • Create Menu on Openerp
    Menus are records in the ir.ui.menu table. In order to create a new menu entry, you can directly create a record using the record tag. ...
  • Predefined fields in Openerp
    _auto Determines whether a corresponding PostgreSQL table must be generated automatically from the object. Setting _auto to False can be u...
  • Fields Introduction on Openerp
    Here’s the header of the initialization method of the class any field defined in OpenERP inherits (as you can see in server/bin/osv/fields.p...

Mengenai Saya

Unknown
Lihat profil lengkapku
Diberdayakan oleh Blogger.
Copyright 2013 Tutorial Openerp Basic Code - All Rights Reserved
Design by Download software Articel and game free