Orm 错误可能是';t适应类型';一些.模型';

Orm 错误可能是';t适应类型';一些.模型';,orm,openerp,odoo-9,Orm,Openerp,Odoo 9,尝试从列接收数据时出错。 模型为: class int_filial_phone(models.Model): _name = 'pr_filials.int_filial_phone' name = fields.Char(string="Partner-number") #, compute='_get_name_field') number = fields.Char(string="Phone") active = fields.Boolean(str

尝试从列接收数据时出错。 模型为:

class int_filial_phone(models.Model):
    _name = 'pr_filials.int_filial_phone'

    name = fields.Char(string="Partner-number") #,  compute='_get_name_field')
    number = fields.Char(string="Phone")
    active = fields.Boolean(string="Active")
    filial_addr_ids = fields.One2many('pr_filials.filial_addr', 'int_filial_phone_id', string='Address')
    filial_id = fields.Many2one('res.company',  string='Filial')
    advert_phone_ids = fields.One2many('pr_filials.advert_phone', 'int_filial_phone_id', 'Advert phone')

    _sql_constraints = [
        ('number_unique',
         'UNIQUE(number)',
         "The parameter number must be unique"),
    ]
方法:

def find_client_in_filial_phone(self, phone, table):
        cr, uid, context, registry = request.cr, request.uid, request.context, request.registry
        result = None
        table = request.env[table]
        phone = self.format_symbol_phone(phone)
        _logger.error('find_client_in_filial_phone phone: %r ', phone )
        ids = table.sudo().search([['number', '=', phone],], limit=1)
        if(len(ids)>0):
            result = table.sudo().browse(ids)[0]
        _logger.error('find_client_in_filial_phone result: %r ', result )
        return result
我尝试接收记录id:

int_phone = self.find_client_in_filial_phone(data[3], 'pr_filials.int_filial_phone')
int_phone_id = int(int_phone.id)
一切正常 当我尝试接收另一个记录字段时:

_logger.error("PHONE NAME: %r", int_phone[0].name)
我收到错误消息:

回溯(最近一次调用上次):文件 “/home/skif/odoo/openerp/http.py”,第648行,在异常处理中 返回super(JsonRequest,self)。\u handle_exception(exception)文件“/home/skif/odoo/openerp/http.py”,第685行,在分派中 结果=self.\u调用函数(**self.params)文件“/home/skif/odoo/openerp/http.py”,第321行,在调用函数中 返回选中的_调用(self.db,*args,**kwargs)文件“/home/skif/odoo/openerp/service/model.py”,第118行,在包装器中 在checked_调用中返回f(dbname,*args,**kwargs)文件“/home/skif/odoo/openerp/http.py”,第314行 结果=self.endpoint(*a,**kw)文件“/home/skif/odoo/openerp/http.py”,第964行,在调用中 返回self.method(*args,**kw)文件“/home/skif/odoo/openerp/http.py”,第514行,作为响应 response=f(*args,**kw)文件“/home/skif/odoo/openerp/my addons/pr_finance/controllers/controllers.py”, 上传文件中的第151行 _logger.error(“PHONE INT:%r”,INT_PHONE[0].name)文件“/home/skif/odoo/openerp/fields.py”,第830行,在get self.determinate_value(记录)文件“/home/skif/odoo/openerp/fields.py”,第930行,在determinate_value中 记录。预回迁字段(自)文件“/home/skif/odoo/openerp/api.py”,第248行,在包装器中 在预回迁字段中返回新的api(self、*args、**kwargs)文件“/home/skif/odoo/openerp/models.py”,第3308行 结果=wrapper中的records.read([f.name代表f-in-fs],load=''u-classic_-write')文件“/home/skif/odoo/openerp/api.py”,第248行 返回新的_api(self,*args,**kwargs)文件“/home/skif/odoo/openerp/models.py”,第3238行,读取 self.\u从包装器中第248行的数据库(存储的、继承的)文件“/home/skif/odoo/openerp/api.py”中读取 返回新的_api(self,*args,**kwargs)文件“/home/skif/odoo/openerp/models.py”,第3376行,从_数据库读取 包装器中的cr.execute(query_str,params)文件“/home/skif/odoo/openerp/sql_db.py”,第141行 在execute中返回f(self,*args,**kwargs)文件“/home/skif/odoo/openerp/sql_db.py”,第220行 res=self._obj.execute(query,params)文件“/home/skif/.local/lib/python2.7/site packages/psycopg2/extensions.py”, 第129行,在getquote中 pobjs=[adapt(o)for o in self.\u seq]编程错误:无法适应类型'pr\u filials.int\u phone'


如何从记录中接收数据?为什么我收到了id但无法从记录的其他字段接收数据?

在新版api中,当您使用“搜索”方法时,返回的值是一个记录集

def find_client_in_filial_phone(self, phone, table):
    ...
    ids = table.sudo().search([['number', '=', phone],], limit=1)
    # Here ids is a recordSet
    if(len(ids)>0):
        result = table.sudo().browse(ids)[0]
    _logger.error('find_client_in_filial_phone result: %r ', result )
    return result
例如:

旧api版本

record_ids = self.pool.get('model.name').search([('name', '=', 'Jon doe')])
# The value of record_ids is like [1,2,3,4]
records = self.pool.get('model.name').browse(records_ids)
# The value of records is like model.name(1,2,3,4)
在新版本的api中

records = self.env['model.name'].search([('name', '=', 'Jondoe')])
# The vale of records is like model.name(1,2,3,4)
在代码中,您尝试使用记录集进行浏览

def find_client_in_filial_phone(self, phone, table):
    ...
    ids = table.sudo().search([['number', '=', phone],], limit=1)
    # Here ids is a recordSet
    if(len(ids)>0):
        result = table.sudo().browse(ids)[0]
    _logger.error('find_client_in_filial_phone result: %r ', result )
    return result
你必须这样做

def find_client_in_filial_phone(self, phone, table):
    cr, uid, context, registry = request.cr, request.uid, request.context, request.registry
    table = request.env[table]
    phone = self.format_symbol_phone(phone)
    _logger.error('find_client_in_filial_phone phone: %r ', phone )
    result = table.sudo().search([['number', '=', phone],], limit=1)
    _logger.error('find_client_in_filial_phone result: %r ', result )
    return result

如果搜索未找到值,则返回一个空记录集

在新版api中,当您使用“搜索”方法时,返回的值是一个记录集

def find_client_in_filial_phone(self, phone, table):
    ...
    ids = table.sudo().search([['number', '=', phone],], limit=1)
    # Here ids is a recordSet
    if(len(ids)>0):
        result = table.sudo().browse(ids)[0]
    _logger.error('find_client_in_filial_phone result: %r ', result )
    return result
例如:

旧api版本

record_ids = self.pool.get('model.name').search([('name', '=', 'Jon doe')])
# The value of record_ids is like [1,2,3,4]
records = self.pool.get('model.name').browse(records_ids)
# The value of records is like model.name(1,2,3,4)
在新版本的api中

records = self.env['model.name'].search([('name', '=', 'Jondoe')])
# The vale of records is like model.name(1,2,3,4)
在代码中,您尝试使用记录集进行浏览

def find_client_in_filial_phone(self, phone, table):
    ...
    ids = table.sudo().search([['number', '=', phone],], limit=1)
    # Here ids is a recordSet
    if(len(ids)>0):
        result = table.sudo().browse(ids)[0]
    _logger.error('find_client_in_filial_phone result: %r ', result )
    return result
你必须这样做

def find_client_in_filial_phone(self, phone, table):
    cr, uid, context, registry = request.cr, request.uid, request.context, request.registry
    table = request.env[table]
    phone = self.format_symbol_phone(phone)
    _logger.error('find_client_in_filial_phone phone: %r ', phone )
    result = table.sudo().search([['number', '=', phone],], limit=1)
    _logger.error('find_client_in_filial_phone result: %r ', result )
    return result

如果搜索未找到值,则返回一个空记录集

编辑您的问题并添加生成错误的方法,不要将错误日志按make代码放入quote中,这样我们就可以看到我修改的错误源。在电话中呼叫find_client_后,我必须收到记录集model int_Durth_电话。当我尝试接收此记录的ID字段时-一切正常(int_phone.ID)。当我尝试接收此记录的另一个字段(例如int_phone.name)时,我接收到错误。编辑您的问题并添加生成错误的方法,不要将错误日志按make代码放入quote中,以便我们可以查看我修改的错误源。在电话中呼叫find_client_后,我必须收到记录集model int_Durth_电话。当我尝试接收此记录的ID字段时-一切正常(int_phone.ID)。当我尝试接收此记录的另一个字段(例如int_phone.name)时,我接收到错误。