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

How to create a 'onchange' with many2one. [Solved]

Zaprenumeruj

Otrzymaj powiadomienie o aktywności w tym poście

To pytanie dostało ostrzeżenie
solved
5 Odpowiedzi
15443 Widoki
Awatar
Juan Carlos

Hi, Juan Carlos again...

As you know, I'm new in Odoo, and I would learn a lot.

Ok I'm tryin to create a On change with my field many2one, I try to learn onchange, but is very difficult for me, help please.

my.py

class DetalleFactura(models.Model):
    _name = "openacademy.detalle"

    def onchange_producto_id(self,cr,uid,ids, producto_id,context=None):
        precio = self.pool.get('product.product', 'price')
        return {precio}

    name = fields.Char(string="Titulo")
    producto_id = fields.Many2one('product.product', 'Producto')
    precio = fields.Float(string="Precio", readonly=True)

my.xml

<tree editable="bottom">

  <field name="producto_id"/>

  <field name="precio" on_change="onchange_producto_id(producto_id)"/>

</tree>

I use this code, but don't change the price value...

 

0
Awatar
Odrzuć
Juan Carlos
Autor

Thanks for the answers, I have an error with def onchange_productp_id(self): File "/opt/odoo/odoo/addons/openacademy/models.py", line 47 def onchange_producto_id(self): ^ IndentationError: unindent does not match any outer indentation level

Juan Carlos
Autor

Already solved it, sorry, and how I get the price of the product. I don't understand where is the parameters for on change functions... I read in ORM instructions, but is not all the information. My code: @api.onchange('producto_id') def _onchange_producto_id(self): if self.producto_id: self.precio = 100.00

Awatar
Harsh Dhaduk
Najlepsza odpowiedź

HI Juan,

In Odoo 8 Api following example help you to basic understand of how's work on change method and you not need to write in xml file.

my.py

class DetalleFactura(models.Model):
    _name = "openacademy.detalle"

    @api.onchange('producto_id')
    def onchange_producto_id(self):
        # Your Code but if you want to use any field use with self.producto_id like that also you can use all fields using self.<your field name>
        # About return type in this you can not return any value but you simply set your value like
        # self.precio = 100.00
        self.precio = 100.00

    name = fields.Char(string="Titulo")
    producto_id = fields.Many2one('product.product', 'Producto')
    precio = fields.Float(string="Precio", readonly=True)


my.xml

<tree editable="bottom">
  <field name="producto_id"/>
  <field name="precio" />
</tree>


if you have to learn about new API then visit official documentation for Odoo 8 Here
 


Best,
Harsh Dhaduk

4
Awatar
Odrzuć
Awatar
Ivan
Najlepsza odpowiedź

onchange need to return a dictionary in this format: {'value': {'field1': value1, 'field2': value 2}, 'domain': {'field-a': domain-a, 'field-b': domain-b}, 'warning': {'title': 'This is a warning', 'message': "You have done something terribly wrong"}}.

1
Awatar
Odrzuć
Awatar
Sehrish
Najlepsza odpowiedź

 Look into Example:

campus_id = fields.Many2one('model.campus', string="Campus Name")
department_id = fields.Many2one('model.department', string="Department Name")

I have two many2one fields (campus_id and department_id), and we want to change the department on the basis of campus field. 

Todo so we use onchange method and in onchange method we need to return domain.

1     @api.onchange('campus_id')
2    def _campus_onchange(self):
3        res = {}
4        res['domain']={'department_id':[('campus_id', '=', self.campus_id.id)]}
5        return res

For more information read: http://learnopenerp.blogspot.com/2016/10/onchange-many2one-filed-in-odoo.html

0
Awatar
Odrzuć
Sehrish

Get code description from here: http://learnopenerp.blogspot.com/2016/10/onchange-many2one-filed-in-odoo.html

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ść
[SOLVED] How to transfer live chat to another team member? Rozwiązane
livechat solved
Awatar
Awatar
1
paź 23
2180
Why would the addons_path not be picked up?
addons v7 solved
Awatar
Awatar
2
mar 15
7596
select product in module treatment
error appointment solved treatment odoo16
Awatar
0
lip 24
1041
Error for groups xml
error xml apps groups solved
Awatar
Awatar
2
kwi 24
2180
Use the video preview widget in odoo 16
widget preview video solved odoo16features
Awatar
Awatar
1
kwi 23
5065
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