2016-11-03 2 views
0

Я переношу модуль Odoo v8, который используется для загрузки .csv в модель stock.inventory.ProgrammingError: невозможно адаптировать тип 'stock.location' - Odoo v9

Я исправил несколько вещей, но я до сих пор некоторые ошибки на нем, как этот метод:

@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 
     val['inventory_id'] = inventory.id 
     val['fail'] = True 
     val['fail_reason'] = _('No processed') 
     inv_imporline_obj.create(val) 

Everytime, я нажимаю на кнопку, которая призывает к этой функции, чтобы загрузить файл CSV он бросает мне это:

2016-11-02 23:18:38,659 16865 ERROR moto_backup openerp.http: Exception during JSON request handling. 
Traceback (most recent call last): 
File "/home/kristian/odoov9/odoo-9.0/openerp/http.py", line 648, in _handle_exception 
return super(JsonRequest, self)._handle_exception(exception) 
File "/home/kristian/odoov9/odoo-9.0/openerp/http.py", line 685, in dispatch 
result = self._call_function(**self.params) 
File "/home/kristian/odoov9/odoo-9.0/openerp/http.py", line 321, in _call_function 
return checked_call(self.db, *args, **kwargs) 
File "/home/kristian/odoov9/odoo-9.0/openerp/service/model.py", line 118, in wrapper 
return f(dbname, *args, **kwargs) 
File "/home/kristian/odoov9/odoo-9.0/openerp/http.py", line 314, in checked_call 
result = self.endpoint(*a, **kw) 
File "/home/kristian/odoov9/odoo-9.0/openerp/http.py", line 964, in call 
return self.method(*args, **kw) 
File "/home/kristian/odoov9/odoo-9.0/openerp/http.py", line 514, in response_wrap 
response = f(*args, **kw) 
File "/home/kristian/odoov9/odoo-9.0/addons/web/controllers/main.py", line 892, in call_button 
action = self._call_kw(model, method, args, {}) 
File "/home/kristian/odoov9/odoo-9.0/addons/web/controllers/main.py", line 880, in _call_kw 
return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs) 
File "/home/kristian/odoov9/odoo-9.0/openerp/api.py", line 250, in wrapper 
return old_api(self, *args, **kwargs) 
File "/home/kristian/odoov9/odoo-9.0/openerp/api.py", line 421, in old_api 
result = new_api(recs, *args, **kwargs) 
File "/home/kristian/odoov9/odoo-9.0/openerp/api.py", line 425, in new_api 
result = [method(rec, *args, **kwargs) for rec in self] 
File "/home/kristian/odoov9/motostion_addons/odoomrp-wip-9.0/stock_inventory_import/wizard/import_inventory.py", line 89, in action_import 
inv_imporline_obj.create(val) 
File "/home/kristian/odoov9/odoo-9.0/openerp/api.py", line 248, in wrapper 
return new_api(self, *args, **kwargs) 
File "/home/kristian/odoov9/odoo-9.0/openerp/models.py", line 4157, in create 
record = self.browse(self._create(old_vals)) 
File "/home/kristian/odoov9/odoo-9.0/openerp/api.py", line 248, in wrapper 
return new_api(self, *args, **kwargs) 
File "/home/kristian/odoov9/odoo-9.0/openerp/api.py", line 490, in new_api 
result = method(self._model, cr, uid, *args, **old_kwargs) 
File "/home/kristian/odoov9/odoo-9.0/openerp/models.py", line 4301, in _create 
tuple([u[2] for u in updates if len(u) > 2]) 
File "/home/kristian/odoov9/odoo-9.0/openerp/sql_db.py", line 141, in wrapper 
return f(self, *args, **kwargs) 
File "/home/kristian/odoov9/odoo-9.0/openerp/sql_db.py", line 220, in execute 
res = self._obj.execute(query, params) 
ProgrammingError: can't adapt type 'stock.location' 

Я предполагаю, что это что-то с новым API, что я не хватает,

Пожалуйста, любые идеи по этому поводу?

ответ

2

Немного ошибка, вы пытаетесь передать stock.location объект, который вы получили непосредственно из поискового запроса вместо идентификатора

Изменение этой линии

if locat_lst: 
    prod_location = locat_lst[0] 

в

if locat_lst: 
    prod_location = locat_lst[0].id 
+0

LoL , Спасибо, как я этого не заметил, спасибо! – NeoVe

+1

Может быть усталость программирования :) – danidee

+0

Всего xD Cheers – NeoVe