gpt4 book ai didi

python - 编程错误 : can't adapt type 'stock.location' - Odoo v9

转载 作者:行者123 更新时间:2023-11-28 22:32:58 25 4
gpt4 key购买 nike

我正在迁移一个 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 的东西,

请问,对此有什么想法吗?

最佳答案

一个小错误,您试图传递直接从搜索查询中获得的 stock.location 对象而不是 id

改变这一行

if locat_lst:
prod_location = locat_lst[0]

if locat_lst:
prod_location = locat_lst[0].id

关于python - 编程错误 : can't adapt type 'stock.location' - Odoo v9,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40402301/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com