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

[v13] Update one2many field after a change in its parent

Abonare

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

Această întrebare a fost marcată
one2manyonchangeparentOdoo13.0v13
2 Răspunsuri
9026 Vizualizări
Imagine profil
Víctor

I'm trying to apply a global discount to invoices (v13). I don't want to modify the way Odoo calculates the invoice amount, so all I'm doing is change the discount field for every account.move.line of the invoice.

I create the global_discount field in account.move:​

class AccountMove(models.Model):
_inherit = 'account.move'

global_discount = fields.Float(string='Global Discount (%)', digits='Discount', default=0.0)
​

Now, I want to change the discount field when global_discount is modified, but @api.onchange is not being called when doing so. It doesn't work adding either the parent reference or a related field to the decorator:

class AccountMoveLine(models.Model):
_inherit = 'account.move.line'

global_discount = fields.Float(related='move_id.global_discount')

# This method is not being called when changing global_discount
@api.onchange('move_id.global_discount', 'global_discount')
def _compute_discount(self):
for line in self:
# Simplified for easy reading, I'm not actually doing this
line.discount = line.global_discount

Even if I make discount a computed field and use @api.depends, its onchange methods won't be called.
If I modify the lines from an onchange method in the parent, the discount onchange methods won't be called and  price_subtotal will not change:

class AccountMove(models.Model):
_inherit = 'account.move'

@api.onchange('global_discount')
def _compute_discount(self):
for invoice in self:
for line in invoice.invoice_line_ids:
line._compute_discount()

I have also tried calling the onchange methods manually, but I'm definitely doing something wrong because nothing new happens:

@api.onchange('global_discount')
def _compute_discount(self):
for invoice in self:
for line in invoice.invoice_line_ids:
line._compute_discount()
spec = line._onchange_spec()
values = dict(line._cache)

# onchange returns and empty dict {}
updates = line.onchange(values, 'discount', spec)

value = updates.get('value', {})

for name, val in value.items():
if isinstance(val, tuple):
value[name] = val[0]

values.update(value)
line.update(values)

I'm missing something on how Odoo calls onchange methods from python, but I can't figure it out.

0
Imagine profil
Abandonează
Imagine profil
Víctor
Autor Cel mai bun răspuns

I had to call _move_autocomplete_invoice_lines_values() in the parent move after updating the discount for the changes to be propagated.

0
Imagine profil
Abandonează
Imagine profil
Ibrahim ALdaw
Cel mai bun răspuns

 in account.move  use this Methods Instead:

    @api.onchange('global_discount')
def _compute_discount(self):
for line in self.invoice_line_ids:
line.update({'discount':self.global_discount})
0
Imagine profil
Abandonează
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
On change is not triggered Rezolvat
one2many onchange Odoo13.0
Imagine profil
Imagine profil
1
ian. 21
6259
Many2one dependant booleans Rezolvat
onchange Odoo13.0 v13
Imagine profil
Imagine profil
1
dec. 19
3572
fill a field up based on domain condition Rezolvat
onchange Odoo13.0
Imagine profil
Imagine profil
Imagine profil
5
dec. 22
6379
One2many-field based on value in many2one-field Rezolvat
one2many Odoo13.0
Imagine profil
Imagine profil
1
ian. 21
4189
How to update two levels o2m fileds relation
one2many onchange
Imagine profil
0
sept. 20
3762
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