How to give the specific date like "2022-12-31",not the default date as today?
hire_date = fields.Date(string="Hire Date", default=fields.Date.today)
resign_date = fields.Date(string="Resign Date")
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
How to give the specific date like "2022-12-31",not the default date as today?
hire_date = fields.Date(string="Hire Date", default=fields.Date.today)
resign_date = fields.Date(string="Resign Date")
hire_date = fields.Date(string="Hire Date", default=datetime.strptime("2022-12-31", '%Y-%m-%d').date())
You can try the above code.
It didn't work.I tried the below three ways,still showing the error.
(1)datetime.strptime("2022-12-31", '%y-%m-%d').date();
(2)date.strptime("2022-12-31", '%y-%m-%d').date()
(3)strptime("2022-12-31", '%y-%m-%d').date()
from ast import literal_eval
from odoo import api, fields, models
from pytz import timezone, UTC
from odoo.tools import format_time
from datetime import date, datetime, timedelta, time
from time import time
import datetime
import time
import calendar
(1)
File "/opt/bitnami/apps/odoo/lib/odoo-13.0.post20191110-py3.7.egg/odoo/addons/hr/models/hr_employee_base.py", line 33, in HrEmployeeBase
hire_date = fields.Date(string="Hire Date", default=datetime.strptime("2022-12-31", '%y-%m-%d').date())
AttributeError: module 'datetime' has no attribute 'strptime'
(2)
File "/opt/bitnami/apps/odoo/lib/odoo-13.0.post20191110-py3.7.egg/odoo/addons/hr/models/hr_employee_base.py", line 33, in HrEmployeeBase
hire_date = fields.Date(string="Hire Date", default=date.strptime("2022-12-31", '%y-%m-%d').date())
AttributeError: type object 'datetime.date' has no attribute 'strptime'
(3)
File "/opt/bitnami/apps/odoo/lib/odoo-13.0.post20191110-py3.7.egg/odoo/addons/hr/models/hr_employee_base.py", line 33, in HrEmployeeBase
hire_date = fields.Date(string="Hire Date", default=("2022-12-31", '%y-%m-%d').date())
AttributeError: 'tuple' object has no attribute 'date'
from datetime import datetime
The above code should be enough for the import.
Please use capital Y to represent year i.e., use "%Y-%m-%d" in your code, I have made a mistake in the first reply.
Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!
Đăng kýBài viết liên quan | Trả lời | Lượt xem | Hoạt động | |
---|---|---|---|---|
|
3
thg 6 25
|
1075 | ||
|
1
thg 1 25
|
17972 | ||
|
1
thg 1 20
|
3955 | ||
|
1
thg 12 19
|
17268 | ||
|
3
thg 4 18
|
5169 |