Skip to Content
Odoo Menu
  • Zaloguj się
  • Wypróbuj za darmo
  • Aplikacje
    Finanse
    • Księgowość
    • Fakturowanie
    • Wydatki
    • Arkusz kalkulacyjny (BI)
    • Dokumenty
    • Podpisy
    Sprzedaż
    • CRM
    • Sprzedaż
    • PoS Sklep
    • PoS Restauracja
    • Subskrypcje
    • Wypożyczalnia
    Strony Internetowe
    • Kreator Stron Internetowych
    • eCommerce
    • Blog
    • Forum
    • Czat na Żywo
    • eLearning
    Łańcuch dostaw
    • Magazyn
    • Produkcja
    • PLM
    • Zakupy
    • Konserwacja
    • Jakość
    Zasoby Ludzkie
    • Pracownicy
    • Rekrutacja
    • Urlopy
    • Ocena pracy
    • Polecenia Pracownicze
    • Flota
    Marketing
    • Marketing Społecznościowy
    • E-mail Marketing
    • SMS Marketing
    • Wydarzenia
    • Automatyzacja Marketingu
    • Ankiety
    Usługi
    • Projekt
    • Ewidencja czasu pracy
    • Usługi Terenowe
    • Helpdesk
    • Planowanie
    • Spotkania
    Produktywność
    • Dyskusje
    • Zatwierdzenia
    • IoT
    • VoIP
    • Baza wiedzy
    • WhatsApp
    Aplikacje trzecich stron Studio Odoo Odoo Cloud Platform
  • Branże
    Sprzedaż detaliczna
    • Księgarnia
    • Sklep odzieżowy
    • Sklep meblowy
    • Sklep spożywczy
    • Sklep z narzędziami
    • Sklep z zabawkami
    Żywienie i hotelarstwo
    • Bar i Pub
    • Restauracja
    • Fast Food
    • Pensjonat
    • Dystrybutor napojów
    • Hotel
    Agencja nieruchomości
    • Agencja nieruchomości
    • Biuro architektoniczne
    • Budowa
    • Zarządzanie nieruchomościami
    • Ogrodnictwo
    • Stowarzyszenie właścicieli nieruchomości
    Doradztwo
    • Biuro księgowe
    • Partner Odoo
    • Agencja marketingowa
    • Kancelaria prawna
    • Agencja rekrutacyjna
    • Audyt i certyfikacja
    Produkcja
    • Tekstylia
    • Metal
    • Meble
    • Jedzenie
    • Browar
    • Prezenty firmowe
    Zdrowie & Fitness
    • Klub sportowy
    • Salon optyczny
    • Centrum fitness
    • Praktycy Wellness
    • Apteka
    • Salon fryzjerski
    Transakcje
    • Złota rączka
    • Wsparcie Sprzętu IT
    • Systemy energii słonecznej
    • Szewc
    • Firma sprzątająca
    • Usługi HVAC
    Inne
    • Organizacja non-profit
    • Agencja Środowiskowa
    • Wynajem billboardów
    • Fotografia
    • Leasing rowerów
    • Sprzedawca oprogramowania
    Przeglądaj wszystkie branże
  • Community
    Ucz się
    • Samouczki
    • Dokumentacja
    • Certyfikacje
    • Szkolenie
    • Blog
    • Podcast
    Pomóż w nauce innym
    • Program Edukacyjny
    • Scale Up! Gra biznesowa
    • Odwiedź Odoo
    Skorzystaj z oprogramowania
    • Pobierz
    • Porównaj edycje
    • Wydania
    Współpracuj
    • Github
    • Forum
    • Wydarzenia
    • Tłumaczenia
    • Zostań partnerem
    • Usługi dla partnerów
    • Zarejestruj swoją firmę rachunkową
    Skorzystaj z usług
    • Znajdź partnera
    • Znajdź księgowego
    • Spotkaj się z doradcą
    • Usługi wdrożenia
    • Opinie klientów
    • Wsparcie
    • Aktualizacje
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Zaplanuj demo
  • Cennik
  • Pomoc

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

  • CRM
  • e-Commerce
  • Księgowość
  • Zapasy
  • PoS
  • Projekt
  • MRP
All apps
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Pomoc

remove time from datetime field odoo 15

Zaprenumeruj

Otrzymaj powiadomienie o aktywności w tym poście

To pytanie dostało ostrzeżenie
datetimesqlconstraints
3 Odpowiedzi
6801 Widoki
Awatar
Ghassen

Hi Guys, In my Medical Lab project I wanted to use SQL CONSTRAINTS to prevent the same patient of having two appointments in the same day however the appointment_date field is a datetime field which means the validation of SQL constraints works only if the patient would have more than one appointment in the same exact date and the same exact time along with seconds.

but I want the validation to be based on the day month year only.


_sql_constraints = [
('name_code_unique', 'unique (patient_id, appointment_date)', 'An Appointment For the Same Patient Has Already Been Booked On The Same Date'),
]


any one would help please




0
Awatar
Odrzuć
Awatar
Arian Shariat
Najlepsza odpowiedź

Approach 1:

change your field from date = fields.Datetime to fields.Date

you can override the field by inheriting the model.

Approach 2:

override create and write functions to validate date field.

The "create" function example comes below. You have to override the "write" method as well.

from odoo import models, api

import dateutil.parser
from dateutil.relativedelta import relativedelta
from odoo.exceptions import ValidationError


class YourClass(models.Model):
_name = 'module.name'

@api.model
def create
(self, vals_list):
date = vals_list.get('date', None)
if date:
date = dateutil.parser.parse(date).date()
record = self.env['sale.order'].search([('date', '>=', date), ('date', ', date + relativedelta(days=1))])
if record:
raise ValidationError('An appointment is already set for this user on corresponding day.')
return super(YourClass, self).create(vals_list)


1
Awatar
Odrzuć
Arian Shariat

EDIT:
record = self.env['sale.order'].search([('date', '>=', date), ('date', '<', date + relativedelta(days=1))])

Awatar
gitpruuu
Najlepsza odpowiedź

Hello..

I think you could the attr date.date:

Suppose your variable its called date = fields.Datetime(), using date.date and you will get date only from this variable.

0
Awatar
Odrzuć
Awatar
Cybrosys Techno Solutions Pvt.Ltd
Najlepsza odpowiedź

Hi,

In Odoo we have fields DateTime and Date . You can use

field_without_time = fields.Date(string=" ")

for saving date only. In this method the database will only store date.So, you can easily get the date without time.
When we use sql constraints , it will directly check the values from the database. So, if you are using

field_name_with_datetime = fields.DateTime(string=" ")

you have to store the field with only date in the database. You can use the .date() function to get a date from datetime. It can be done just by using an onchange function. So , whenever you choose the first field, the second field will save with only a date. And you can add this field into sql constraints.

Example

@api.onchange('field_name_with_datetime')
def _onchange_field_name_with_datetime(self):
    if self.field_name_with_datetime:
    self.field_without_time = self.field_name_with_datetime.date()

And change sql constraints like this:

_sql_constraints = [('name_code_unique', 'unique (patient_id, field_without_time)', 'An Appointment For the Same Patient Has Already Been Booked On The Same Date'),]

Regards

0
Awatar
Odrzuć
Podoba Ci się ta dyskusja? Dołącz do niej!

Stwórz konto dzisiaj, aby cieszyć się ekskluzywnymi funkcjami i wchodzić w interakcje z naszą wspaniałą społecznością!

Zarejestruj się
Powiązane posty Odpowiedzi Widoki Czynność
See the SQL constraints section for further details?
sql constraints
Awatar
Awatar
Awatar
2
mar 15
11706
Odoo12: SQL Constraint not working?!?
sql constraints Odoo12.0
Awatar
0
sie 20
5311
How to create SQL Constraints in Wizard with models.TransientModel ?
wizard sql constraints
Awatar
1
cze 17
1282
Need constraints for Customer name field doesn't allow "spaces"? Rozwiązane
customer sql constraints
Awatar
Awatar
Awatar
2
lis 15
7829
sql constraints exception Rozwiązane
database sql constraints odoo12
Awatar
Awatar
2
wrz 21
4650
Społeczność
  • Samouczki
  • Dokumentacja
  • Forum
Open Source
  • Pobierz
  • Github
  • Runbot
  • Tłumaczenia
Usługi
  • Hosting Odoo.sh
  • Wsparcie
  • Aktualizacja
  • Indywidualne rozwiązania
  • Edukacja
  • Znajdź księgowego
  • Znajdź partnera
  • Zostań partnerem
O nas
  • Nasza firma
  • Zasoby marki
  • Skontaktuj się z nami
  • Oferty pracy
  • Wydarzenia
  • Podcast
  • Blog
  • Klienci
  • Informacje prawne • Prywatność
  • Bezpieczeństwo Odoo
الْعَرَبيّة 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 to pakiet aplikacji biznesowych typu open source, które zaspokoją wszystkie potrzeby Twojej firmy: CRM, eCommerce, księgowość, inwentaryzacja, punkt sprzedaży, zarządzanie projektami itp.

Unikalną wartością Odoo jest to, że jest jednocześnie bardzo łatwe w użyciu i w pełni zintegrowane.

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