编程错误:无法适应类型&stock; location.location' - Odoo v9

时间:2016-11-03 13:07:09

标签: python openerp odoo-9

我正在迁移Odoo v8模块,该模块用于将.csv上传到stock.inventory模型。

我已经解决了一些问题,但我仍然有一些错误,比如这种方法:

@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)

每次,我点击调用此功能的按钮,上传它抛出的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有关,

请关于此的任何想法?

1 个答案:

答案 0 :(得分:4)

有点错误,您尝试直接从搜索查询中传递#include <signal.h> #include <stdio.h> #include <unistd.h> static void handler(int unused) { } static void child(sigset_t *ss) { unsigned int c = 0; pid_t parent_pid = getppid(); sigdelset(ss, SIGUSR1); for (;;) { sigsuspend(ss); printf("child %u\n", c++); kill(parent_pid, SIGUSR2); } } static void parent(sigset_t *ss, pid_t child_pid) { unsigned int c = 0; sigdelset(ss, SIGUSR2); for (;;) { printf("parent %u\n", c++); kill(child_pid, SIGUSR1); sigsuspend(ss); } } int main(void) { // Ensure line-buffered stdout. if (setvbuf(stdout, 0, _IOLBF, 0)) { perror("setvbuf"); return 1; } // This signal mask is in effect at all times _except_ when sleeping // in sigsuspend(). Note that _only_ the signals used for IPC are // blocked. After forking, each process will modify it appropriately // for its own use of sigsuspend(); this does not affect the kernel-side // copy made by sigprocmask(). sigset_t ss; sigemptyset(&ss); sigaddset(&ss, SIGUSR1); sigaddset(&ss, SIGUSR2); if (sigprocmask(SIG_BLOCK, &ss, 0)) { perror("sigprocmask"); return 1; } // Always use sigaction(), not signal(); signal() is underspecified. // The mask here is the signal mask to use _while the handler is // executing_; it should also block both IPC signals. struct sigaction sa; sa.sa_handler = handler; sa.sa_mask = ss; sa.sa_flags = SA_RESTART; if (sigaction(SIGUSR1, &sa, 0) || sigaction(SIGUSR2, &sa, 0)) { perror("sigaction"); return 1; } pid_t child_pid = fork(); if (child_pid < 0) { perror("fork"); return 1; } if (child_pid == 0) child(&ss); else parent(&ss, child_pid); // we never get here but the compiler might not know that return 0; } 对象,而不是ID

更改此行

import numpy as np
import scipy.io as sc

# Import matlab data
Seat = sc.loadmat('WC_Seat_Session1')
Back = sc.loadmat('WC_Back_Session1')

# Remove data from dict
Seat.pop("__globals__")
Seat.pop("__header__")
Seat.pop("__version__")
Seat.pop("ShimmerA_Timestamp_Shimmer_CAL")
Back.pop("__globals__")
Back.pop("__header__")
Back.pop("__version__")
Back.pop("id5F17_Timestamp_Shimmer_CAL")

# Create new Timestamp nessesary for next script
SF = 256
L = len(Seat['s1'])
T = L/SF
time_vec = np.arange(1/SF,T+1/SF,1/SF)


Seat_X = {'AAA': time_vec, 'SeatX':Seat['s1']}
Seat_Y = {'AAA': time_vec, 'SeatY':Seat['s2']}
Seat_Z = {'AAA': time_vec, 'SeatZ':Seat['s3']}

Back_X = {'AAA': time_vec, 'BackX':Back['b1']}
Back_Y = {'AAA': time_vec, 'BackY':Back['b2']}
Back_Z = {'AAA': time_vec, 'BackZ':Back['b3']}

# Save data as a matlab file
sc.savemat('Seat_X.mat', {'Seat_X': Seat_X }, oned_as='column')
sc.savemat('Seat_Y.mat', {'Seat_Y': Seat_Y}, oned_as='column')
sc.savemat('Seat_Z.mat', {'Seat_Z': Seat_Z}, oned_as='column')
sc.savemat('Back_X.mat', {'Back_X': Seat_X}, oned_as='column')
sc.savemat('Back_Y.mat', {'Back_Y': Seat_Y}, oned_as='column')
sc.savemat('Back_Z.mat', {'Back_Z': Seat_Z}, oned_as='column')

stock.location