Monday, 22 September 2014

Odoo New API: Recordsets


Share it Please


A recordset is:
  • An ordered collection of records.
  • One concept to replace:
              - browse records,
              - browse lists,
              - browse nulls.
  • An instance of the model's class.

1. The recordset as a collection:

It implements a sequence and set operations:

Operation Supported:

RecordSet also support set operations you can add, union and intersect, ... recordset:

1. Addition:

recordsetA + recordsetB: Returns the concatenation of two recordsets.

2. Substration:

recordsetA - recordsetB: Return the recordset of all the records in 'recordsetA' that are not in 'recordsetB'.

3. Intersection:

recordsetA & recordsetB: Return the intersection of two recordsets. Note that recordset order is not preserved.

4. Union:

recordsetA | recordsetB: Return the union of two recordsets. Note that recordset order is not preserved.

5. Equivalent:

recordsetA == recordsetB: Test whether two recordsets are equivalent (up to reordering).


2. The recordset as a record:

It behaves just like former browse records:

    print partner['name']

Except that updates are written to database: = 'Agrolait' = ''
    partner.parent_id = ...   # another record

If len(partners) > 1, do it on the first record:

    print           # name of first partner
    print partners[0].name = 'Agrolait'    # assign to first partner
    partners[0].name = 'Agrolait'

If len(partners) == 0, return the null value of the field:

    print        # False
    print partners.parent_id   # Empty recordset = 'Foo'      # Error

3. The recordset as an instance:

Methods of the model's class can be invoked on recordsets:

# calling convention: leave out cr, uid, ids, context
def write(self, values):
    result = super(C, self).write(values)
    # search returns a recordset instead of a list of ids
    domain = [('id', 'in', self.ids), ('parent_id', '=', False)]
    roots =
    # modify all records in roots
    roots.write({'modified': True})
    return result

The missing parameters are hidden inside the recordset.

Record creation in cache only:

You can create a new record with following method:

def new(self, values={}):
    """ new([values]) -> record """

Return a new record instance attached to the current environment and initialized with the provided 'value'. The record is not created in database, it only exists in memory.

New record is used to compute default values and perform onchanges.


record =

This will creates a new record with values, and attach 'self' to it.

Comment With:
The Choice is Yours!

1 comment:

  1. Enpersol is an Odoo consultants Company in indore proficient in business process reenginerring and optimization. Enpersol is an Odoo partners Company provide best Odoo services in pune.