Skip to Content
Odoo Meniu
  • Autentificare
  • Try it free
  • Aplicații
    Finanțe
    • Contabilitate
    • Facturare
    • Cheltuieli
    • Spreadsheet (BI)
    • Documente
    • Semn
    Vânzări
    • CRM
    • Vânzări
    • POS Shop
    • POS Restaurant
    • Abonamente
    • Închiriere
    Site-uri web
    • Constructor de site-uri
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Lanț Aprovizionare
    • Inventar
    • Producție
    • PLM
    • Achiziție
    • Maintenance
    • Calitate
    Resurse Umane
    • Angajați
    • Recrutare
    • Time Off
    • Evaluări
    • Referințe
    • Flotă
    Marketing
    • Social Marketing
    • Marketing prin email
    • SMS Marketing
    • Evenimente
    • Automatizare marketing
    • Sondaje
    Servicii
    • Proiect
    • Foi de pontaj
    • Servicii de teren
    • Centru de asistență
    • Planificare
    • Programări
    Productivitate
    • Discuss
    • Aprobări
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Aplicații Terțe Odoo Studio Platforma Odoo Cloud
  • Industrii
    Retail
    • Book Store
    • Magazin de îmbrăcăminte
    • Magazin de Mobilă
    • Magazin alimentar
    • Magazin de materiale de construcții
    • Magazin de jucării
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Distribuitor de băuturi
    • Hotel
    Proprietate imobiliara
    • Real Estate Agency
    • Firmă de Arhitectură
    • Construcție
    • Estate Managament
    • Grădinărit
    • Asociația Proprietarilor de Proprietăți
    Consultanta
    • Firma de Contabilitate
    • Partener Odoo
    • Agenție de marketing
    • Law firm
    • Atragere de talente
    • Audit & Certification
    Producție
    • Textil
    • Metal
    • Mobilier
    • Mâncare
    • Brewery
    • Cadouri corporate
    Health & Fitness
    • Club Sportiv
    • Magazin de ochelari
    • Centru de Fitness
    • Wellness Practitioners
    • Farmacie
    • Salon de coafură
    Trades
    • Handyman
    • IT Hardware and Support
    • Asigurare socială de stat
    • Cizmar
    • Servicii de curățenie
    • HVAC Services
    Altele
    • Organizație nonprofit
    • Agenție de Mediu
    • Închiriere panouri publicitare
    • Fotografie
    • Închiriere biciclete
    • Asigurare socială
    Browse all Industries
  • Comunitate
    Învăță
    • Tutorials
    • Documentație
    • Certificări
    • Instruire
    • Blog
    • Podcast
    Empower Education
    • Program Educațional
    • Scale Up! Business Game
    • Visit Odoo
    Obține Software-ul
    • Descărcare
    • Compară Edițiile
    • Lansări
    Colaborați
    • Github
    • Forum
    • Evenimente
    • Translations
    • Devino Partener
    • Services for Partners
    • Înregistrează-ți Firma de Contabilitate
    Obține Servicii
    • Găsește un Partener
    • Găsiți un contabil
    • Meet an advisor
    • Servicii de Implementare
    • Referințe ale clienților
    • Suport
    • Actualizări
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obține un demo
  • Prețuri
  • Ajutor

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

  • CRM
  • e-Commerce
  • Contabilitate
  • Inventar
  • PoS
  • Proiect
  • MRP
All apps
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Suport

How to import odoo module?

Abonare

Primiți o notificare când există activitate la acestă postare

Această întrebare a fost marcată
pythonmoduleimportinheritancewiki
21 Răspunsuri
39199 Vizualizări
Imagine profil
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
Imagine profil
Abandonează
Imagine profil
Axel Mendoza
Cel mai bun răspuns

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
Imagine profil
Abandonează
Temur
Autor

@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
Autor

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
Autor

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
Autor

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
Autor

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
Autor

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
Autor

* @Axel, not Alex :)

Axel Mendoza

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

Temur
Autor

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
Autor
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
Autor

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
Autor

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

Imagine profil
Temur
Autor Cel mai bun răspuns

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
Imagine profil
Abandonează
mustafa

This solution worked for me

Imagine profil
omar bahri
Cel mai bun răspuns

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
Imagine profil
Abandonează
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

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Înscrie-te
Related Posts Răspunsuri Vizualizări Activitate
ImportError: No module named wizard Rezolvat
module import
Imagine profil
Imagine profil
1
dec. 22
17726
How to Change the property of inherited field in OpenERP?
python inheritance
Imagine profil
0
mar. 15
6042
create a module through interface?
python module
Imagine profil
Imagine profil
1
mar. 15
5209
Error In Open Erp when create new module
python module
Imagine profil
0
mar. 15
4812
How to override a method and continue using the same method variables? v16 Rezolvat
import inheritance V16
Imagine profil
Imagine profil
1
iun. 24
2757
Comunitate
  • Tutorials
  • Documentație
  • Forum
Open Source
  • Descărcare
  • Github
  • Runbot
  • Translations
Servicii
  • Hosting Odoo.sh
  • Suport
  • Actualizare
  • Custom Developments
  • Educație
  • Găsiți un contabil
  • Găsește un Partener
  • Devino Partener
Despre Noi
  • Compania noastră
  • Active de marcă
  • Contactați-ne
  • Locuri de muncă
  • Evenimente
  • Podcast
  • Blog
  • Clienți
  • Aspecte juridice • Confidențialitate
  • Securitate
الْعَرَبيّة 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 este o suită de aplicații de afaceri open source care acoperă toate nevoile companiei dvs.: CRM, comerț electronic, contabilitate, inventar, punct de vânzare, management de proiect etc.

Propunerea de valoare unică a Odoo este să fie în același timp foarte ușor de utilizat și complet integrat.

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