Skip ke Konten
Odoo Menu
  • Login
  • Uji coba gratis
  • Aplikasi
    Keuangan
    • Akuntansi
    • Faktur
    • Pengeluaran
    • Spreadsheet (BI)
    • Dokumen
    • Tanda Tangan
    Sales
    • CRM
    • Sales
    • POS Toko
    • POS Restoran
    • Langganan
    • Rental
    Website
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Rantai Pasokan
    • Inventaris
    • Manufaktur
    • PLM
    • Purchase
    • Maintenance
    • Kualitas
    Sumber Daya Manusia
    • Karyawan
    • Rekrutmen
    • Cuti
    • Appraisal
    • Referensi
    • Armada
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Acara
    • Otomatisasi Marketing
    • Survei
    Layanan
    • Project
    • Timesheet
    • Layanan Lapangan
    • Meja Bantuan
    • Planning
    • Appointment
    Produktivitas
    • Diskusi
    • Approval
    • IoT
    • VoIP
    • Pengetahuan
    • WhatsApp
    Aplikasi pihak ketiga Odoo Studio Platform Odoo Cloud
  • Industri-Industri
    Retail
    • Toko Buku
    • Toko Baju
    • Toko Furnitur
    • Toko Kelontong
    • Toko Hardware
    • Toko Mainan
    Makanan & Hospitality
    • Bar dan Pub
    • Restoran
    • Fast Food
    • Rumah Tamu
    • Distributor Minuman
    • Hotel
    Real Estate
    • Agensi Real Estate
    • Firma Arsitektur
    • Konstruksi
    • Estate Management
    • Perkebunan
    • Asosiasi Pemilik Properti
    Konsultansi
    • Firma Akuntansi
    • Mitra Odoo
    • Agensi Marketing
    • Firma huku
    • Talent Acquisition
    • Audit & Sertifikasi
    Manufaktur
    • Tekstil
    • Logam
    • Perabotan
    • Makanan
    • Brewery
    • Corporate Gift
    Kesehatan & Fitness
    • Sports Club
    • Toko Kacamata
    • Fitness Center
    • Wellness Practitioners
    • Farmasi
    • Salon Rambut
    Perdagangan
    • Handyman
    • IT Hardware & Support
    • Sistem-Sistem Energi Surya
    • Pembuat Sepatu
    • Cleaning Service
    • Layanan HVAC
    Lainnya
    • Organisasi Nirlaba
    • Agen Lingkungan
    • Rental Billboard
    • Fotografi
    • Penyewaan Sepeda
    • Reseller Software
    Browse semua Industri
  • Komunitas
    Belajar
    • Tutorial-tutorial
    • Dokumentasi
    • Sertifikasi
    • Pelatihan
    • Blog
    • Podcast
    Empower Education
    • Program Edukasi
    • Game Bisnis 'Scale Up!'
    • Kunjungi Odoo
    Dapatkan Softwarenya
    • Download
    • Bandingkan Edisi
    • Daftar Rilis
    Kolaborasi
    • Github
    • Forum
    • Acara
    • Terjemahan
    • Menjadi Partner
    • Layanan untuk Partner
    • Daftarkan perusahaan Akuntansi Anda.
    Dapatkan Layanan
    • Temukan Mitra
    • Temukan Akuntan
    • Temui penasihat
    • Layanan Implementasi
    • Referensi Pelanggan
    • Bantuan
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dapatkan demo
  • Harga
  • Bantuan

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

  • CRM
  • e-Commerce
  • Akuntansi
  • Inventaris
  • PoS
  • Project
  • MRP
All apps
Anda harus terdaftar untuk dapat berinteraksi di komunitas.
Semua Post Orang Lencana-Lencana
Label (Lihat semua)
odoo accounting v14 pos v15
Mengenai forum ini
Anda harus terdaftar untuk dapat berinteraksi di komunitas.
Semua Post Orang Lencana-Lencana
Label (Lihat semua)
odoo accounting v14 pos v15
Mengenai forum ini
Help

remove time from datetime field odoo 15

Langganan

Dapatkan notifikasi saat terdapat aktivitas pada post ini

Pertanyaan ini telah diberikan tanda
datetimesqlconstraints
3 Replies
6797 Tampilan
Avatar
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
Avatar
Buang
Avatar
Arian Shariat
Jawaban Terbai

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
Avatar
Buang
Arian Shariat

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

Avatar
gitpruuu
Jawaban Terbai

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
Avatar
Buang
Avatar
Cybrosys Techno Solutions Pvt.Ltd
Jawaban Terbai

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
Avatar
Buang
Menikmati diskusi? Jangan hanya membaca, ikuti!

Buat akun sekarang untuk menikmati fitur eksklufi dan agar terlibat dengan komunitas kami!

Daftar
Post Terkait Replies Tampilan Aktivitas
See the SQL constraints section for further details?
sql constraints
Avatar
Avatar
Avatar
2
Mar 15
11705
Odoo12: SQL Constraint not working?!?
sql constraints Odoo12.0
Avatar
0
Agu 20
5310
How to create SQL Constraints in Wizard with models.TransientModel ?
wizard sql constraints
Avatar
1
Jun 17
1282
Need constraints for Customer name field doesn't allow "spaces"? Diselesaikan
customer sql constraints
Avatar
Avatar
Avatar
2
Nov 15
7827
sql constraints exception Diselesaikan
database sql constraints odoo12
Avatar
Avatar
2
Sep 21
4646
Komunitas
  • Tutorial-tutorial
  • Dokumentasi
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Terjemahan
Layanan
  • Odoo.sh Hosting
  • Bantuan
  • Peningkatan
  • Custom Development
  • Pendidikan
  • Temukan Akuntan
  • Temukan Mitra
  • Menjadi Partner
Tentang Kami
  • Perusahaan kami
  • Aset Merek
  • Hubungi kami
  • Tugas
  • Acara
  • Podcast
  • Blog
  • Pelanggan
  • Hukum • Privasi
  • Keamanan
الْعَرَبيّة 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 adalah rangkaian aplikasi bisnis open source yang mencakup semua kebutuhan perusahaan Anda: CRM, eCommerce, akuntansi, inventaris, point of sale, manajemen project, dan seterusnya.

Mudah digunakan dan terintegrasi penuh pada saat yang sama adalah value proposition unik Odoo.

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