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.
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign upRelated Posts | Replies | Views | Activity | |
---|---|---|---|---|
|
1
Jan 24
|
16296 | ||
|
1
Jan 20
|
2545 | ||
|
1
Dec 19
|
15672 | ||
|
3
Apr 18
|
4097 | ||
|
1
May 16
|
5365 |