from datetime import datetime, date
from odoo import api, fields, models, _
from odoo.exceptions import ValidationError
import calendar
class HrPublicHolidayHolidays(models.Model):
_name = 'hr.public.holiday.holidays'
_description = 'Public Holidays Dates'
name = fields.Char('Holiday Name', required=True)
date = fields.Date('Holiday Date', required=True)
date_day = fields.Char('Day')
year_id = fields.Many2one('hr.public.holiday', 'Calendar Year', required=True)
variable = fields.Boolean('Date may change')
@api.onchange('date')
def _get_day_of_date(self):
for r in self:
selected = fields.Datetime.from_string(r.date)
r.date_day = calendar.day_name[selected.weekday()]
所以基本上代码会运行,但是错误一直在显示,我也不知道为什么。
如果有人知道出了什么问题,请您帮我吗?
谢谢。
答案 0 :(得分:0)
首先默认获取当前日期 例如:date = fields.Date(string ='Date',default = fields.Date.context_today,required = True)
之后,编写此波纹管函数以获取日期名称,
例如:@ api.multi @ api.depends('日期') def _get_day(): self.day = self.date和(datetime.strptime(self.date,'%Y-%m-%d')。date())。strftime('%A')或''