İç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 override onchange old api vs new ?

Abone Ol

Get notified when there's activity on this post

Bu soru işaretlendi
v7apionchangeoverridev8.0
7 Cevaplar
15845 Görünümler
Avatar
Temur

Need to override onchange function from old v7 API, like this one:

Python (v7 API):

...
def onchange_field_a(self, cr, uid, ids, field_a, field_b, field_c, context=None):
    vals = {'value':{} }
    #
    # A huge code here to be executed on field_a changes...
    #
    return vals
...

XML (v7 API):

...
    <field name="field_a" on_change="onchange_field_a(field_a, field_b, field_c)"
...

v7 onchange function said to be incompatible with the new v8 api. here is related posts on this forum that I've found for now:

https://www.odoo.com/forum/help-1/question/75299 

https://www.odoo.com/forum/help-1/question/73893 

- however, we'd like to override onchange_field_a function using new v8.0 API and 1) we do not want to rewrite a huge code written in v7 onchange function, which is well tested and working in the parent model and 2) we do not want to copy-paste it either. Beside that it's bad practice to have copy of a same code in several places, it should be harder to maintain such a copy, as it's likely to receive further bugfixes and improvements (if any) in the same v7 implementation and the same place where it's defined. So, we need to reuse existing v7 onchange_field_a function code defined in the superclass by calling it from overridden v8 onchange_field_a function and add our additional code afterwards (or before,depending on case). 

1
Avatar
Vazgeç
Avatar
Temur
Üretici En İyi Yanıt

right question to ask here is what it makes incompatible onchange v7 vs v8? and can we overcome this incompatibility in order to reuse existing code? Actually it's possible by applying quite simple workaround to the onchange v7 vs v8 incompatibility:

Python (v8 API):

...
@api.onchange("field_a")
@api.depends("field_b", "field_c", "custom_field_in_my_class")
def onchange_field_a(self):

### section 1. get result of original onchange_field_a from superclass:
orig_result = super(my_class,self).onchange_field_a(self.field_a, self.field_b, self.field_c)

### section 2. workaround for api incompatibility:
if type(orig_result) is dict and orig_result.has_key('value'):
for field, value in orig_result.get('value').items():
if hasattr(self, field):
setattr(self, field, value)


### section 3. your additional code, for example:
if self.field_c:
self.custom_field_in_my_class = True
...

Old api way was to return value dictionary for changed fields, whereas new api way is to assign changes directly to fields of virtual record inside the onchange function, so in the "section 2" we turn value return through dictionary into direct assignments to fields. that's it, api incompatibility is handled by the "section 2".

Note:
field's "on_change" property in XML is no more necessary in v8 

2
Avatar
Vazgeç
Temur
Üretici
XML part: we can just ignore XML part in this case. it'll work with or without removing on_change property from corresponding XML record, this record just become redundant, but do not interfere normal execution of this overridden function.
Temur
Üretici
Note for Relational Fields: if any field from @api.onchange or @api.depends lists are relational fields, then in "section1" you have to use self.field_name.id or self.field_name.ids respectively for many2one and x2many fields. for example, if field_a has a type Many2one and field_b has a type one2many or many2many, then instead of:
orig_result = super(my_class,self).onchange_field_a(self.field_a, self.field_b, self.field_c)
we'll have:
orig_result = super(my_class,self).onchange_field_a(self.field_a.id, self.field_b.ids, self.field_c)
Temur
Üretici
Return Value: as it's v8.0 style onchange function (@api.onchange), we do NOT need to return anything. the "orig_result" result of call parent function is just used in the "section 2", where it's turned into direct assignments. No need to return anything, "section 3" is just normal v8.0 @api.onchange code with direct assignments to fields of "self"
Gavin Yap

Hi Temur, I've tried to over the onchange methood fo hr.payslip

 
    @api.onchange("contract_id")
    @api.depends( "date_from", "date_to", "employee_id", "contract_id")
    def onchange_field_a(self):
        print "do something"
it doesn't work for contract_id. Can you advise?
Temur
Üretici

if there is already a XML entry with on_change in a corresponding form view, then it may require to be replaced with on_change="1", Try to add attribute directly: <field name="contract_id" position="attributes"> <atribute name="on_change" >1</attribute></field>, if it does not work then you can simply replace entire contract_id field with itself, but with on_change="1" (pay attention to other properties in field definition as well, if there is any, in order to preserve them by the way)

Temur
Üretici

Here is original definition of contract_id in it's view:

<field name="contract_id" domain="[('employee_id','=',employee_id),('date_start','&lt;=',date_to),'|',('date_end','&gt;=',date_from),('date_end','=',False)]" on_change="onchange_contract_id(date_from, date_to, employee_id, contract_id)" context="{'default_employee_id': employee_id}"/>
There is "domain" and "context" attributes as well, most probably you'll need to preserve them, but change the existing "on_change" property, in order to have the on_change="1" record in it's place. There is a few ways to do so. Here is one of the options, inherit the view and replace on_change property of contract_id (Note: please try the "attribute" way described in the previous comment first, it's interesting if that one will work), by replacing an entire field with itself, like:
<field name="contract_id" position="replace" >
<field name="contract_id" domain="[('employee_id','=',employee_id),('date_start','&lt;=',date_to),'|',('date_end','&gt;=',date_from),('date_end','=',False)]" on_change="1" context="{'default_employee_id': employee_id}" />
</field>
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
Override Onchange Method : onchange_partner_id on account_voucher [v7]
v7 method onchange override
Avatar
Avatar
Avatar
5
Nis 17
8290
How to override the onchange_product_tmpl_id with new api?
api inherit onchange override
Avatar
Avatar
Avatar
Avatar
3
Kas 15
7962
API 8.0 onchange() and depends() decorators only work for UI changes and 1 record only?
api onchange
Avatar
Avatar
1
Haz 15
5900
Is there a v7 API guide? Çözüldü
v7 api
Avatar
Avatar
1
Mar 15
4931
Preventing On change recursion
v7 onchange
Avatar
1
Mar 15
6241
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