Skip to Content
Odoo Menu
  • Prisijungti
  • Išbandykite nemokamai
  • Programėlės
    Finansai
    • Apskaita
    • Pateikimas apmokėjimui
    • Sąnaudos
    • Skaičiuoklė (BI)
    • Dokumentai
    • Pasirašymas
    Pardavimai
    • CRM
    • Pardavimai
    • Kasų sistema - Parduotuvė
    • Kasų sistema - Restoranas
    • Prenumeratos
    • Nuoma
    Svetainės
    • Svetainių kūrėjimo įrankis
    • El. Prekyba
    • Internetinis Tinklaraštis
    • Forumas
    • Tiesioginis pokalbis
    • eMokymasis
    Tiekimo grandinė
    • Atsarga
    • Gamyba
    • PLM
    • Įsigijimai
    • Priežiūra
    • Kokybė
    Žmogaus ištekliai
    • Darbuotojai
    • Įdarbinimas
    • Atostogos
    • Įvertinimai
    • Rekomendacijos
    • Transporto priemonės
    Rinkodara
    • Socialinė rinkodara
    • Rinkodara el. paštu
    • SMS rinkodara
    • Renginiai
    • Rinkodaros automatizavimas
    • Apklausos
    Paslaugos
    • Projektas
    • Darbo laiko žiniaraščiai
    • Priežiūros tarnyba
    • Pagalbos tarnyba
    • Planavimas
    • Rezervacijos
    Produktyvumas
    • Diskucija
    • Patvirtinimai
    • IoT
    • VoIP
    • Žinių biblioteka
    • WhatsApp
    Trečiųjų šalių programos Odoo Studija Odoo debesijos platforma
  • Pramonės šakos
    Mažmeninė prekyba
    • Knygynas
    • Drabužių parduotuvė
    • Baldų parduotuvė
    • Maisto prekių parduotuvė
    • Techninės įrangos parduotuvė
    • Žaislų parduotuvė
    Food & Hospitality
    • Barai ir pub'ai
    • Restoranas
    • Greitasis maistas
    • Guest House
    • Gėrimų platintojas
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architektūros įmonė
    • Konstrukcija
    • Estate Managament
    • Sodininkauti
    • Turto savininkų asociacija
    Consulting
    • Accounting Firm
    • Odoo Partneris
    • Marketing Agency
    • Teisinė firma
    • Talentų paieška
    • Auditai & sertifikavimas
    Gamyba
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Įmonių dovanos
    Sveikata & Fitnesas
    • Sporto klubas
    • Akinių parduotuvė
    • Fitneso Centras
    • Sveikatos praktikai
    • Vaistinė
    • Kirpėjas
    Trades
    • Handyman
    • IT įranga ir palaikymas
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Aplinkos agentūra
    • Reklaminių stendų nuoma
    • Fotografavimas
    • Dviračių nuoma
    • Programinės įrangos perpardavėjas
    Browse all Industries
  • Bendrija
    Mokykitės
    • Mokomosios medžiagos
    • Dokumentacija
    • Sertifikatai
    • Mokymai
    • Internetinis Tinklaraštis
    • Tinklalaidės
    Skatinkite švietinimą
    • Švietimo programa
    • Scale Up! Verslo žaidimas
    • Aplankykite Odoo
    Gaukite programinę įrangą
    • Atsisiųsti
    • Palyginkite versijas
    • Leidimai
    Bendradarbiauti
    • Github
    • Forumas
    • Renginiai
    • Vertimai
    • Tapkite partneriu
    • Services for Partners
    • Registruokite jūsų apskaitos įmonę
    Gaukite paslaugas
    • Susiraskite partnerį
    • Susirask buhalterį
    • Susitikti su konsultantu
    • Diegimo paslaugos
    • Klientų rekomendavimas
    • Palaikymas
    • Atnaujinimai
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Gaukite demo
  • Kainodara
  • Pagalba

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

  • CRM
  • e-Commerce
  • Apskaita
  • Atsarga
  • PoS
  • Projektas
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Žymos (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Žymos (View all)
odoo accounting v14 pos v15
About this forum
Pagalba

Compute field difference of dates

Prenumeruoti

Get notified when there's activity on this post

This question has been flagged
fielddatetimecomputecomputed-fields
2 Replies
9007 Rodiniai
Portretas
Glosema

Hello,


I want to have difference of dwo dates.

I write the function in Compute field in odoo:


fmt = '%Y-%m-%d %H:%M:%S'  
for record in self:
  record_id = record.id
  start_hour = record.date_start
  end = record.date_end
  if record.date_end is None:
  end = 0
  diff = 0
  else:
  end = record.date_end
  a = datetime.datetime.strptime(end, fmt)
  b = datetime.datetime.strptime(start_hour, fmt)
  diff = (a-b)
  record['x_test_true_working_hours'] = diff

But i have an error :


Traceback (most recent call last):
  File "/odoo/odoo-server/odoo/http.py", line 641, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/odoo/odoo-server/odoo/http.py", line 683, in dispatch
    result = self._call_function(**self.params)
  File "/odoo/odoo-server/odoo/http.py", line 333, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/odoo/odoo-server/odoo/service/model.py", line 101, in wrapper
    return f(dbname, *args, **kwargs)
  File "/odoo/odoo-server/odoo/http.py", line 326, in checked_call
    result = self.endpoint(*a, **kw)
  File "/odoo/odoo-server/odoo/http.py", line 941, in __call__
    return self.method(*args, **kw)
  File "/odoo/odoo-server/odoo/http.py", line 506, in response_wrap
    response = f(*args, **kw)
  File "/odoo/odoo-server/addons/web/controllers/main.py", line 832, in search_read
    return self.do_search_read(model, fields, offset, limit, domain, sort)
  File "/odoo/odoo-server/addons/web/controllers/main.py", line 854, in do_search_read
    offset=offset or 0, limit=limit or False, order=sort or False)
  File "/odoo/odoo-server/odoo/models.py", line 4693, in search_read
    result = records.read(fields)
  File "/odoo/odoo-server/odoo/models.py", line 3018, in read
    values[name] = field.convert_to_read(record[name], record, use_name_get)
  File "/odoo/odoo-server/odoo/models.py", line 5208, in __getitem__
    return self._fields[key].__get__(self, type(self))
  File "/odoo/odoo-server/odoo/fields.py", line 910, in __get__
    self.determine_value(record)
  File "/odoo/odoo-server/odoo/fields.py", line 1022, in determine_value
    self.compute_value(recs)
  File "/odoo/odoo-server/odoo/fields.py", line 976, in compute_value
    self._compute_value(records)
  File "/odoo/odoo-server/odoo/fields.py", line 969, in _compute_value
    self.compute(records)
  File "/odoo/odoo-server/odoo/addons/base/ir/ir_model.py", line 34, in <lambda>
    func = lambda self: safe_eval(text, SAFE_EVAL_BASE, {'self': self}, mode="exec")
  File "/odoo/odoo-server/odoo/tools/safe_eval.py", line 301, in safe_eval
    return unsafe_eval(c, globals_dict, locals_dict)
  File "", line 14, in <module>
ValueError: <type 'exceptions.TypeError'>: "strptime() argument 1 must be string, not bool" while evaluating
u"fmt = '%Y-%m-%d %H:%M:%S'  \r\nfor record in self:\r\n\r\n  \r\n        record_id = record.id\r\n        start_hour = record.date_start\r\n        end = record.date_end\r\n\r\n        if record.date_end is None:\r\n#            end = None \r\n            diff = 0\r\n        else:\r\n            end = record.date_end\r\n            a = datetime.datetime.strptime(end, fmt)\r\n            b = datetime.datetime.strptime(start_hour, fmt)\r\n#            diff = (a-b)\r\n\r\n        record['x_test_true_working_hours'] = a"


How to fix this ?

0
Portretas
Atmesti
Fatih Piristine

you have problem with your variable. try to use relative delta instead

Portretas
Yvan
Best Answer

Hi Glosema,

to convert the record value to a datetime object, you should use the from_string. Therefore it's not necessary to know in which format the datetime records are stored in the database.

The error message you get means that the variable end or start_hour is a boolean instead of a string. The reason is that record.date_start and/or record.date_end is not defined and set to False.

Try following code to see if it meets your requirements.

import datetime
from openerp import fields

time_delta = datetime.timedelta(0)
if record.date_start and record.date_end:
start_datetime = fields.Datetime.from_string(record.date_start)
end_datetime = fields.Datetime.from_string(record.date_end)
time_delta = end_datetime - start_datetime
record['x_test_true_working_hours'] = time_delta


Best regards
Yvan

0
Portretas
Atmesti
Melvin

Hi Yvan,

Could you please give some more detailed explanation about this?

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

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

Registracija
Related Posts Replies Rodiniai Veikla
how to perform subtract operation in odoo11 field Solved
field compute computed-fields odoov11
Portretas
Portretas
1
gruod. 19
4450
How to retrieve values on another page?
field payslip compute
Portretas
0
gruod. 23
1936
Compute if time is Between 00:00 and 07:00. Solved
datetime compute v15
Portretas
1
saus. 23
2760
Compute field
field compute v15
Portretas
Portretas
1
liep. 22
2858
compute issue Solved
compute computed-fields odoo12.0
Portretas
1
geg. 21
4302
Bendrija
  • Mokomosios medžiagos
  • Dokumentacija
  • Forumas
Atvirasis kodas
  • Atsisiųsti
  • Github
  • Runbot
  • Vertimai
Paslaugos
  • Odoo.sh talpinimas
  • Palaikymas
  • Atnaujinti
  • Pritaikytas programavimo kūrimas
  • Švietimas
  • Susirask buhalterį
  • Susiraskite partnerį
  • Tapkite partneriu
Apie mus
  • Mūsų įmonė
  • Prekės ženklo turtas
  • Susisiekite su mumis
  • Darbo pasiūlymai
  • Renginiai
  • Tinklalaidės
  • Internetinis Tinklaraštis
  • Klientai
  • Teisinis • Privatumas
  • Saugumas
الْعَرَبيّة 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 yra atvirojo kodo verslo programų rinkinys, kuris apima visas įmonės poreikius: CRM, El. Prekybą, Apskaitą, Atsargų, Kasų sistemą, Projektų valdymą ir kt.

Unikali Odoo vertės pasiūla – būti tuo pačiu metu labai lengvai naudojama ir visiškai integruota sistema.

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