Skip to Content
Odoo Meniu
  • Autentificare
  • Try it free
  • Aplicații
    Finanțe
    • Contabilitate
    • Facturare
    • Cheltuieli
    • Spreadsheet (BI)
    • Documente
    • Semn
    Vânzări
    • CRM
    • Vânzări
    • POS Shop
    • POS Restaurant
    • Abonamente
    • Închiriere
    Site-uri web
    • Constructor de site-uri
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Lanț Aprovizionare
    • Inventar
    • Producție
    • PLM
    • Achiziție
    • Maintenance
    • Calitate
    Resurse Umane
    • Angajați
    • Recrutare
    • Time Off
    • Evaluări
    • Referințe
    • Flotă
    Marketing
    • Social Marketing
    • Marketing prin email
    • SMS Marketing
    • Evenimente
    • Automatizare marketing
    • Sondaje
    Servicii
    • Proiect
    • Foi de pontaj
    • Servicii de teren
    • Centru de asistență
    • Planificare
    • Programări
    Productivitate
    • Discuss
    • Aprobări
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Aplicații Terțe Odoo Studio Platforma Odoo Cloud
  • Industrii
    Retail
    • Book Store
    • Magazin de îmbrăcăminte
    • Magazin de Mobilă
    • Magazin alimentar
    • Magazin de materiale de construcții
    • Magazin de jucării
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Distribuitor de băuturi
    • Hotel
    Proprietate imobiliara
    • Real Estate Agency
    • Firmă de Arhitectură
    • Construcție
    • Estate Managament
    • Grădinărit
    • Asociația Proprietarilor de Proprietăți
    Consultanta
    • Firma de Contabilitate
    • Partener Odoo
    • Agenție de marketing
    • Law firm
    • Atragere de talente
    • Audit & Certification
    Producție
    • Textil
    • Metal
    • Mobilier
    • Mâncare
    • Brewery
    • Cadouri corporate
    Health & Fitness
    • Club Sportiv
    • Magazin de ochelari
    • Centru de Fitness
    • Wellness Practitioners
    • Farmacie
    • Salon de coafură
    Trades
    • Handyman
    • IT Hardware and Support
    • Asigurare socială de stat
    • Cizmar
    • Servicii de curățenie
    • HVAC Services
    Altele
    • Organizație nonprofit
    • Agenție de Mediu
    • Închiriere panouri publicitare
    • Fotografie
    • Închiriere biciclete
    • Asigurare socială
    Browse all Industries
  • Comunitate
    Învăță
    • Tutorials
    • Documentație
    • Certificări
    • Instruire
    • Blog
    • Podcast
    Empower Education
    • Program Educațional
    • Scale Up! Business Game
    • Visit Odoo
    Obține Software-ul
    • Descărcare
    • Compară Edițiile
    • Lansări
    Colaborați
    • Github
    • Forum
    • Evenimente
    • Translations
    • Devino Partener
    • Services for Partners
    • Înregistrează-ți Firma de Contabilitate
    Obține Servicii
    • Găsește un Partener
    • Găsiți un contabil
    • Meet an advisor
    • Servicii de Implementare
    • Referințe ale clienților
    • Suport
    • Actualizări
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obține un demo
  • Prețuri
  • Ajutor

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

  • CRM
  • e-Commerce
  • Contabilitate
  • Inventar
  • PoS
  • Proiect
  • MRP
All apps
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Suport

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

Abonare

Primiți o notificare când există activitate la acestă postare

Această întrebare a fost marcată
solved
5 Răspunsuri
15447 Vizualizări
Imagine profil
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
Imagine profil
Abandonează
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

Imagine profil
Harsh Dhaduk
Cel mai bun răspuns

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
Imagine profil
Abandonează
Imagine profil
Ivan
Cel mai bun răspuns

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
Imagine profil
Abandonează
Imagine profil
Sehrish
Cel mai bun răspuns

 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
Imagine profil
Abandonează
Sehrish

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

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Înscrie-te
Related Posts Răspunsuri Vizualizări Activitate
[SOLVED] How to transfer live chat to another team member? Rezolvat
livechat solved
Imagine profil
Imagine profil
1
oct. 23
2180
Why would the addons_path not be picked up?
addons v7 solved
Imagine profil
Imagine profil
2
mar. 15
7596
select product in module treatment
error appointment solved treatment odoo16
Imagine profil
0
iul. 24
1042
Error for groups xml
error xml apps groups solved
Imagine profil
Imagine profil
2
apr. 24
2180
Use the video preview widget in odoo 16
widget preview video solved odoo16features
Imagine profil
Imagine profil
1
apr. 23
5067
Comunitate
  • Tutorials
  • Documentație
  • Forum
Open Source
  • Descărcare
  • Github
  • Runbot
  • Translations
Servicii
  • Hosting Odoo.sh
  • Suport
  • Actualizare
  • Custom Developments
  • Educație
  • Găsiți un contabil
  • Găsește un Partener
  • Devino Partener
Despre Noi
  • Compania noastră
  • Active de marcă
  • Contactați-ne
  • Locuri de muncă
  • Evenimente
  • Podcast
  • Blog
  • Clienți
  • Aspecte juridice • Confidențialitate
  • Securitate
الْعَرَبيّة 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 este o suită de aplicații de afaceri open source care acoperă toate nevoile companiei dvs.: CRM, comerț electronic, contabilitate, inventar, punct de vânzare, management de proiect etc.

Propunerea de valoare unică a Odoo este să fie în același timp foarte ușor de utilizat și complet integrat.

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