系统中找不到外部ID - Odoo v9社区

时间:2017-03-02 01:29:15

标签: python openerp odoo-9

这是一个非常奇怪的行为,它正在工作,现在我正要将我的模块安装在另一个数据库上,并且突然出现了关于外部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列的订单吗?

有什么想法吗?

2 个答案:

答案 0 :(得分:1)

可能是您的xml文件未创建位置。

您可以尝试以下操作:

从xml文件中删除 noupdate =“1”属性,然后重新启动Odoo服务器并升级自定义模块。

然后转到位置菜单并检查 ReparacionUnidades 是否创建。如果它创建,那么我们可以在xml文件中放回 noupdate =“1”属性。

现在,检查 x_location_dest_id 值。它应该给你欲望输出。

答案 1 :(得分:1)

如果您确定您的XML ID在文件中,并且THE XML FILE在return中。然后问题是__openerp__.py中的XML文件的顺序,你需要尊重XML ID顺序,你不能引用不持久保存在数据库中的ID。