这是一个非常奇怪的行为,它正在工作,现在我要在另一个数据库上安装我的模块,突然出现有关外部ID的错误。
这是我在模型中的代码:
def _static_location(self):
return self.env.ref('fleet_stock.location_stock')
然后我从现场调用此函数:
x_location_dest_id = fields.Many2one('stock.location', string=u'Ubicacion Destino de Productos', required=True,
readonly=False, default=_static_location,
help="Location where the system will look for components.")
location_stock
属性位于数据文件夹中的xml文件中,声明如下:<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="1">
<record id="location_stock" model="stock.location">
<field name="name">ReparacionUnidades</field>
<field name="location_id" ref="stock.stock_location_locations_virtual"/>
<field name="usage">production</field>
<field name="company_id"></field>
</record>
</data>
</openerp>
在
__openerp__.py
文件上: "data": [
'data/location_data.xml',
'data/fleet_stock_data.xml',
'views/fleet_vehicle_log_services.xml',
],
当我尝试安装它时,将其抛出:
Traceback (most recent call last):
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/http.py", line 648, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/http.py", line 685, in dispatch
result = self._call_function(**self.params)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/http.py", line 321, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/service/model.py", line 118, in wrapper
return f(dbname, *args, **kwargs)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/http.py", line 314, in checked_call
result = self.endpoint(*a, **kw)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/http.py", line 964, in __call__
return self.method(*args, **kw)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/http.py", line 514, in response_wrap
response = f(*args, **kw)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/addons/web/controllers/main.py", line 892, in call_button
action = self._call_kw(model, method, args, {})
File "/home/kristian/odoov9/odoo-9.0c-20161106/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 "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/api.py", line 250, in wrapper
return old_api(self, *args, **kwargs)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/addons/base/module/module.py", line 459, in button_immediate_install
return self._button_immediate_function(cr, uid, ids, self.button_install, context=context)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/api.py", line 250, in wrapper
return old_api(self, *args, **kwargs)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/addons/base/module/module.py", line 534, in _button_immediate_function
registry = openerp.modules.registry.RegistryManager.new(cr.dbname, update_module=True)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/modules/registry.py", line 386, in new
openerp.modules.load_modules(registry._db, force_demo, status, update_module)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/modules/loading.py", line 338, in load_modules
loaded_modules, update_module)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/modules/loading.py", line 237, in load_marked_modules
loaded, processed = load_module_graph(cr, graph, progressdict, report=report, skip_modules=loaded_modules, perform_checks=perform_checks)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/modules/loading.py", line 137, in load_module_graph
init_module_models(cr, package.name, models)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/modules/module.py", line 300, in init_module_models
result = obj._auto_init(cr, {'module': module_name})
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/api.py", line 250, in wrapper
return old_api(self, *args, **kwargs)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/models.py", line 2643, in _auto_init
self._set_default_value_on_column(cr, k, context=context)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/api.py", line 250, in wrapper
return old_api(self, *args, **kwargs)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/models.py", line 2399, in _set_default_value_on_column
default = default(self, cr, SUPERUSER_ID, context)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/api.py", line 250, in wrapper
return old_api(self, *args, **kwargs)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/api.py", line 354, in old_api
result = method(recs, *args, **kwargs)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/fields.py", line 82, in <lambda>
return api.model(lambda model: field.convert_to_write(value(model)))
File "/home/kristian/odoov9/danisan/fleet_stock/models/fleet_vehicle_services.py", line 122, in _static_location
return self.env.ref('fleet_stock.location_stock')
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/api.py", line 792, in ref
return self['ir.model.data'].xmlid_to_object(xml_id, raise_if_not_found=raise_if_not_found)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/api.py", line 248, in wrapper
return new_api(self, *args, **kwargs)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/api.py", line 490, in new_api
result = method(self._model, cr, uid, *args, **old_kwargs)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/addons/base/ir/ir_model.py", line 1019, in xmlid_to_object
t = self.xmlid_to_res_model_res_id(cr, uid, xmlid, raise_if_not_found)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/api.py", line 250, in wrapper
return old_api(self, *args, **kwargs)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/addons/base/ir/ir_model.py", line 1005, in xmlid_to_res_model_res_id
return self.xmlid_lookup(cr, uid, xmlid)[1:3]
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/api.py", line 250, in wrapper
return old_api(self, *args, **kwargs)
File "<string>", line 2, in xmlid_lookup
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/tools/cache.py", line 85, in lookup
value = d[key] = self.method(*args, **kwargs)
File "/home/kristian/odoov9/odoo-9.0c-20161106/openerp/addons/base/ir/ir_model.py", line 995, in xmlid_lookup
raise ValueError('External ID not found in the system: %s' % (xmlid))
ValueError: External ID not found in the system: fleet_stock.location_stock
但这是完全荒谬的,可以正常工作,而且是我的模块,该模块称为
fleet_stock
,那是什么?是
data
文件中__openerp__.py
列上的顺序吗?有任何想法吗?
最佳答案
可能是不是根据您的xml文件创建的位置。
您可以尝试以下操作:
从您的xml文件中删除noupdate =“ 1”属性,然后重新启动Odoo服务器并升级您的自定义模块。
然后转到“位置”菜单,检查是否创建了ReparacionUnidades。如果创建,则可以在xml文件中放回noupdate =“ 1”属性。
现在,检查您的x_location_dest_id值。它应该给您期望的输出。
关于python - 在系统中找不到外部ID-Odoo v9社区,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42545268/