Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Relational Types in OpenERP

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 336
    Comment on it

    Relational types in OpenERP are:

    1. many2one
    2. one2many
    3. many2many
    4. related

    many2one: associates an object to its parent object. Example Customer and Invoices. Many invoices belong to one customer.

    Syntax:

    fields.many2one(
            'other.object.name',
            'Field Name',
            optional parameters)
    

    Exampe:

    partner_id': fields.many2one('res.partner', 'Partner', change_default=True, readonly=True, required=True, states={'draft':[('readonly',False)]}),
    

    Optional parameters:

    ondelete: 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)
    

    one2many: associates the parent to its child object. Example one Invoice with many Lines(items).

    Syntax:

    fields.one2many(
            'other.object.name',
            'Field relation id',
            'Fieldname',
            optional parameter) 
    

    Example:

    'invoice_line': fields.one2many('account.invoice.line', 'invoice_id', 'Invoice Lines', readonly=True, states={'draft':[('readonly',False)]}),
    

    Optional parameters:

    invisible: True/False
    states: ?
    readonly: True/False
    

    many2many: associates two objects with many links. Example many tax entries with many invoice (line)entries.

    Syntax:

    fields.many2many('other.object.name',
                     'relation object',
                     'actual.object.id',
                     'other.object.id',
                     'Field Name')
    

    Where:

    other.object.name: the other object which belongs to the relation
    relation object: the table that makes the link
    actual.object.id and other.object.id: the fields' names used in the relation table
    

    Example:

    'invoice_line_tax_id': fields.many2many('account.tax', 'account_invoice_line_tax', 'invoice_line_id', 'tax_id', 'Taxes', domain=[('parent_id','=',False)]),
    

    describes the tax associated with each line of the invoice

    related: associates relation of a relation, example company,partner,invoice lines, you can refer directly from an invoice to a company.

    Syntax:

    'other_object_id': fields.related(
        'chain_id1',
        'chain_id2',
        type="many2one",
        relation="other.object.name",
        string="Name",
        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
    relation is the table to look up that reference in
    

    Example:

    'company_id': fields.related('invoice_id','company_id',type='many2one',relation='res.company',string='Company', store=True, readonly=True),
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: