Skip to Content
Odoo Menu
  • Zaloguj się
  • Wypróbuj za darmo
  • Aplikacje
    Finanse
    • Księgowość
    • Fakturowanie
    • Wydatki
    • Arkusz kalkulacyjny (BI)
    • Dokumenty
    • Podpisy
    Sprzedaż
    • CRM
    • Sprzedaż
    • PoS Sklep
    • PoS Restauracja
    • Subskrypcje
    • Wypożyczalnia
    Strony Internetowe
    • Kreator Stron Internetowych
    • eCommerce
    • Blog
    • Forum
    • Czat na Żywo
    • eLearning
    Łańcuch dostaw
    • Magazyn
    • Produkcja
    • PLM
    • Zakupy
    • Konserwacja
    • Jakość
    Zasoby Ludzkie
    • Pracownicy
    • Rekrutacja
    • Urlopy
    • Ocena pracy
    • Polecenia Pracownicze
    • Flota
    Marketing
    • Marketing Społecznościowy
    • E-mail Marketing
    • SMS Marketing
    • Wydarzenia
    • Automatyzacja Marketingu
    • Ankiety
    Usługi
    • Projekt
    • Ewidencja czasu pracy
    • Usługi Terenowe
    • Helpdesk
    • Planowanie
    • Spotkania
    Produktywność
    • Dyskusje
    • Zatwierdzenia
    • IoT
    • VoIP
    • Baza wiedzy
    • WhatsApp
    Aplikacje trzecich stron Studio Odoo Odoo Cloud Platform
  • Branże
    Sprzedaż detaliczna
    • Księgarnia
    • Sklep odzieżowy
    • Sklep meblowy
    • Sklep spożywczy
    • Sklep z narzędziami
    • Sklep z zabawkami
    Żywienie i hotelarstwo
    • Bar i Pub
    • Restauracja
    • Fast Food
    • Pensjonat
    • Dystrybutor napojów
    • Hotel
    Agencja nieruchomości
    • Agencja nieruchomości
    • Biuro architektoniczne
    • Budowa
    • Zarządzanie nieruchomościami
    • Ogrodnictwo
    • Stowarzyszenie właścicieli nieruchomości
    Doradztwo
    • Biuro księgowe
    • Partner Odoo
    • Agencja marketingowa
    • Kancelaria prawna
    • Agencja rekrutacyjna
    • Audyt i certyfikacja
    Produkcja
    • Tekstylia
    • Metal
    • Meble
    • Jedzenie
    • Browar
    • Prezenty firmowe
    Zdrowie & Fitness
    • Klub sportowy
    • Salon optyczny
    • Centrum fitness
    • Praktycy Wellness
    • Apteka
    • Salon fryzjerski
    Transakcje
    • Złota rączka
    • Wsparcie Sprzętu IT
    • Systemy energii słonecznej
    • Szewc
    • Firma sprzątająca
    • Usługi HVAC
    Inne
    • Organizacja non-profit
    • Agencja Środowiskowa
    • Wynajem billboardów
    • Fotografia
    • Leasing rowerów
    • Sprzedawca oprogramowania
    Przeglądaj wszystkie branże
  • Community
    Ucz się
    • Samouczki
    • Dokumentacja
    • Certyfikacje
    • Szkolenie
    • Blog
    • Podcast
    Pomóż w nauce innym
    • Program Edukacyjny
    • Scale Up! Gra biznesowa
    • Odwiedź Odoo
    Skorzystaj z oprogramowania
    • Pobierz
    • Porównaj edycje
    • Wydania
    Współpracuj
    • Github
    • Forum
    • Wydarzenia
    • Tłumaczenia
    • Zostań partnerem
    • Usługi dla partnerów
    • Zarejestruj swoją firmę rachunkową
    Skorzystaj z usług
    • Znajdź partnera
    • Znajdź księgowego
    • Spotkaj się z doradcą
    • Usługi wdrożenia
    • Opinie klientów
    • Wsparcie
    • Aktualizacje
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Zaplanuj demo
  • Cennik
  • Pomoc

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

  • CRM
  • e-Commerce
  • Księgowość
  • Zapasy
  • PoS
  • Projekt
  • MRP
All apps
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Pomoc

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

Zaprenumeruj

Otrzymaj powiadomienie o aktywności w tym poście

To pytanie dostało ostrzeżenie
saleonchangev14
2 Odpowiedzi
45460 Widoki
Awatar
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
Awatar
Odrzuć
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
Autor

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.

Awatar
Dries Cox
Autor Najlepsza odpowiedź

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
Awatar
Odrzuć
Awatar
Cayprol
Najlepsza odpowiedź

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
Awatar
Odrzuć
Dries Cox
Autor

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.

Podoba Ci się ta dyskusja? Dołącz do niej!

Stwórz konto dzisiaj, aby cieszyć się ekskluzywnymi funkcjami i wchodzić w interakcje z naszą wspaniałą społecznością!

Zarejestruj się
Powiązane posty Odpowiedzi Widoki Czynność
Onchange not triggered when record is altered from python code Rozwiązane
onchange v14
Awatar
Awatar
1
gru 21
7092
Is there a way to create dependencies between sale order lines?
sale v14
Awatar
Awatar
1
kwi 21
2628
Pause user interface during the calculation
onchange v14
Awatar
Awatar
2
gru 20
4886
Set UOM and precision on product without inventory module.
invoice sale v14
Awatar
1
cze 21
2651
How to set a Dynamic domain in odooV14 on a One2many list?
sale domain_filter dynamic v14
Awatar
Awatar
1
maj 24
7011
Społeczność
  • Samouczki
  • Dokumentacja
  • Forum
Open Source
  • Pobierz
  • Github
  • Runbot
  • Tłumaczenia
Usługi
  • Hosting Odoo.sh
  • Wsparcie
  • Aktualizacja
  • Indywidualne rozwiązania
  • Edukacja
  • Znajdź księgowego
  • Znajdź partnera
  • Zostań partnerem
O nas
  • Nasza firma
  • Zasoby marki
  • Skontaktuj się z nami
  • Oferty pracy
  • Wydarzenia
  • Podcast
  • Blog
  • Klienci
  • Informacje prawne • Prywatność
  • Bezpieczeństwo Odoo
الْعَرَبيّة 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 to pakiet aplikacji biznesowych typu open source, które zaspokoją wszystkie potrzeby Twojej firmy: CRM, eCommerce, księgowość, inwentaryzacja, punkt sprzedaży, zarządzanie projektami itp.

Unikalną wartością Odoo jest to, że jest jednocześnie bardzo łatwe w użyciu i w pełni zintegrowane.

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