What is self.pool.get() in python and odoo?

Kiran picture Kiran · Oct 29, 2015 · Viewed 12.6k times · Source

I assume it is used to refer fields in other modules in openerp, but I am not sure.

Here they are somehow getting price from one products module to sales module.

price = self.pool.get('product.pricelist').price_get(cr, uid, [pricelist], product, qty or 1.0, partner_id, ctx)[pricelist]
    if price is False:
        warn_msg = _("Cannot find a pricelist line matching this product and quantity.\n"
                "You have to change either the product, the quantity or the pricelist.")

        warning_msgs += _("No valid pricelist line found ! :") + warn_msg +"\n\n"
    else:
        result.update({'price_unit': price})
        if context.get('uom_qty_change', False):
            return {'value': {'price_unit': price}, 'domain': {}, 'warning': False}

Answer

bud-e picture bud-e · Oct 29, 2015

self.pool.get()

The pool is here just a dictionary-like object that is used to store instances of the OpenERP models, like res.users or ir.model.data.

Multi-database nature of OpenERP / Odoo: a single OpenERP server process can manage multiple databases, and for each database, the set of installed modules, and thus the set of models, can vary.

So, we have different pools, one per database, and the normal way to reference the model instance we are already in, self

Thanks to The Hypered Blog for the great explanation on the self.pool.get(). For more info check that link.