Ich habe ein Modul migriert, das stock.inventory
Bewegungen erstellen kann, indem ich csvs hochlade.AttributeError: 'int' Objekt hat kein Attribut 'id' - Odoo v9 Community
Es funktioniert ganz gut, aber manchmal, wenn ich bestimmte csv die hochladen, wirft sie mir diesen Fehler:
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) for 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'
Der Code ist dies:
@api.one
def action_import(self):
"""Load Inventory data from the 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 to select a file!"))
# Decode the 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 a 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'})
for i in range(len(reader_info)):
val = {}
field = reader_info[i]
values = dict(zip(keys, field))
prod_location = location.id
if 'location' in values and 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 and 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)
Und der Blick des csv wie folgt aus:
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
Dieser Fehler erscheint von Zeit zu Zeit, oft funktioniert es einfach ohne Probleme, aber einige o Theres mal wirft diesen Fehler auf.
Es ist genau auf location
Spalte.
Ich habe CSV mit mehr als 5k Elemente, so ist es schwierig für mich, den Fehler zu verfolgen.
Ist diese csv verwandt? Oder ist es eine Frage des Codes?
Hallo @ cricket_007 vielen Dank, entschuldigen Sie, bitte, wissen Sie eine Abhilfe dafür? Ich meine, scheint, als ob die Objekte nicht übereinstimmen, oder? – NeoVe
Ich kenne diese Bibliothek nicht, die Sie verwenden, sorry. Nur 'prod_location' wird auf eine Ganzzahl gesetzt.Sie müssen die if-Anweisung reparieren, um 'prod_location = locat_lst [0]' zu bekommen, um immer zu laufen –
Vielen Dank, wenn es schief geht, öffne ich eine neue Frage, Nochmals vielen Dank! – NeoVe