I am creating the function field to return date and time and i need to display only year in the field how to achieve this ?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- ลูกค้าสัมพันธ์
- e-Commerce
- ระบบบัญชี
- สินค้าคงคลัง
- PoS
- Project
- MRP
คำถามนี้ถูกตั้งค่าสถานะ
You can extract Year
from your datetime
string like:
year = time.strftime('%Y',time.strptime(datetime, "%Y"))
And return it in other functional field as string.
how to make this as selection field
For the selection field check your functional field type="selection" and define their range of year.
Hello,
if you want a return financial year like 2022-2023.
from datetime import date
year_of_completion = fields.Selection(selection='years_selection', string="Indian Finacial Year")
defyears_selection(self):
year_list = []
for y in range(datetime.now().year-100, datetime.now().year + 10):
year_str = str(y-1)+'-'+str(y)
year_list.append((year_str, year_str))
return year_list
year_of_completion = fields.Selection(
selection='years_selection',
string="Estimated Year of Completion",
default="2021" # as a default value it would be 2019)
def years_selection(self):
year_list = []
for y in range(datetime.now().year, datetime.now().year + 10):
year_list.append((str(y), str(y)))
return year_list
I have already defined these two. But when I pushed these on live server, it doesnot work. Any help?
Hello,
If You want to return only year from your datetime field then do like this:
import datetime
from tools import DEFAULT_SERVER_DATETIME_FORMAT
year = datetime.datetime.strptime(your_date, DEFAULT_SERVER_DATETIME_FORMAT).strftime("%Y")
Thank You, Serpent Consulting Services Pvt. Ltd.
สนุกกับการพูดคุยนี้ใช่ไหม? เข้าร่วมเลย!
สร้างบัญชีวันนี้เพื่อเพลิดเพลินไปกับฟีเจอร์พิเศษและมีส่วนร่วมกับคอมมูนิตี้ที่ยอดเยี่ยมของเรา!
ลงชื่อRelated Posts | ตอบกลับ | มุมมอง | กิจกรรม | |
---|---|---|---|---|
|
3
มี.ค. 15
|
6174 | ||
|
2
ก.พ. 24
|
7585 | ||
|
1
เม.ย. 22
|
8110 | ||
|
1
ต.ค. 19
|
5679 | ||
|
2
เม.ย. 19
|
10685 |
Instead of this you can use
account.fiscalyear
.i need to fetch current year and increment the year by 1 and need to dispaly both current and incremented year in selection field