İçereği Atla
Odoo Menü
  • Portal
  • Ücretsiz deneyin
  • Uygulamalar
    Finans
    • Muhasebe
    • Faturalama
    • Masraf Yönetimi
    • Elektronik Çizelge (BI)
    • Belgeler
    • İmza
    Satış
    • Müşteri İlişkileri Yönetimi (CRM)
    • Satış
    • Satış Noktası Mağaza
    • Satış Noktası Restoran
    • Abonelikler
    • Kiralama
    Web Sitesi
    • Web Sitesi Oluşturucu
    • eTicaret
    • Blog
    • Forum
    • Canlı Sohbet
    • eÖğrenme
    Tedarik Zinciri
    • Envanter
    • Üretim
    • Ürün Yaşam Döngüsü Yönetimi
    • Satın Alma
    • Bakım
    • Kalite
    İnsan Kaynakları
    • Çalışanlar
    • İşe Alım
    • İzin
    • Değerlendirme
    • Referans
    • Filo Yönetimi
    Pazarlama
    • Sosyal Medyada Pazarlama
    • E-posta ile Pazarlama
    • SMS ile Pazarlama
    • Etkinlikler
    • Pazarlama Otomasyonu
    • Anket
    Hizmetler
    • Proje Yönetimi
    • Çalışma Çizelgeleri
    • Saha Hizmeti
    • Yardım Masası
    • Planlama
    • Randevular
    Verimlilik
    • Sohbet
    • Onay
    • Nesnelerin İnterneti
    • VoIP
    • Bilgi Bankası
    • WhatsApp
    Üçüncü taraf uygulamalar Odoo Stüdyo Odoo Bulut Platformu
  • Sektörler
    Perakende satış
    • Kitapçı
    • Giyim Mağazası
    • Mobilya Mağazası
    • Gıda Marketi
    • Hırdavat Dükkanı
    • Oyuncak Dükkanı
    Gıda ve Konaklama
    • Bar ve Pub
    • Restoran
    • Fast Food Restoranı
    • Konuk Evi
    • İçecek Distribütörü
    • Otel
    Gayrimenkul
    • Emlak Acentesi
    • Mimarlık Firması
    • İnşaat
    • Emlak Yönetimi
    • Bahçe Tasarımı
    • Mülk Sahipleri Derneği
    Uzmanlık
    • Muhasebe Firması
    • Odoo Partner
    • Pazarlama Ajansı
    • Hukuk Firması
    • Yetenek Kazanımı
    • Denetim ve Belgelendirme
    Üretim
    • Tekstil
    • Metal
    • Mobilyalar
    • Gıda
    • Bira fabrikası
    • Kurumsal Hediye
    Sağlık ve Spor
    • Spor Kulübü
    • Optik Mağazası
    • Fitness Merkezi
    • Sağlıklı Yaşam Merkezi
    • Eczane
    • Kuaför Salonu
    Ticaret
    • Tamirci
    • BT Donanım & Destek
    • Güneş Enerjisi Sistemleri
    • Ayakkabı İmalatçısı
    • Temizlik Hizmetleri
    • HVAC Hizmetleri
    Diğerleri
    • Kar Amacı Gütmeyen Kuruluş
    • Çevre Ajansı
    • Reklam Panosu Kiralama
    • Fotoğrafçılık
    • Bisiklet Kiralama
    • Yazılım Bayisi
    Tüm Sektörlere Göz Atın
  • Topluluk
    Öğrenim
    • Eğitim Araçları
    • Dokümantasyon
    • Sertifikasyonlar
    • Eğitim Etkinlikleri
    • Blog
    • Podcast
    Eğitim ve Gelişim
    • Eğitim Programı
    • Scale Up! İşletme Oyunu
    • Odoo'yu Ziyaret Edin
    Yazılım
    • İndirin
    • Sürümleri Kıyaslayın
    • Sürümler
    İş Birliği
    • Github
    • Forum
    • Etkinlikler
    • Çeviriler
    • Partner Olun
    • Partnerler için Hizmetler
    • Muhasebe Firmanızı Kaydettirin
    Hizmetler
    • Partner Bulun
    • Muhasebeci Bulun
    • Bir danışmanla görüşün
    • Kurulum Hizmetleri
    • Müşteri Referansları
    • Destek
    • Sürüm Yükseltme
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Demo randevusu alın
  • Fiyatlandırma
  • Yardım

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

  • Müşteri İlişkileri Yönetimi
  • e-Commerce
  • Muhasebe
  • Envanter
  • PoS
  • Proje Yönetimi
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiketler (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiketler (View all)
odoo accounting v14 pos v15
About this forum
Yardım

How to invoke a Controller function from inside a Model function ?

Abone Ol

Get notified when there's activity on this post

Bu soru işaretlendi
modelsession_idcontrollerroute
18 Cevaplar
23588 Görünümler
Avatar
PY

Hi !

I basically try to invoke a function from within a Controller that does exactly what I want. But, I can't reach it, neither by importing this controller, nor by using it's route.

To use the function directly, I need an instance of this controller.

To use the route method, I tried using Requests (Python) and a simple get on the route. However, I need the session_id in the headers. And I can't retrieve that info within the Model function, where I am.

I tried with request.session_id, but I got this error:

Traceback (most recent call last):
File "/home/odoo/server/openerp/service/server.py", line 929, in preload_registries
registry = RegistryManager.new(dbname, update_module=update_module)
File "/home/odoo/server/openerp/modules/registry.py", line 370, in new
openerp.modules.load_modules(registry._db, force_demo, status, update_module)
File "/home/odoo/server/openerp/modules/loading.py", line 351, in load_modules
force, status, report, loaded_modules, update_module)
File "/home/odoo/server/openerp/modules/loading.py", line 255, in load_marked_modules
loaded, processed = load_module_graph(cr, graph, progressdict, report=report, skip_modules=loaded_modules, perform_checks=perform_checks)
File "/home/odoo/server/openerp/modules/loading.py", line 176, in load_module_graph
_load_data(cr, module_name, idref, mode, kind='data')
File "/home/odoo/server/openerp/modules/loading.py", line 118, in _load_data
tools.convert_file(cr, module_name, filename, idref, mode, noupdate, kind, report)
File "/home/odoo/server/openerp/tools/convert.py", line 901, in convert_file
convert_xml_import(cr, module, fp, idref, mode, noupdate, report)
File "/home/odoo/server/openerp/tools/convert.py", line 987, in convert_xml_import
obj.parse(doc.getroot(), mode=mode)
File "/home/odoo/server/openerp/tools/convert.py", line 853, in parse
self._tags[rec.tag](self.cr, rec, n, mode=mode)
File "/home/odoo/server/openerp/tools/convert.py", line 379, in _tag_function
_eval_xml(self,rec, self.pool, cr, uid, self.idref, context=context)
File "/home/odoo/server/openerp/tools/convert.py", line 230, in _eval_xml
res = getattr(model, method)(cr, uid, *args)
File "/home/odoo/server/openerp/api.py", line 241, in wrapper
return old_api(self, *args, **kwargs)
File "/home/odoo/server/openerp/api.py", line 336, in old_api
result = method(recs, *args, **kwargs)
File "/home/odoo/my_addons/vimexcom/models/company.py", line 62, in set_params
headers = {'cookie': 'session_id=%s' % request.session_id}
File "/usr/lib/python2.7/dist-packages/werkzeug/local.py", line 336, in __getattr__
return getattr(self._get_current_object(), name)
File "/usr/lib/python2.7/dist-packages/werkzeug/local.py", line 295, in _get_current_object
return self.__local()
File "/usr/lib/python2.7/dist-packages/werkzeug/local.py", line 131, in _lookup
raise RuntimeError('object unbound')
ParseError: "object unbound" while parsing /home/odoo/my_addons/vimexcom/data/data.xml:10, near
<function model="res.company" name="set_params"/>

Any tips would be appreciated.

Thanks !

0
Avatar
Vazgeç
Sehrish

hope this will helps: https://learnopenerp.blogspot.com/2020/08/unbound-method-call-controller-function-from-another-controller-odoo.html

Avatar
Temur
En İyi Yanıt

if it may help you, then you can get session id as follows:

from openerp import http


session_id = http.request.session.sid


UPDATE:

Controllers are registering itself in the openerp.http.controllers_per_module dict (see code)... so you can get controller instance using module name and controller name under it:

from openerp.http import controllers_per_module

controller_instance = None
for name,instance in controllers_per_module.get('my_module'): if name.endswith('my_module.controller.name'): controller_instance = instance break if controller_instance != None: controller_instance.a_function(*args)




1
Avatar
Vazgeç
PY
Üretici

I tried that, but I got an error (can't remember the error).

PY
Üretici

Updated my question.

Temur

http.request.session.sid gives you a session id string.

PY
Üretici

Same error with request.session.sid

Temur

ok. it seems session id does not helps

PY
Üretici

thanks anyway, I'll find a workaround one day, I'm sure ^^

Temur

you mention direct call, what is problem with it?

PY
Üretici

Oh, yeah, if I import the controller (from addons/website/controllers/main import Website) and use it (let's say ... Website.some_function(*args)), I get a "unbound method blablabla must be called with Website instance as first argument ..." But, hey, where do I find that instance ? Can I create one ?

Temur

actually you can create, if you'll have all arguments to "constructor" if required, if no such requirement then it may be as simple as:

Website().some_function(*args)), 
PY
Üretici

Oh yeah, I'm so stupid. And I pretend to be a developper ? Thanks, I'll try that on Monday ! Good we !

Temur

for ordinary python object it works, I don't know if it'll work for a controller without side effects :) Good we!

Temur

As I doubted it has side effect to create controller instance, it registering itself in a global dict.. and you can get existing instance from there... see updated answer.

PY
Üretici

Ok, so far, that's an amazing answer ! But, what if the controller is not registered ? Can I safely instanciate one ?

Temur

Normally it should be registered. as we can see in the code, all direct children of a "Controller" (i.e. "http.Controller") class are registered. So, if a controller class you're interested in is a child of the Controller class, then it's surely registered there. you'll need just figure out it's full name under it's own module in order to find it in the "controllers_per_module". Try to print or log the "controllers_per_module" variable and check if it's a case. Most probably it'll be registered. if not, then you can try to instantiate one and check if it's a safe operation...

PY
Üretici

Ok, no, nothing works, and I think it's because my method is called on module update, so, maybe not all the controllers are instanciated at this moment (the Website controller specifically). But, hey, your answer is the right one I think, and I'll accept that. And, for the record, I just copy/pasted/shortened the content of the method I wanted to call so... problem solved.

Avatar
Axel Mendoza
En İyi Yanıt

Maybe you need to call your function in another moment, like after the models registry(pool) is loaded. You could do this by implementing the method _register_hook in your model. Odoo will always call that method in your model to allow you to initialize whatever you want, but you just have the self and cr arguments.

Maybe helps

1
Avatar
Vazgeç
Enjoying the discussion? Don't just read, join in!

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

Üye Ol
İlgili Gönderiler Cevaplar Görünümler Aktivite
session_id as GET parameter in URL returns 404
session_id controller route
Avatar
Avatar
Avatar
3
Eki 15
12837
Get current model informations in the controller Çözüldü
model controller
Avatar
Avatar
2
Tem 24
3436
http.route(... auth="none") not working in Odoo11 Çözüldü
controller route
Avatar
4
Eki 20
6912
Problem with the controller routes
controller route
Avatar
Avatar
2
Mar 16
5172
Get model data in a controller Çözüldü
orm model controller
Avatar
Avatar
Avatar
Avatar
4
Eki 21
38531
Topluluk
  • Eğitim Araçları
  • Dokümantasyon
  • Forum
Açık Kaynak
  • İndirin
  • Github
  • Runbot
  • Çeviriler
Hizmetler
  • Odoo.sh Hosting
  • Destek
  • Sürüm Yükseltme
  • Özel Geliştirmeler
  • Eğitim
  • Muhasebeci Bulun
  • Partner Bulun
  • Partner Olun
Hakkında
  • Şirketimiz
  • Pazarlama Gereçleri
  • İletişim
  • Kariyer
  • Etkinlikler
  • Podcast
  • Blog
  • Müşteriler
  • Hukuki • Gizlilik
  • Güvenlik
الْعَرَبيّة 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, müşteri ilişkileri yönetimi, eTicaret, muhasebe, envanter, satış noktası, proje yönetimi gibi şirketinizin tüm ihtiyaçlarını karşılayan bir açık kaynak işletme uygulamaları paketidir.

Odoo’nun eşsiz değer önermesi, aynı anda hem kullanımının çok kolay olup hem de tamamen entegre olmasıdır.

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