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

Use Onchange on one record to change fields on other records.

Abone Ol

Get notified when there's activity on this post

Bu soru işaretlendi
saleonchangev14
2 Cevaplar
45457 Görünümler
Avatar
Dries Cox

Hello Community,
I am writing some code that changes the value of a field in all the lines of a sales order.  So if a user changed the category_id in one sale order line, other lines should be change this categ_id as well.

But for some reason this is not working. The values on other lines are not updated and stay the same like nothing happened. 

class SaleOrderLine(models.Model):
_inherit="sale.order.line"

@api.onchange('categ_id')
def _onchange_categ_id(self):
    
    for changed_line in self:
            #find all lines of the parent sale_order
             all_lines = changed_line.order_id.order_line
            vals = {'categ_id': changed_line.categ_id}
            for line in all_lines:
                line.update(vals)
    return {}

-> update to give more clarification on what the reason behind this code is.

The reason for this that, in the bigger picture, is that I can create groups of sale order lines, separated by line_sections. Each group of lines has the same categ_id, so if the categ_id of a section changes, all the lines in this section should change to the categ_id as well.

All the help is welcome.

Greetings,

1
Avatar
Vazgeç
Cayprol

In that case I think it's not possible,

In the ORM API documentation,

It is not possible for a one2many or many2many field to modify itself via onchange. This is a webclient limitation - see #2693.

https://www.odoo.com/documentation/13.0/reference/orm.html

https://github.com/odoo/odoo/issues/2693

Dries Cox
Üretici

I think you're right. That is a pity, I will have to look for an other solution.

can you change your remark to an answer so we can set that as the right answer? Thanks again for the help.

Avatar
Dries Cox
Üretici En İyi Yanıt

Hello, I found a solution for this problem.

I changed the onchange function that happens in the line of a One2many so it sets a flag that it is changed.

Then I added a onchange function on the "order_line"-field in the order model. This onchange method is triggered as well after a line changed and it is triggered the last in line after a change in the records.

In the onchange-orderline function I check the states of the flags, reset them and preform the necessary action using a function call on the sale object. (don't know if it is necessary to do it with a function call, but I saw that in sale.order.line onchange fiscal postition)

That does the job. The lines are changed on-screen!

class SaleOrderLine(models.Model):
    _inherit="sale.order.line"

    categ_changed = fields.Boolean("technical field, do not use or show to user", default = False)

    @api.onchange('categ_id')
    def _onchange_categ_id(self)
        for line in self:
            line.categ_changed = True
        return True

    def change_categs(self, changed_lines_lst)
        for line in self
            if self.id in changed_lines_lst:
                self.categ_changed = False
                #do necessary update actions within this line
        return

class SaleOrder(models.Model):
    _inherit="sale.order"

    @api.onchange('order_line')
    def _onchange_order_line(self)
        #we need to get this from te context because object might not be the same as screen values.
        ctx_lines = self.env.context.get('order_line')
        changed_lines_lst = []
        if ctx_lines:
            for ctx_line in ctx_lines:
                if ctx_line[2]:
                    if ctx_line[2].get("categ_changed")
                        changed_lines_lst.append(ctx_line[1])

           for order in self:
                self.order_line.change_categs(changed_lines_lst)

adding context to view:
<xpath expr="//field[@name='order_line']" position="attributes">
<attribute
name="context">{"order_line": order_line}</attribute>
</xpath>


Good luck :-)
3
Avatar
Vazgeç
Avatar
Cayprol
En İyi Yanıt

Update:

In that case I think it's not possible,

In the ORM API documentation,

It is not possible for a one2many or many2many field to modify itself via onchange. This is a webclient limitation - see #2693.

https://www.odoo.com/documentation/13.0/reference/orm.html

https://github.com/odoo/odoo/issues/2693


If I understand correctly,

You are trying to change a field name 'categ_id' in model 'sale.order', and you modify this field from a view in model 'sale.order', likely from view_id 'sale.view_order_form'

The expected behavior is that all 'order_line' records will have a corresponding field to be changed to the same.

If so, you don't need to use onchange, I use a Char field named 'categ_idd' as an example

class SaleOrder(models.Model): 
    _inherit = 'sale.order'
    categ_idd = fields.Char('Categ IDD')

class SaleOrderLine(models.Model):
    _inherit = 'sale.order.line'
    categ_idd = fields.Char('Categ IDD', related='order_id.categ_idd')
0
Avatar
Vazgeç
Dries Cox
Üretici

Hello, this is not really what I am looking for. It should be that categ_id is a field of the sale.order.line and if the field categ_id is changed on one line it should change on other sale.order.lines as well.

The reason for this that, in the bigger picture, i can create groups of sale order lines, separated by line_sections. Each group of lines has the same categ_id, so if the categ_id of a section changes, all the lines in this section should change as well to the same categ_id. -> I will add this explanation to my question as well this might clarify my question more. Thank you for your answer.

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
Onchange not triggered when record is altered from python code Çözüldü
onchange v14
Avatar
Avatar
1
Ara 21
7092
Is there a way to create dependencies between sale order lines?
sale v14
Avatar
Avatar
1
Nis 21
2628
Pause user interface during the calculation
onchange v14
Avatar
Avatar
2
Ara 20
4886
Set UOM and precision on product without inventory module.
invoice sale v14
Avatar
1
Haz 21
2651
How to set a Dynamic domain in odooV14 on a One2many list?
sale domain_filter dynamic v14
Avatar
Avatar
1
May 24
7010
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