İç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

Storing function field upon creation of resource in dependent model

Abone Ol

Get notified when there's activity on this post

Bu soru işaretlendi
transaction
2 Cevaplar
5515 Görünümler
Avatar
Richard Lewis

I have a function field which is defined like this:

def _get_field_value(self, cr, uid, ids, field_name, args, context=None):
    return ...

def _get_related_others(self, cr, uid, other_ids, context=None):
    return self.pool.get('this.model').search(cr, uid,
                         [('other_id','in',other_ids)], context=None)

'field': fields.function(_get_field_value, ...,
    store={'other.model': (_get_related_others, ['other_field'], 10)}),

The idea is that when the user creates a new resource in the other.model an update of 'field' is triggered. The update is triggered without any problems, but the _get_related_others can't retrieve the given other_ids from other.model. It gets passed a list containing one id (of a new other.model resource), but self.pool.get('other.model').search() returns no IDs.

I can see that the newly created other.model resource is not in the database at the time that _get_related_others is called, but isn't this just because it's in a transaction that's yet to be committed? And shouldn't the self.pool.get('other.model').search() call be working with the same transaction? And therefore have access to he newly created other.model resource?

Otherwise, please explain how/whether this is possible.

EDIT

Apologies, I abstracted my actual problem incorrectly. I'm aware that the aim is to return a list of IDs on this.model that need to be updated, but the problem is that I want to select resources from this.model which are related to the resource(s) on other.model that changed.

this.model has a field, 'other_id', that points to other.model. In my _get_related_others method I intend to select all the this.model resources where other_id is in the list of other_ids that changed. However, I find that:

self.search(cr, uid, [('other_id','in',other_ids)], context=None)

is wrong because self is actually a other.model object (I expected it to be this.model). And

self.pool.get('this.model').search(cr, uid, [('other_id','in',other_ids)], context=None)

(as I've edited to above to now read) doesn't work as it returns an empty list. It should be returning resources on this.model whose other_id field points to the newly created resource on other.model.

I hope that's a bit clearer?

0
Avatar
Vazgeç
Lucio

I am not sure what do you want to do, are you trying to look for the newly created id? Isn't that the id in other_ids?

Lucio

But if you just created the other.model, how is it that any of the this.model is related with it? If, on creation, you set the relation through other.model in, lets say, field first_model, you can access to it whit something like self.browse(cr,ids[0],context).first_model

Richard Lewis
Üretici

Now, I have to apologise again. I've worked more on this today and found that the problem was very specifically to do with the actual models I was working with, and that my abstract version here would actually work fine. So I guess this question is either 'answered' or, better, 'asked in error'; not sure if there's a state for that.

Avatar
filsystem
En İyi Yanıt

You have to return the id(s) of current model from _get_related_others, not id(s) from other.model. Try something like that:

def _get_related_others(self, cr, uid, other_ids, context=None):
    result = set()
    for om in self.pool.get('other.model').browse(cr, uid, other_ids):
        result.add(om.id)
    return list(result)
1
Avatar
Vazgeç
Avatar
Andreas Brueckl
En İyi Yanıt

In the function _get_related_others the variable other_ids contains the Ids of the model other.model.

The job of this function is to return Ids of the current model (do not know how the model is called in your example).

But returning Ids of the model other.model is not correct!

I know that this is confusing, but once you got it it will be more clear :-)

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
how to change summernote toolbar language (web_editor)
transaction
Avatar
0
Ağu 22
3270
Managing transactions between countries (Multi-currency)
transaction
Avatar
0
Mar 15
4088
Inter company transfer
transaction intercompany
Avatar
Avatar
1
Ağu 20
9172
How to remove all the transactions? Çözüldü
warehouses transaction
Avatar
Avatar
Avatar
2
Kas 19
18130
accessing one record with two counters at once
transaction counter
Avatar
0
Ağu 16
4319
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