Skip to Content
Odoo Menu
  • Log ind
  • Prøv gratis
  • Apps
    Økonomi
    • Bogføring
    • Fakturering
    • Udgifter
    • Regneark (BI)
    • Dokumenter
    • e-Signatur
    Salg
    • CRM
    • Salg
    • POS Butik
    • POS Restaurant
    • Abonnementer
    • Udlejning
    Hjemmeside
    • Hjemmesidebygger
    • e-Handel
    • Blog
    • Forum
    • LiveChat
    • e-Læring
    Forsyningskæde
    • Lagerbeholdning
    • Produktion
    • PLM
    • Indkøb
    • Vedligeholdelse
    • Kvalitet
    HR
    • Medarbejdere
    • Rekruttering
    • Fravær
    • Medarbejdersamtaler
    • Anbefalinger
    • Flåde
    Marketing
    • Markedsføring på sociale medier
    • E-mailmarketing
    • SMS-marketing
    • Arrangementer
    • Automatiseret marketing
    • Spørgeundersøgelser
    Tjenester
    • Projekt
    • Timesedler
    • Udkørende Service
    • Kundeservice
    • Planlægning
    • Aftaler
    Produktivitet
    • Dialog
    • Godkendelser
    • IoT
    • VoIP
    • Vidensdeling
    • WhatsApp
    Tredjepartsapps Odoo Studio Odoo Cloud-platform
  • Brancher
    Detailhandel
    • Boghandel
    • Tøjforretning
    • Møbelforretning
    • Dagligvarebutik
    • Byggemarked
    • Legetøjsforretning
    Mad og værtsskab
    • Bar og pub
    • Restaurant
    • Fastfood
    • Gæstehus
    • Drikkevareforhandler
    • Hotel
    Ejendom
    • Ejendomsmægler
    • Arkitektfirma
    • Byggeri
    • Ejendomsadministration
    • Havearbejde
    • Boligejerforening
    Rådgivning
    • Regnskabsfirma
    • Odoo-partner
    • Marketingbureau
    • Advokatfirma
    • Rekruttering
    • Audit & certificering
    Produktion
    • Tekstil
    • Metal
    • Møbler
    • Fødevareproduktion
    • Bryggeri
    • Firmagave
    Heldbred & Fitness
    • Sportsklub
    • Optiker
    • Fitnesscenter
    • Kosmetolog
    • Apotek
    • Frisør
    Håndværk
    • Handyman
    • IT-hardware og support
    • Solenergisystemer
    • Skomager
    • Rengøringsservicer
    • VVS- og ventilationsservice
    Andet
    • Nonprofitorganisation
    • Miljøagentur
    • Udlejning af billboards
    • Fotografi
    • Cykeludlejning
    • Softwareforhandler
    Gennemse alle brancher
  • Community
    Få mere at vide
    • Tutorials
    • Dokumentation
    • Certificeringer
    • Oplæring
    • Blog
    • Podcast
    Bliv klogere
    • Udannelselsesprogram
    • Scale Up!-virksomhedsspillet
    • Besøg Odoo
    Få softwaren
    • Download
    • Sammenlign versioner
    • Udgaver
    Samarbejde
    • Github
    • Forum
    • Arrangementer
    • Oversættelser
    • Bliv partner
    • Tjenester til partnere
    • Registrér dit regnskabsfirma
    Modtag tjenester
    • Find en partner
    • Find en bogholder
    • Kontakt en rådgiver
    • Implementeringstjenester
    • Kundereferencer
    • Support
    • Opgraderinger
    Github Youtube Twitter LinkedIn Instagram Facebook Spotify
    +1 (650) 691-3277
    Få en demo
  • Prissætning
  • Hjælp

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

  • CRM
  • e-Commerce
  • Bogføring
  • Lager
  • PoS
  • Projekt
  • MRP
All apps
Du skal være registreret for at interagere med fællesskabet.
All Posts People Emblemer
Tags (View all)
odoo accounting v14 pos v15
Om dette forum
Du skal være registreret for at interagere med fællesskabet.
All Posts People Emblemer
Tags (View all)
odoo accounting v14 pos v15
Om dette forum
Hjælp

i need calculate difference between two date in odoo studio

Tilmeld

Få besked, når der er aktivitet på dette indlæg

Dette spørgsmål er blevet anmeldt
calculateStudioodoo16features
3 Besvarelser
3828 Visninger
Avatar
Katalina Lagos

I'm new to odoo, I have 2 date fields, I have tried in various ways to get the calculation taken by a third field, but I can't get it to work when placing it in the view. The code I am using on the calculated field is this

for record in self:
    if record.x_studio_fecha_prevista_1 and record.create_date:
        date_diff = record.x_studio_fecha_prevista_1 - record.create_date
        record.x_studio_calculohora = date_diff.total_seconds() / 3600
    else:
        record.x_studio_calculohora = False
-1
Avatar
Kassér
Chris TRINGHAM

Hi Katalina,

I did test my solution, and when the date is changed it does recalculate the number of days. That's defining the computed field as "stored".

Don't forget to include both fields as dependencies.

Having said that, I have had problems before with computed fields! Maybe someone else can offer more advice!

Avatar
Cybrosys Techno Solutions Pvt.Ltd
Bedste svar

Hi,

In your compute function code, there appears to be an error, particularly in the computation of the date difference. Let's address the problem in the third field:

Dependencies: x_studio_start_date, x_studio_end_date

Compute:

for record in self:
    date_diff = (record.x_studio_end_date - record.x_studio_start_date).total_seconds() / 3600 if record.x_studio_start_date and record.x_studio_end_date else 0
    record['x_studio_date_difference'] = date_diff

Explanation:

The corrected code snippet calculates the date difference accurately by subtracting the end date from the start date. Additionally, it ensures that the computation only proceeds if both the start date and end date are present. If either of these dates is missing, it sets the date difference to zero.

This adjustment should resolve the error in your compute function code. If you encounter any further issues or have additional questions, feel free to ask for clarification.

Hope it helps

2
Avatar
Kassér
Avatar
Chris TRINGHAM
Bedste svar

There are many Python experts on here who will know this better than me, but this should work:

for record in self:
    if record.x_studio_fecha_prevista_1 and record.create_date:
        record['x_studio_calculohora'] = (record.x_studio_fecha_prevista_1 - record.create_date).days
    else:
        record['x_studio_calculohora'] = False

Dependencies: x_studio_calculohora, x_studio_fecha_prevista_1


1
Avatar
Kassér
Avatar
Katalina Lagos
Forfatter Bedste svar

Hi, Thank you for you reply, i tried whit both code, but it don't work, an error appears when trying to place the field in the list view in which I am performing the calculation, the operation worked at one point only because the stored option was enabled, but it gave an incorrect data for the same reason, when removing the stored option fails again.


0
Avatar
Kassér
Enjoying the discussion? Don't just read, join in!

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

Tilmeld dig
Related Posts Besvarelser Visninger Aktivitet
Odoo Studio Error
Studio odoo16features
Avatar
Avatar
Avatar
2
feb. 24
8284
Sales Order - Qty Order - OnHand - Delivered
Studio odoo16features
Avatar
1
jan. 24
2105
Error on view for an Odoo studio app Løst
Studio odoo16features
Avatar
Avatar
1
aug. 23
2352
Get date type data from chat
calculate studio odoo16features
Avatar
Avatar
1
mar. 24
2239
Odoov16 Failed to activate the web_studio module
module Studio odoo16features
Avatar
Avatar
Avatar
2
sep. 24
3342
Community
  • Tutorials
  • Dokumentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Oversættelser
Tjenester
  • Odoo.sh-hosting
  • Support
  • Opgradere
  • Individuelt tilpasset udvikling
  • Uddannelse
  • Find en bogholder
  • Find en partner
  • Bliv partner
Om os
  • Vores virksomhed
  • Brandaktiver
  • Kontakt os
  • Stillinger
  • Arrangementer
  • Podcast
  • Blog
  • Kunder
  • Juridiske dokumenter • Privatlivspolitik
  • Sikkerhedspolitik
الْعَرَبيّة 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 er en samling open source-forretningsapps, der dækker alle dine virksomhedsbehov – lige fra CRM, e-handel og bogføring til lagerstyring, POS, projektledelse og meget mere.

Det unikke ved Odoo er, at systemet både er brugervenligt og fuldt integreret.

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