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

onchange method doesn't work for new records

Abonare

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

Această întrebare a fost marcată
ormonchangeodoo12
2 Răspunsuri
7455 Vizualizări
Imagine profil
Nurlan Farajov

I have python function which I want it to fill one2many field for all payslip records. Onchange method works only when I change employee_id for already created records, doesn't work for when I create new record. I need to create, save and then edit.

How can I make it work for also new records(payslips)?

all_project_hours = fields.One2many('hr.payslip.projects', 'slip_id', "Project Hours")

@api.onchange('employee_id')
def _calculate_project_hours(self):
    all_project_hours = []
    value = {}
    projects = self.env['project.project'].search([])
    for project in projects:
        domain = [('employee_id', '=', self.employee_id.name), ('date', '>=', self.date_from),
                  ('date', '<=', self.date_to),
                  ('validated', '=', True), ('is_bonus_eligible', '=', True), ('project_id', '=', project.name)]
        domain_ot = [('employee_id', '=', self.employee_id.name), ('date', '>=', self.date_from),
                     ('date', '<=', self.date_to),
                     ('validated', '=', True), ('is_bonus_eligible', '=', True), ('project_id', '=', project.name),
                     ('task_id', '=', 'Overtime')]
        all_timesheets = self.env["account.analytic.line"].search(domain)
        ot_timesheets = self.env["account.analytic.line"].search(domain_ot)
        sum_all = 0.0
        sum_ot = 0.0
        for unit in all_timesheets:
            sum_all += unit.unit_amount
        for ot in ot_timesheets:
            sum_ot += ot.unit_amount
        if self.total_project_hours > 0.0:
            split = sum_all / self.total_project_hours * 100
        else:
            split = 0.0
            return split
        all_project_hours.append(
            (0, 0, {'project_id': project.id, 'project_hours': sum_all, 'overtime_hours': sum_ot, 'project_split': split}))
    value.update(all_project_hours=all_project_hours)
    return {'value': value}
0
Imagine profil
Abandonează
Sehrish

Odoo Customization Tips: https://learnopenerp.tumblr.com/

Imagine profil
Volodymyr
Cel mai bun răspuns

Hi,

You should try to add more fields in @api.onchange() declaration, for example:

@api.onchange('employee_id', 'employee_id.name', 'date_from', 'date_to')

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
How to get the pseudo-record like one of api.onchange() ? Rezolvat
onchange odoo12
Imagine profil
Imagine profil
1
mar. 20
5322
Add month to date field Rezolvat
date orm onchange
Imagine profil
Imagine profil
2
iun. 22
18490
How to avoid onchange loop on Odoo 12
onchange loop odoo12
Imagine profil
0
mar. 22
2872
Update one2many record within the same view
orm onchange V13
Imagine profil
Imagine profil
1
ian. 22
4037
override create/write method on odoo 12 Rezolvat
orm override odoo12
Imagine profil
Imagine profil
Imagine profil
5
iun. 20
32629
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