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
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Managament
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Producție
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware and Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    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 access the vals dict.

Abonare

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

Această întrebare a fost marcată
createvals
4 Răspunsuri
7740 Vizualizări
Imagine profil
Tarek Mohamed Ibrahim

I created a new record in a one2many field in a view, e.g. the order.line in a sales order screen. I need after each new line added in the detail, the one2many field, to sum the total amount of the order via an onchange method in the qty or price fields. I don't need to go to the 'update' button and click it each time I need to update the total amount. How to do that?

----

My idea is to access the vals array that is sent to the 'create' method when saving a record, I need to access it before saving.

0
Imagine profil
Abandonează
Imagine profil
Axel Mendoza
Cel mai bun răspuns

The one2many fields store the values in a format described on the write method of the model. For this task you need to pass the one2many field for the on_change method and check the state of their records in order to properly sum your total, something like this:

 def onchange_line_ids(self, cr, uid, ids, order_lines, context=None):  
    total = 0
    line_pool = self.pool.get('sale.order.line')
   for line in order_lines: 
if line[0] == 0:
             total += line[2].get('qty', 0)
        elif line[0] == 4:
            total += line_pool.browse(cr, uid, line[1], context=context).qty
        elif line[0] == 1:
             if line[2].get('qty', False):
                 total += line[2].get('qty', 0)
            else:
                 total += line_pool.browse(cr, uid, line[1], context=context).qty  
   return {'value': {'total': total}}

2
Imagine profil
Abandonează
Tarek Mohamed Ibrahim
Autor

in the onchange method of the price I passed the 'order_id.order_line' and it didn't recognize it. I then passed only the 'order_id' on hope to access 'order_line' in the method, but it gave me what is called 'Newid' and was not able to accomplish my task

Axel Mendoza

You cannot do that, you need to put the onchange on the main form level to be able to pass order_line field, you could put the onchange to the order_line field itself because it's the main source of changes that you need to monitor, and pass only order_line instead of order.order_line, in the view you cannot move very easily over relation fields

Tarek Mohamed Ibrahim
Autor

thx Axel for answer, it has worked. I accepted the answer and gave you an upvote

Imagine profil
Pawan
Cel mai bun răspuns

Hi Tarek, 

If i am wright, you want to sum of total price/qty in your one2many field. you can simply add an attribute "sum" at the qty/price field under tree tag, like:

<tree> [your one2many field tree view]

<field name="[your field]" sum="Total" />

........

</tree>

it will show sum of your fields data at the end of tree view.....

Hope it helps!!    

0
Imagine profil
Abandonează
Tarek Mohamed Ibrahim
Autor

I've already did that and I can see the sum of the amounts every time I do a change in qty or price in any line. My case is different, that is, I have a field that defines the upper limit of a Sales Order amount, this field is per customer, and I read this field in the sale_order class via a function and display it on the order header. When saving the order, the create/write method checks if the sum of the line amounts exceeded this limit, then it raises an exception and stops the save action. The user then have to go to lines and reduce qtys until the amounts sum go below the upper limit allowed. I need this be done automatically via an onchange method. I checked the last reply from Axel and still didn't try it. I think it would work

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
Can't get some values from vals
create vals
Imagine profil
0
sept. 17
4647
What does vals mean ,and how to use it in the case of overriding the create() & write() methods ? Rezolvat
create write vals
Imagine profil
Imagine profil
1
aug. 16
11573
Create new bug
create
Imagine profil
0
apr. 24
2827
vals for relationship fields (one2many) Rezolvat
one2many create v7 vals
Imagine profil
Imagine profil
1
dec. 22
6808
how i can update value of field in create method in Odoo v13 CE
create
Imagine profil
0
dec. 19
5360
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