新建模块时models不能加载如何解决



  • @Siyuan
    报错如下

    Traceback (most recent call last):
      File "D:\GOdoo10\source\odoo\http.py", line 638, in _handle_exception
        return super(JsonRequest, self)._handle_exception(exception)
      File "D:\GOdoo10\source\odoo\http.py", line 675, in dispatch
        result = self._call_function(**self.params)
      File "D:\GOdoo10\source\odoo\http.py", line 331, in _call_function
        return checked_call(self.db, *args, **kwargs)
      File "D:\GOdoo10\source\odoo\service\model.py", line 119, in wrapper
        return f(dbname, *args, **kwargs)
      File "D:\GOdoo10\source\odoo\http.py", line 324, in checked_call
        result = self.endpoint(*a, **kw)
      File "D:\GOdoo10\source\odoo\http.py", line 933, in __call__
        return self.method(*args, **kw)
      File "D:\GOdoo10\source\odoo\http.py", line 504, in response_wrap
        response = f(*args, **kw)
      File "D:\GOdoo10\source\addons\web\controllers\main.py", line 866, in call_button
        action = self._call_kw(model, method, args, {})
      File "D:\GOdoo10\source\addons\web\controllers\main.py", line 854, in _call_kw
        return call_kw(request.env[model], method, args, kwargs)
      File "D:\GOdoo10\source\odoo\api.py", line 681, in call_kw
        return call_kw_multi(method, model, args, kwargs)
      File "D:\GOdoo10\source\odoo\api.py", line 672, in call_kw_multi
        result = method(recs, *args, **kwargs)
      File "D:\GOdoo10\source\odoo\addons\base\module\module.py", line 527, in button_immediate_upgrade
        return self._button_immediate_function(type(self).button_upgrade)
      File "D:\GOdoo10\source\odoo\addons\base\module\module.py", line 484, in _button_immediate_function
        modules.registry.Registry.new(self._cr.dbname, update_module=True)
      File "D:\GOdoo10\source\odoo\modules\registry.py", line 78, in new
        odoo.modules.load_modules(registry._db, force_demo, status, update_module)
      File "D:\GOdoo10\source\odoo\modules\loading.py", line 333, in load_modules
        force, status, report, loaded_modules, update_module)
      File "D:\GOdoo10\source\odoo\modules\loading.py", line 235, in load_marked_modules
        loaded, processed = load_module_graph(cr, graph, progressdict, report=report, skip_modules=loaded_modules, perform_checks=perform_checks)
      File "D:\GOdoo10\source\odoo\modules\loading.py", line 156, in load_module_graph
        _load_data(cr, module_name, idref, mode, kind='data')
      File "D:\GOdoo10\source\odoo\modules\loading.py", line 95, in _load_data
        tools.convert_file(cr, module_name, filename, idref, mode, noupdate, kind, report)
      File "D:\GOdoo10\source\odoo\tools\convert.py", line 851, in convert_file
        convert_xml_import(cr, module, fp, idref, mode, noupdate, report)
      File "D:\GOdoo10\source\odoo\tools\convert.py", line 921, in convert_xml_import
        obj.parse(doc.getroot(), mode=mode)
      File "D:\GOdoo10\source\odoo\tools\convert.py", line 802, in parse
        self.parse(rec, mode)
      File "D:\GOdoo10\source\odoo\tools\convert.py", line 805, in parse
        self._tags[rec.tag](rec, de, mode=mode)
      File "D:\GOdoo10\source\odoo\tools\convert.py", line 443, in _tag_act_window
        id = self.env['ir.model.data']._update('ir.actions.act_window', self.module, res, xml_id, noupdate=self.isnoupdate(data_node), mode=self.mode)
      File "D:\GOdoo10\source\odoo\addons\base\ir\ir_model.py", line 1159, in _update
        record = record.create(values)
      File "D:\GOdoo10\source\odoo\addons\base\ir\ir_actions.py", line 340, in create
        return super(IrActionsActWindow, self).create(vals)
      File "D:\GOdoo10\source\odoo\addons\base\ir\ir_actions.py", line 40, in create
        res = super(IrActions, self).create(vals)
      File "D:\GOdoo10\source\odoo\models.py", line 3798, in create
        record = self.browse(self._create(old_vals))
      File "D:\GOdoo10\source\odoo\models.py", line 3954, in _create
        self._validate_fields(vals)
      File "D:\GOdoo10\source\odoo\models.py", line 1058, in _validate_fields
        check(self)
      File "D:\GOdoo10\source\odoo\addons\base\ir\ir_actions.py", line 248, in _check_model
        raise ValidationError(_('Invalid model name %r in action definition.') % action.res_model)
    ParseError: "Invalid model name u'shouhou.shouhoudan' in action definition.
    None" while parsing file:///D:/GOdoo10/myaddons/shouhou/views/views.xml:38, near
    <act_window id="action_shouhou_shouhoudan" name="&#x552E;&#x540E;&#x5355;" res_model="shouhou.shouhoudan" view_mode="tree,form"/>
    
    

    应该就是模型未被成功的导入,但是却不知的为什么会导入不了



  • @zysdmjj新建模块时models不能加载如何解决 中说:

    \modles

    from . import controllers
    from . import models

    \modles

    文件夹名字错了 -_-



  • 学习odoo模块创建,

    推荐官方文档:

    https://www.odoo.com/documentation/10.0/howtos/backend.html

    Building a Module

    -_-



  • @Siyuan
    额额。。不好意思,这是我在发帖过程中的手打失误,在模块中未发生这样的低级错误。。。但是相应的,问题未被解决。。



  • @zysdmjj 看下models文件夹下有没有编译过的.pyc文件,没有的话,就是文件没有编译,把controller的import 注释掉

    -_-



  • @Siyuan
    0_1496383996370_QQ截图20170602141306.png
    有编译过的pyc文件,但是修改日期似乎不对,我是不是应该将其删除之后重新启动服务器再让其编译一次?另外听从您的建议,已将import controller注释掉了



  • @Joshua 不好意思或许还要麻烦下您,在听从上面的几位朋友的意见之后,我仍然是无法将自己的模型导入到odoo的数据库之中。现在的我真的是黔驴技穷了,恳请答疑解惑,万分感谢


  • 管理员

    你的模块有以下几个问题:

    1. .\init.py ,如果你的模块里面没有controllers,这行删掉。
    2. .\manifest.py,如果你的模块里面没有'views/templates.xml',这行删掉。
    3. .\manifest.py,如果你的模块里面没有'demo/demo.xml',,这行删掉。
    4. .\models\models.py,文件里面有中文字符,那就在首行加上编码,# -- coding: utf-8 --

    然后重启odoo服务更新模块,如果还是出错。你可以在启动odoo server的时候通过命令行参数更新模块 -d 数据库名 -u模块名或者你可以删掉旧数据库再重新安装。



  • @Joshua 感谢,我这就去进行尝试



  • 我也正在学习odoo,用命令自动生成整个模块文件很方便,我觉得你也可以尝试一下自己弄整个模块文件


登录后回复
 

与 Odoo 中文社区 的连接断开,我们正在尝试重连,请耐心等待