python - AttributeError: 'int' object has no attribute 'id' - Odoo v9 community -


i've migrated module can create stock.inventory movements, uploading csv's.

it's functioning quite good, sometimes, when upload csv's, throws me error:

odoo  odoo server error  traceback (most recent call last): file "/usr/lib/python2.7/dist-packages/openerp/http.py", line 648, in _handle_exception return super(jsonrequest, self)._handle_exception(exception) file "/usr/lib/python2.7/dist-packages/openerp/http.py", line 685, in dispatch result = self._call_function(**self.params) file "/usr/lib/python2.7/dist-packages/openerp/http.py", line 321, in _call_function return checked_call(self.db, *args, **kwargs) file "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 118, in wrapper return f(dbname, *args, **kwargs) file "/usr/lib/python2.7/dist-packages/openerp/http.py", line 314, in checked_call result = self.endpoint(*a, **kw) file "/usr/lib/python2.7/dist-packages/openerp/http.py", line 964, in __call__ return self.method(*args, **kw) file "/usr/lib/python2.7/dist-packages/openerp/http.py", line 514, in response_wrap response = f(*args, **kw) file "/usr/lib/python2.7/dist-packages/openerp/addons/web/controllers/main.py", line 892, in call_button action = self._call_kw(model, method, args, {}) file "/usr/lib/python2.7/dist-packages/openerp/addons/web/controllers/main.py", line 880, in _call_kw return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs) file "/usr/lib/python2.7/dist-packages/openerp/api.py", line 250, in wrapper return old_api(self, *args, **kwargs) file "/usr/lib/python2.7/dist-packages/openerp/api.py", line 421, in old_api result = new_api(recs, *args, **kwargs) file "/usr/lib/python2.7/dist-packages/openerp/api.py", line 425, in new_api result = [method(rec, *args, **kwargs) rec in self] file "/usr/lib/python2.7/dist-packages/openerp/custom_addons/stock_inventory_import/wizard/import_inventory.py", line 85, in action_import val['location_id'] = prod_location.id attributeerror: 'int' object has no attribute 'id' 

the code this:

@api.one def action_import(self):     """load inventory data csv file."""     ctx = self._context     stloc_obj = self.env['stock.location']     inventory_obj = self.env['stock.inventory']     inv_imporline_obj = self.env['stock.inventory.import.line']     product_obj = self.env['product.product']     if 'active_id' in ctx:         inventory = inventory_obj.browse(ctx['active_id'])     if not self.data:         raise exceptions.warning(_("you need select file!"))     # decode file data     data = base64.b64decode(self.data)     file_input = cstringio.stringio(data)     file_input.seek(0)     location = self.location     reader_info = []     if self.delimeter:         delimeter = str(self.delimeter)     else:         delimeter = ','     reader = csv.reader(file_input, delimiter=delimeter,                         lineterminator='\r\n')     try:         reader_info.extend(reader)     except exception:         raise exceptions.warning(_("not valid file!"))     keys = reader_info[0]     # check if keys exist     if not isinstance(keys, list) or ('code' not in keys or                                       'quantity' not in keys):         raise exceptions.warning(             _("not 'code' or 'quantity' keys found"))     del reader_info[0]     values = {}     actual_date = fields.date.today()     inv_name = self.name + ' - ' + actual_date     inventory.write({'name': inv_name,                      'date': fields.datetime.now(),                      'imported': true, 'state': 'confirm'})     in range(len(reader_info)):         val = {}         field = reader_info[i]         values = dict(zip(keys, field))         prod_location = location.id         if 'location' in values , values['location']:             locat_lst = stloc_obj.search([('name', '=',                                            values['location'])])             if locat_lst:                 prod_location = locat_lst[0]         prod_lst = product_obj.search([('default_code', '=',                                         values['code'])])         if prod_lst:             val['product'] = prod_lst[0].id         if 'lot' in values , values['lot']:             val['lot'] = values['lot']         val['code'] = values['code']         val['quantity'] = values['quantity']         val['location_id'] = prod_location.id         val['inventory_id'] = inventory.id         val['fail'] = true         val['fail_reason'] = _('no processed')         inv_imporline_obj.create(val) 

and csv's this:

id       product_id     reference                   code    combinacion avanzadastock   location                            quantity    qty 2780    piloto trasero  recambio ecológico original m0002780                            gsx 600 f 600 1988-1991/4316/a8i    1    

this error appears time time, works without problems, other times throws error.

it on location column.

i have csv's more 5k items, it's difficult me track error.

is csv related? or matter of code?

issue logic

prod_location = location.id 

then following if statement never entered, , move

val['location_id'] = prod_location.id 

and error thrown


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -