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

    • 0
    • 0
    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 3.95k
    Comment on it

    Every object in OpenERP is based on OSV i.e Object Service and this service implements full Object-Relational Mapping enabling developers not to worry for the simple SQL operations.

    In OpenERP, we have such ORM methods that are very useful. Here are the few basic methods:

    1. read(cr, uid, ids, fields=None, context=None): returns a list of dictionaries with field values.
    2.  res =, uid, [5,6],['name', 'partner_id'])
       print 'Partner:', res[0]['partner_id']

    3. write(cr, uid, ids, values, context=None): updates a record with provided values.

      for line in self.browse(cr, uid, ids, context=context):
                  if set_total:
                      self.pool.get('add.penalty').write(cr, uid, [], {'name':})

    4. search(cr, uid, values, args, offset=0, limit=None, order=None, context=None, count=False): returns list of ids (tuple) on search criteria

      seq_id = self.pool.get('ir.sequence').search(cr, uid, [('name','=','Sales Journal')])[0]

    5. copy(cr, uid, id, defaults, context=None): duplicates a record with default values

      def copy(self, cr, uid, id, default=None, context=None):
              default = default or {}
              default.update({'invoice_ids' : []})
              return super(res_partner, self).copy(cr, uid, id, default, context)

    6. unlink(cr, uid, values, context=None): deletes a record with given id or ids

      account_move_obj.unlink(cr, uid, move_ids, context=context)

    7. create(cr, uid, values, context=None): creates a new record with given values and returns the newly created record id

      partner_id = self.create(cr, uid,
      { 'name': 'XYZ',
      'description' : 'Contact',
      'phone': 123456,

    8. browse(cr, uid, values, context=None): retrieves records with required fields, returns a list of records

          invoice = self.pool.get('account.invoice') 
          cr.execute("select * from account_invoice where state = 'open' and payment_term > 0 and cash_credit='Credit Memo'")
          invoices = invoice.browse(cr, uid, map(lambda x: x[0], cr.fetchall()) )

    For more you can visit OpenERP ORM Methods

 1 Comment(s)

Sign In

Sign up using

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: