跳至内容
Odoo 菜单
  • 登录
  • 免费试用
  • 应用程序
    财务
    • 会计
    • 发票
    • 费用
    • 电子表格 (BI)
    • 文档
    • 电子签名
    销售
    • 客户关系管理
    • 销售
    • POS 销售点管理-零售
    • POS 销售点管理 - 餐厅
    • 订阅
    • 租赁
    网站
    • 网站设计
    • 电子商务
    • 博客
    • 论坛
    • 在线客服
    • 在线学习
    供应链
    • 库存
    • 制造
    • 产品生命周期
    • 采购
    • 维护保养
    • 品控
    人力资源
    • 员工
    • 招聘
    • 休假
    • 评价
    • 内部推荐
    • 车队
    营销
    • 社媒营销
    • 电邮营销
    • 短信营销
    • 近期活动
    • 营销自动化
    • 网上调查
    服务
    • 项目管理
    • 工时单
    • 现场服务
    • 服务台
    • 排期
    • 预约
    生产力
    • 讨论
    • 批核
    • IoT物联网
    • VoIP
    • 知识库
    • WhatsApp
    第三方应用软件 Odoo 定制 Odoo云端平台
  • 行业
    零售
    • 书店
    • 服装店
    • 家具店
    • 食品杂货店
    • 五金店
    • 玩具店
    餐饮与酒店服务
    • 酒吧及酒馆
    • 餐厅
    • 快餐
    • 民宿
    • 饮品分销商
    • 酒店
    房地产
    • 房地产代理
    • 建筑师事务所
    • 建造业
    • 地产管理
    • 园艺
    • 业主协会
    咨询
    • 会计师事务所
    • Odoo合作伙伴
    • 市场推广公司
    • 律师事务所
    • 人才招聘
    • 审核 & 认证
    制造
    • 纺织
    • 金属
    • 家具
    • 食品
    • 啤酒厂
    • 企业礼品
    保健与健身
    • 体育俱乐部
    • 眼镜店
    • 健身中心
    • 健康从业者
    • 药房
    • 发型屋
    商贸服务
    • 维修人员
    • IT 硬件及支持
    • 太阳能系统
    • 鞋匠
    • 清洁服务
    • 暖通空调服务
    其他
    • 非营利组织
    • 环境机构
    • 广告牌租赁
    • 摄影服务
    • 自行车租赁
    • 软件经销商
    浏览所有行业
  • 社区
    学习
    • 教学视频
    • 文档
    • 认证
    • 培训
    • 博客
    • 播客
    赋能教育
    • 教育计划
    • Scale Up! 商业游戏
    • 参观Odoo
    获取软件
    • 下载
    • 版本对比
    • 发布
    合作
    • Github
    • 论坛
    • 近期活动
    • 翻译
    • 成为合作伙伴
    • 合作伙伴服务
    • 注册您的会计事务所
    获取服务
    • 寻找合作伙伴
    • 查找会计服务
    • 预约顾问咨询
    • 安装及推行服务
    • 客户参考
    • 支持
    • 升级
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    获取演示
  • 定价
  • 技术支持

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • 客户关系管理
  • e-Commerce
  • 会计
  • 库存
  • PoS
  • 项目
  • MRP
All apps
只限注册用戶才可与社群互动。
所有帖文 人 徽章
标签 (查看所有)
odoo accounting v14 pos v15
关于此论坛区
只限注册用戶才可与社群互动。
所有帖文 人 徽章
标签 (查看所有)
odoo accounting v14 pos v15
关于此论坛区
帮助

How to import odoo module?

订阅

此帖文有活动时,接收通知

此问题已终结
pythonmoduleimportinheritancewiki
21 回复
39217 查看
形象
Temur

In order to extend or override controller function in odoo, it's necessary to extend it as normal python class (see controllers reference ). To do so, we'll need to import the original module of controller class, but normally odoo modules are not on the sys.path... so we can't import them directly. How to import then odoo module in order to override a controller in our module?

3
形象
丢弃
形象
Axel Mendoza
最佳答案

all the Odoo modules are added to the openerp.addons package, your controller A in the module testx could be imported in the module testy like:

from openerp.addons.testx.controllers.main import A
...
class my_controller(A):
@api.route()
def controller_func(self,**kw):
result = super(my_controller,self).controller_func(**kw)
       # your stuff here....
       return result

 

3
形象
丢弃
Temur
编写者

@Alex, your box is too small :D What about community modules? they surely are outside of openerp.addons package? As I suggest in my answer, openerp.conf.addons_paths way guarantees to include any module path (community or custom) and so, import them successfully. And if you have any custom module, it's not a recommended way to add your odoo modules to the original module folder of odoo. What about custom odoo modules, at custom path? You should ask me about, if you had some doubts buddy, I just listed 2 cases where your answer can't work... you'd better mark my answer as accepted instead of inaccurate downvote

Temur
编写者

Do you know where community modules are stored as you install them in Odoo?

Axel Mendoza

Odoo add every module that get loaded into the package openerp.addons, take a look at:

def initialize_sys_path(): 
""" Setup an import-hook to be able to import OpenERP addons from the different addons paths. This ensures something like ``import crm`` (or even ``import openerp.addons.crm``) works even if the addons are not in the PYTHONPATH. """
Temur
编写者

It does not worked for me in case of community module. You think I've not tried simple "import module" statement before going to this workaround?

Axel Mendoza

I not mean:

import module
I mean:
import openerp.addons.module
Axel Mendoza

Odoo do this:

sys.modules['openerp.addons.' + module_part] = mod
for every module that need to be loaded
Temur
编写者

Nice, "import openerp.addons.module" is a much simpler then a workaround I found, I'll try it. But, it's not intuitive to me, to use "openerp.addons.module" for a python module that is actually far away from addons directory.

Axel Mendoza

It joins all the addons modules found in all the addons_paths in that package(that not means that odoo copy the module to the /openerp/addons folder) so a module with the same name of one in the get replaced the original one.

Temur
编写者

quote: "This ensures something like ``import crm`` (or even ``import openerp.addons.crm``) " means "import module" should work as well, and "import openerp.addons.module" indicated as an additional functionality to this...

Temur
编写者

And I can confirm that for "import module" that's NOT a case, you can't import community or custom module with just "import module" way (regardless of the comment quoted from odoo code), and if one does not investigates code as does @Alex, then it's not intuitive to use "import openerp.addons.module" for other modules then modules really located in odoo addons folder. I read once again my question post on this thread and I do not find anything wrong with it, all the details provided in my question post are exact and accurate, and it's downvoted, I do not get you buddies. And this question makes sense, because of existence of community modules and custom modules, outside of default addons path, what was actual problem for me (to be exact, the community one), and my answer here was perhaps ugly but complete and working solution, downvoted as well (relatively acceptable downvote compared to downvote of the question above). Your answer @Alex provide us with much more elegant way to solve the problem, so I'll mark it as accepted, I want to have marked as accepted the best answers on my questions, counting that I do not always get one. Thanks

Temur
编写者

* @Axel, not Alex :)

Axel Mendoza

it's a valid question, I upvote it to get it > 0

Temur
编写者

Thanks @Axel :) BTW I figured out that I've some mysterious fan on this forum, it's Dr Obx, it was he, who downvoted my question above. He is very interesting person, first he downvoted question and I got -1, then he took back his downvote and the -1 turned in zero(but it leaves effect of -1 in this forum). He've also downvoted few other questions/answers and I've got 6 negative vote from him, by now his votes some are -1, some are 0 (0 means he took back his vote, either negative or positive, but on this post I've seen that it was negative), but not even one +1... Perhaps as a being human I happen to write bad Q/A sometimes, but not always I think... and there is other interesting pattern in his behavior as well, he generally downvotes already upvoted posts (for example this one), so his downvote stays invisible, downvote to this post was an exception to this pattern, but it was part of another, he takes back his downvotes, when it's no more invisible. For now, he is author of about half negative votes I ever got on this forum (in contrast of being far from authoring half of positive votes), and all of -1 are invisible according his pattern, he first show his face on this post. I simply interested if I gave him any vote, and that's a case, I upvoted +1 his post once, in addition to helping him and accompanying him down to the solution, and that's all my votes to him. For now, I understand his behavior and when and how and according which patterns he follows me, but I do not yet understand why, because all his downvotes are far from being honest :) of course I'm not going to do same to him, as he will run out of the necessary carma to post anything here, and so, I'll stay with no fans, now at least I have interesting one :)

Temur
编写者
maybe he'll respond there? He may have some original idea though... who knows...
Axel Mendoza

Sorry to hear that. Maybe he could bring a light to his behavior

Temur
编写者

No, you have not to be, We have not to be sorry... he's just exception fortunately, "Dr Dislike", most of people are cool out there... Only thing I'm sorry about is that I spent too much time to investigate his behavior on this forum... But it was interesting anyway, as a new thing :) Next time I'll ignore such cases if any...

Temur
编写者

for anyone interested, this way was posted somewhere on this forum, you can put it into the browser console:

var get_likes_by_post = function(post_id) {
    openerp.jsonRpc('/web/dataset/call_kw', 'call', {
        model: 'forum.post.vote',
        method: 'search_read',
        args: [[['post_id','=',post_id]], ['user_id', 'vote']],
        kwargs: { context: openerp.website.get_context()}
    }).then(function(result) { 
        function vote(x) { 
            this.user_name = x.user_id[1];
            this.user_id = x.user_id[0];
            this.vote = parseInt(x.vote);
        }
        res = [];
        _.forEach(result, function(x){ res.push(new vote(x)); }); 
        console.table(res, ['vote','user_id','user_name']);
    })
}
for this question post, it'll like:
get_likes_by_post(87139)
Axel Mendoza

In the case that you need it, I migrate that script to Odoo Forum v9, see it at:
https://www.odoo.com/es_ES/forum/help-1/question/how-to-know-who-vote-for-your-questions-or-answers-in-odoo-forum-v9-script-update-94628

mustafa

It doesn't work for me!, i can't import a custom module, i just need to put my custom module or the community module under /odoo/openerp/addons/ directory so that i can use import from openerp.addons.mymodule

Axel Mendoza

Hi Mustafa, seems that your modules are not loaded correctly because you don't set correctly the addons_path option in the config or command-line

形象
Temur
编写者 最佳答案

Adding those modules to sys.path just before importing it in our python code may be a solution if we know/find path to the imported module, but such code may NOT be portable in some cases. fortunately there is pretty nice solution if we consider to use configuration entry inside the odoo: openerp.conf.addons_paths, using value of this config we can find/import odoo module as follows:

from openerp import conf
import imp

fp, pathname, description = imp.find_module('odoo_module_to_import',conf.addons_paths)
module_mod = imp.load_module('odoo_module_to_import', fp, pathname, description)

that's it. in the module_mod we have imported odoo module named "odoo_module_to_import". If we imagine that odoo modules are on the sys.path and we can import them directly, then the above code should be equivalent of :

import odoo_module_to_import as module_mod

now you can use module_mod in order to inherit your own controller from it and override/extend functions in the parent controller, for example:

class my_controller(module_mod.controllers.parent_controller):
@api.route()
def controller_func(self,**kw):
result = super(my_controller,self).controller_func(**kw)
# your stuff here....
return result

1
形象
丢弃
mustafa

This solution worked for me

形象
omar bahri
最佳答案

i create page has 3 classes and every class inherit from model

it is work for first time then show to me Key error

0
形象
丢弃
Axel Mendoza

I don't see anything related, could you explain a little more your issue? or post a question with your code so someone could help you to fix your issue

喜欢讨论吗?不要只阅读,加入进来!

立即创建账户,享受专属功能,与我们的精彩社区互动!

注册
相关帖文 回复 查看 活动
ImportError: No module named wizard 已解决
module import
形象
形象
1
12月 22
17738
How to Change the property of inherited field in OpenERP?
python inheritance
形象
0
3月 15
6046
create a module through interface?
python module
形象
形象
1
3月 15
5217
Error In Open Erp when create new module
python module
形象
0
3月 15
4815
How to override a method and continue using the same method variables? v16 已解决
import inheritance V16
形象
形象
1
6月 24
2764
社区
  • 教学视频
  • 文档
  • 论坛
开源
  • 下载
  • Github
  • Runbot
  • 翻译
服务
  • Odoo.sh 托管
  • 支持
  • 升级
  • 自定义开发服务
  • 教育
  • 查找会计服务
  • 寻找合作伙伴
  • 成为合作伙伴
关于我们
  • 我们的公司
  • 品牌资产
  • 联系我们
  • 招聘
  • 近期活动
  • 播客
  • 博客
  • 客户
  • 法律 • 隐私
  • 安全
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo致力于为企业管理提供高效智能的开源解决方案,是全球业内高速成长的软件服务商之一,逾七百五十万用户选择Odoo进行数字化升级。通过一系列全业务链覆盖、高度集成、简单易用的商业应用,助力企业实现信息化改革、降本增效并释放公司增长潜力。

Odoo独特的价值在于是一款非常容易使用又完全集成的应用。

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now