Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Openerp python和odoo中的self.pool.get()是什么?_Openerp_Openerp 7 - Fatal编程技术网

Openerp python和odoo中的self.pool.get()是什么?

Openerp python和odoo中的self.pool.get()是什么?,openerp,openerp-7,Openerp,Openerp 7,我假设它用于引用openerp中其他模块中的字段,但我不确定 在这里,他们以某种方式从一个产品模块到另一个销售模块获取价格 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 price

我假设它用于引用openerp中其他模块中的字段,但我不确定

在这里,他们以某种方式从一个产品模块到另一个销售模块获取价格

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}
self.pool.get()
用于从注册表池获取orm模型的单例实例

如果您想为任何其他模型调用orm方法,您可以使用
self.pool.get('model').orm_方法

在新的API中,如果您想直接从对象调用ORM方法,可以使用
self.env['obj'].method
而不是
self.method

希望这有帮助

self.pool.get()

pool
在这里只是一个类似字典的对象,用于存储
OpenERP模型的实例,比如
res.users
ir.model.data

OpenERP/Odoo的多数据库性质:单个OpenERP服务器进程可以管理多个数据库,对于每个数据库,安装的模块集以及模型集可能会有所不同

因此,我们有不同的
,每个数据库一个,以及引用我们已经在其中的模型实例的正常方式,
self

感谢您对self.pool.get()的精彩解释。 有关更多信息,请查看该链接。

Pool

池是一个注册表(字典对象{})

注册表本质上是模型名和模型名之间的映射 实例。每个数据库有一个注册表实例

server/openerp/osv/orm.py

class BaseModel(object):

    def __init__(self, pool, cr):
请参阅/openerp/sql_db.py以了解Odoo Postgresql连接的方式 池建立

连接类

class Connection(object):
    """ A lightweight instance of a connection to postgres
    """
    def __init__(self, pool, dbname, dsn):
        self.dbname = dbname
        self.dsn = dsn
        self.__pool = pool
如果您查看那里的/server/openerp/pooler.py文件,您可以找到用于创建和返回数据库连接和新初始化的注册表的方法get_db_和_pool,还有许多其他与pool相关的方法

def get_db_and_pool(db_name, force_demo=False, status=None, update_module=False):
    """Create and return a database connection and a newly initialized registry."""
    registry = RegistryManager.get(db_name, force_demo, status, update_module)
    return registry.db, registry


def restart_pool(db_name, force_demo=False, status=None, update_module=False):
    """Delete an existing registry and return a database connection and a newly initialized registry."""
    registry = RegistryManager.new(db_name, force_demo, status, update_module)
    return registry.db, registry

def get_db(db_name):
    """Return a database connection. The corresponding registry is initialized."""
    return get_db_and_pool(db_name)[0]


def get_pool(db_name, force_demo=False, status=None, update_module=False):
    """Return a model registry."""
    return get_db_and_pool(db_name, force_demo, status, update_module)[1]
最后调用dictionary的get方法来获取指定键的值,即使您可以使用can-useself.pool['model\u name'],dictionary的任何方法都可以与pool一起使用

_Pool = None

def db_connect(to, allow_uri=False):
    global _Pool
    if _Pool is None:
        _Pool = ConnectionPool(int(tools.config['db_maxconn']))

    db, uri = dsn(to)
    if not allow_uri and db != to:
        raise ValueError('URI connections not allowed')
    return Connection(_Pool, db, uri)

def close_db(db_name):
    """ You might want to call openerp.modules.registry.RegistryManager.delete(db_name) along this function."""
    global _Pool
    if _Pool:
        _Pool.close_all(dsn(db_name)[1])

def close_all():
    global _Pool
    if _Pool:
        _Pool.close_all()
class Connection(object):
    """ A lightweight instance of a connection to postgres
    """
    def __init__(self, pool, dbname, dsn):
        self.dbname = dbname
        self.dsn = dsn
        self.__pool = pool
def get_db_and_pool(db_name, force_demo=False, status=None, update_module=False):
    """Create and return a database connection and a newly initialized registry."""
    registry = RegistryManager.get(db_name, force_demo, status, update_module)
    return registry.db, registry


def restart_pool(db_name, force_demo=False, status=None, update_module=False):
    """Delete an existing registry and return a database connection and a newly initialized registry."""
    registry = RegistryManager.new(db_name, force_demo, status, update_module)
    return registry.db, registry

def get_db(db_name):
    """Return a database connection. The corresponding registry is initialized."""
    return get_db_and_pool(db_name)[0]


def get_pool(db_name, force_demo=False, status=None, update_module=False):
    """Return a model registry."""
    return get_db_and_pool(db_name, force_demo, status, update_module)[1]