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
    • Discuss
    • 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

odoo 16: how to add time in Datetime and days/week/month(s) in Date field for default value

Langganan

Dapatkan notifikasi saat terdapat aktivitas pada post ini

Pertanyaan ini telah diberikan tanda
datedatetimeodoo16features
1 Balas
10450 Tampilan
Avatar
SmithJohn45

i have created a model with a Date and a Datetime field, want to know to set default values:

1) how i can add Day(s) / Week(s) / Month(s) in Date and Datetime field in model to assign a default value?

2) how to add time in Datetime field in model to assign a default value?

right now, i have following default values and if i want by default add 3 days in today's Date how i can ( same for week and month ) and what if i want to add 30min or 1 hour in time ( Datetime field )  

appointment_time = fields.Datetime (string='Appointment Time', default=fields.Datetime.now)
booking_date = fields.Date(string='Booking Date', default=fields.Date.context_today)


please help.

regards

0
Avatar
Buang
Avatar
Niyas Raphy (Walnut Software Solutions)
Jawaban Terbai

Hi,

If you search inside the odoo source code for the usage of relativedelta you will get a lot of such samples.

lead_days_date = fields.Date.today() + relativedelta.relativedelta(days=10)

The above code will add 10 days to today's date, similar you can change month and year.


For more: https://dateutil.readthedocs.io/en/stable/relativedelta.html

Thanks

1
Avatar
Buang
SmithJohn45
Penulis

thank you @Niyas Raphy , will check the link to learn further. regards

SmithJohn45
Penulis

@Niyas Raphy, i just tried your code as below but when upgrading my app/module, it is saying that booking_date field is not in database ( i have used in patient_view.xml ).

booking_date = fields.Date.today() + relativedelta(days=3)

how i can have the field with data or this code is used in a compute function? or something else? i searched odoo default addons folder for relativedelta yet failed to find how to set default value as mentioned in my opening post above. or i am missing something or this is my wrong approach etc.?

please help.
regards

SmithJohn45
Penulis

when using relativedelta.relativedelta(days=3) it is not starting server and showing error

type object 'relativedelta' has no attribute 'relativedelta'

may be i have to import something for this purpose.
regards

SmithJohn45
Penulis

for field booking_date which type is Date is working fine now with code below:

booking_date = fields.Date(default=str(datetime.now() + relativedelta.relativedelta(days=3)))

but for Datetime type field it is thowing error when going to create New record. error as below (the last line only because there are several lines):

ValueError: unconverted data remains: .191905

may be i have to use some other pythong function to convert it correctly for Datetime field, please help.
regards

SmithJohn45
Penulis

@Niyas Raphy thank you for helping us.

its done now, also modified Datetime type field to have default date + time as below:

appointment_time = fields.Datetime(default=datetime.today() + relativedelta.relativedelta(days=3, hours=3))

please advise if i am doing wrong or missing something.
regards

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
Need Studio compute code to show number of days from today vs. a date field Diselesaikan
date datetime
Avatar
Avatar
2
Jan 24
3599
Adding days to a date
date datetime
Avatar
Avatar
Avatar
2
Jun 22
5684
How can I use date format only without time? Diselesaikan
date datetime
Avatar
Avatar
2
Jun 18
7029
[SOLVED] How can I hide the time of Datetime field of a quotation (doc.date_order)? Diselesaikan
date datetime
Avatar
Avatar
Avatar
2
Nov 16
15074
how to find number of days between two dates? Diselesaikan
date datetime
Avatar
Avatar
Avatar
2
Feb 24
13572
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