TypeError:' int'对象在odoo中不可迭代

时间:2016-06-22 13:21:31

标签: python orm openerp typeerror odoo-8

所有

向表格添加数据时收到错误:

2016-06-22 12:14:59,292 21364 ERROR odoov8 openerp.addons.webvisitorcalc.controllers: prevouseURLsearchEngine: {'search_marker': u'q', 'id': 1, 'uniq_part_in_host': u'google'}
2016-06-22 12:14:59,292 21364 ERROR odoov8 openerp.addons.webvisitorcalc.controllers: search_engine_id: 1
2016-06-22 12:14:59,293 21364 ERROR odoov8 openerp.http: Exception during JSON request handling.
Traceback (most recent call last):
  File "/home/skif/odoo/openerp/http.py", line 540, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/home/skif/odoo/openerp/http.py", line 577, in dispatch
    result = self._call_function(**self.params)
  File "/home/skif/odoo/openerp/http.py", line 313, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/home/skif/odoo/openerp/service/model.py", line 118, in wrapper
    return f(dbname, *args, **kwargs)
  File "/home/skif/odoo/openerp/http.py", line 310, in checked_call
    return self.endpoint(*a, **kw)
  File "/home/skif/odoo/openerp/http.py", line 806, in __call__
    return self.method(*args, **kw)
  File "/home/skif/odoo/openerp/http.py", line 406, in response_wrap
    response = f(*args, **kw)
  File "/home/skif/odoo/my-modules/webvisitorcalc/controllers.py", line 179, in register_session
    writeRelationSession.write({'search_engine_id':int(1)})
  File "/home/skif/odoo/openerp/api.py", line 266, in wrapper
    return new_api(self, *args, **kwargs)
  File "/home/skif/odoo/openerp/models.py", line 3788, in write
    self._write(old_vals)
  File "/home/skif/odoo/openerp/api.py", line 266, in wrapper
    return new_api(self, *args, **kwargs)
  File "/home/skif/odoo/openerp/api.py", line 592, in new_api
    result = method(self._model, cr, uid, self.ids, *args, **old_kwargs)
  File "/home/skif/odoo/openerp/models.py", line 3816, in _write
    for wtuple in vals[field]:
TypeError: 'int' object is not iterable

我怎么能发现这是关系错误。其他关系也很好。

我的模特档案: 的 [models.py]

class SessionVisitor(models.Model):
        _name = 'webvisitorcalc.session_visitor'
        client_addr = fields.Char(string="Client IP", required=True)
        date_visit = fields.Datetime(default=fields.Datetime.now())
        date_last_check = fields.Datetime(default=fields.Datetime.now())

        target_url_ids = fields.Many2one('webvisitorcalc.url_list', string='Target URL')

        site_trip_id = fields.One2many('webvisitorcalc.site_trip', 'session_ids', string='Trip records')

        #search
        search_engine_id = fields.One2many('webvisitorcalc.search_engine', 'session_ids', string='Search engine')
        search_phrase_id = fields.One2many('webvisitorcalc.search_phrases', 'session_ids', string='Search phrase')

        # advert
        advert_company_id = fields.One2many('webvisitorcalc.advert_company', 'session_ids', string='Advert. company')
        advert_engine_id = fields.One2many('webvisitorcalc.advert_engine', 'session_ids', string='Advert. engine')


class SearchEngine(models.Model):
        _name = 'webvisitorcalc.search_engine'
        name = fields.Char(string="Engine name", required=True)
        uniq_part_in_host = fields.Char(string="Uniq part hostname", required=True)
        search_marker = fields.Char(string="marker for search phrase", required=True) # q='' для Google, text='' для Яндекс
        #utm_marker = fields.Char(string="UTM mark name", required=True)
        #url_list_ids = fields.Many2one('webvisitorcalc.url_list', string='Target URL')
        session_ids = fields.Many2one('webvisitorcalc.session_visitor', string='Session IDs')

这是带错误的代码: 的 [controllers.py]

createParam = {}
if (prevouseURLsearchEngine!={}):
                _logger.error("prevouseURLsearchEngine: %r", prevouseURLsearchEngine)
                _logger.error("search_engine_id: %r", prevouseURLsearchEngine['id'])
                createParam['search_engine_id'] = int(prevouseURLsearchEngine['id'])
                writeRelationSession.write(createParam)

你能否提出我的错误?

2 个答案:

答案 0 :(得分:0)

以下是我要尝试的内容:

createParam = {}
if prevouseURLsearchEngine:
    _logger.error("prevouseURLsearchEngine: %r", prevouseURLsearchEngine)
    _logger.error("search_engine_id: %r", prevouseURLsearchEngine['id'])
    # the search_engine field is a `OneToMany` so we are expecting an array not a scalar
    createParam['search_engine_id'] = [ int(prevouseURLsearchEngine['id']) ]
    writeRelationSession.write(createParam)

答案 1 :(得分:0)

谢谢大家的回答。 我写了错误的关系。我班级的关系必须是改变位置。