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

api.onchange modification One2many field with NewItem does not works

Zaprenumeruj

Otrzymaj powiadomienie o aktywności w tym poście

To pytanie dostało ostrzeżenie
one2many many2one custom field
3910 Widoki
Awatar
Richard Kellner

In version v9.x I have defined models that have One2many and Many2one relation:

Sample code, that doesn't works for me (created in new module):

class ClassA(models.Model):    
    _name = 'module.class_a'    
    
    CYCLE = 'cycle'   
    AMOUNT = 'amount'   
    Other = (        
        (CYCLE, 'Cycle'),        
        (AMOUNT, 'Amount')    
    )    
    name = fields.Char(string='Name', required=True)   
    other_influence = fields.Selection(Other, string='Other influence', required=True)   
    related = fields.One2many('module.class_b', 'components')   
    
    @api.onchange('other_influence')    
    def _other_influence_change(self):        
        self.related = None       
        if self.other_influence == self.CYCLE:            
            b = {               
                'name': 'XXX', # Lets say we do generate something here, hardocded just to show the problem
            }           
            self.related += self.related.new(b)
    
class ClassB(models.Model):   
    _name = 'module.class_b'   
    
    name = fields.Char(string='Name', required=True)   
    components = fields.Many2one('module.class_a', ondelete='no action')

When user create new entry for ClassA in view I would expect when clicking on Other influence dropdown and select Cycle in new XXX will appear in related, however what happen is that a new blank line appear, and when trying to save it ends up with error.

openerp.sql_db: bad query:  SELECT "module_class_b"."components" as "components","module_class_b"."id" as "id" FROM "module_class_b"
                        WHERE "module_class_b".id IN ('one2many_v_id_53')  ORDER BY "module_class_b"."id"

I know the difference betweem new and create, but if I change new to create in line

self.related += self.related.create(b) 

and click at Other influence field view works fine and new row is added, e.g. Name field contains XXX. Save works as well, but this is obviously bad setup as each click on Other influence would create and entry in DB (but works, both updated view and also store, but create shouldn't be used here instead on new).

I would like to click at Other influence field in view function _other_influence_change is triggered with

self.related += self.related.new(b)

and new row is added in view, and it shows data from variable b, eg. Name field contains XXX. And save to the DB successfully once user pres the save button.

I have tried to look for existing bugs and also advises how to do it properly but nothing doesn't seems to work, colleague of mine told me that this has worked fine in v8.x. Thanks for the advises.

0
Awatar
Odrzuć
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ść
Specifing FK and PK in One2many relation in v15 via Studio
one2many many2one custom field
Awatar
0
lis 22
132
[Odoo13][Form view - many2one / one2many] Display problem on my one2many field, in my project module form view
one2many many2one custom field
Awatar
Awatar
2
sie 20
3561
How can i change the displayed value of a custom many2one selection field?
one2many many2one custom field
Awatar
0
mar 15
4286
show One2Many field list base another model field
one2many one2many many2one custom field
Awatar
Awatar
Awatar
2
maj 25
3100
How to automatically fill all records from one2many tree view of model b into one2many tree view of model a? (Odoo 13) Rozwiązane
relationship many2one_list one2many_list one2many many2one custom field Odoo13
Awatar
1
paź 23
5689
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