Skip to Content
  • +31 653-919-302
Cafayate.Net
  • 0
  • 0
  • Sign in
  • Nederlands English (US) Español (AR)
  • Contact Us
  • Home
  • Blog
  • Jobs
  • Contact us
Cafayate.Net
  • 0
  • 0
    • Home
    • Blog
    • Jobs
    • Contact us
  • +31 653-919-302
  • Nederlands English (US) Español (AR)
  • Sign in
  • Contact Us

ORM Methods in OpenERP

  • All Blogs
  • Tech Blog
  • ORM Methods in OpenERP
  • March 5, 2021 by
    Administrator

    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.
    1. res = self.read(cr, uid, [5,6],[‘name’, ‘partner_id’])
    2. print ‘Partner:’, res[0][‘partner_id’]
    1. write(cr, uid, ids, values, context=None): updates a record with provided values.
      1. for line in self.browse(cr, uid, ids, context=context):
      2. if set_total:
      3. self.pool.get(‘add.penalty’).write(cr, uid, [line.id], {‘name’: line.name})
    2. search(cr, uid, values, args, offset=0, limit=None, order=None, context=None, count=False): returns list of ids (tuple) on search criteria
      1. seq_id = self.pool.get(‘ir.sequence’).search(cr, uid, [(‘name’,’=’,’Sales Journal’)])[0]
    3. copy(cr, uid, id, defaults, context=None): duplicates a record with default values
      1. def copy(self, cr, uid, id, default=None, context=None):
      2. default = default or {}
      3. default.update({‘invoice_ids’ : []})
      4. return super(res_partner, self).copy(cr, uid, id, default, context)
    4. unlink(cr, uid, values, context=None): deletes a record with given id or ids
      1. account_move_obj.unlink(cr, uid, move_ids, context=context)
    5. create(cr, uid, values, context=None): creates a new record with given values and returns the newly created record id
      1. partner_id = self.create(cr, uid,
      2. { ‘name’: ‘XYZ’,
      3. ‘description’ : ‘Contact’,
      4. ‘phone’: 123456,
      5. })
    6. browse(cr, uid, values, context=None): retrieves records with required fields, returns a list of records
      1. invoice = self.pool.get(‘account.invoice’)
      2. cr.execute(“select * from account_invoice where state = ‘open’ and payment_term > 0 and cash_credit=’Credit Memo'”)
      3. invoices = invoice.browse(cr, uid, map(lambda x: x[0], cr.fetchall()) )

    For more you can visit OpenERP ORM Methods

    in Tech Blog
    Node-Odoo

    Designed for companies

    We are a team of passionate people whose goal is to improve everyone's life through disruptive products. We build great products to solve your business problems. Our products are designed for small to medium size companies willing to optimize their performance.

    Get in touch

    Plantexel
    Pedernera
    Salta Capital 
    Argenina

    • +31 653-919-302
    • [email protected]
    Follow us
    Copyright © Plantexel
    Nederlands | English (US) | Español (AR)