How to resolve this error - Uncaught Error: '2016-' is not a correct date, datetime nor time
How to resolve this error - Uncaught Error: '2016-' is not a correct date, datetime nor time
我从 Odoo 社区参考网站获得了以下部分代码,用于创建生日日历标记
.PY文件
class birthday_report(osv.osv):
_name = "birthday.report"
_auto = False
_columns = {
'name': fields.many2one('hr.employee','Employee', readonly=True),
'dob' : fields.date('Birthday', readonly=True),
}
def init(self, cr):
tools.drop_view_if_exists(cr, 'birthday_report')
cr.execute("""
create or replace view birthday_report as (
select
h.id as id,
h.id as name,
concat(concat(date_part('Year',current_date),'-'),to_char(h.birthday, 'mm-dd')) as dob
from
hr_employee as h
join
resource_resource as r
on
h.resource_id=r.id
where r.active ='t'
)
""")
birthday_report()
.XML 文件
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_birthday_report_calendar" model="ir.ui.view">
<field name="name">Employee Birthday</field>
<field name="model">birthday.report</field>
<field name="arch" type="xml">
<calendar string="Birthday" color="name"
date_start="dob"
quick_add="False" avatar_model="hr.employee">
<field name="name"/>
</calendar>
</field>
</record>
<record model="ir.actions.act_window" id="action_birthday_view">
<field name="name">Birthday</field>
<field name="res_model">birthday.report</field>
<field name="view_type">form</field>
<field name="view_mode">calendar</field>
<field name="view_id" eval="view_birthday_report_calendar"/>
<field name="domain">[]</field>
</record>
<menuitem id="menu_birthday" name="Birthday" parent="hr.menu_hr_root" groups="base.group_user"/>
<menuitem id="menu_view_birthday" parent="menu_birthday" action="action_birthday_view" groups="base.group_user"/>
</data>
</openerp>
当我导航到 1 月或上一年的 12 月时出现错误,出现以下错误:
未捕获错误:“2016-”不是正确的日期、日期时间或时间。
我是 Odoo 中 sql 查询的新手,任何对此有建议的人都将不胜感激。谢谢!!
首先,我建议使用 ||
而不是 concat。这允许您进行多个连接。
date_part('Year',current_date) || '-' || to_char(h.birthday, 'mm-dd')
其次,我建议选角,所以
(date_part('Year',current_date) || '-' || to_char(h.birthday, 'mm-dd'))::date
第三,如果从视图中只使用 psql 和 select 会发生什么情况?是否有格式错误的日期?还是您的 Python 代码中的其他地方发生了其他事情?
我从 Odoo 社区参考网站获得了以下部分代码,用于创建生日日历标记
.PY文件
class birthday_report(osv.osv):
_name = "birthday.report"
_auto = False
_columns = {
'name': fields.many2one('hr.employee','Employee', readonly=True),
'dob' : fields.date('Birthday', readonly=True),
}
def init(self, cr):
tools.drop_view_if_exists(cr, 'birthday_report')
cr.execute("""
create or replace view birthday_report as (
select
h.id as id,
h.id as name,
concat(concat(date_part('Year',current_date),'-'),to_char(h.birthday, 'mm-dd')) as dob
from
hr_employee as h
join
resource_resource as r
on
h.resource_id=r.id
where r.active ='t'
)
""")
birthday_report()
.XML 文件
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_birthday_report_calendar" model="ir.ui.view">
<field name="name">Employee Birthday</field>
<field name="model">birthday.report</field>
<field name="arch" type="xml">
<calendar string="Birthday" color="name"
date_start="dob"
quick_add="False" avatar_model="hr.employee">
<field name="name"/>
</calendar>
</field>
</record>
<record model="ir.actions.act_window" id="action_birthday_view">
<field name="name">Birthday</field>
<field name="res_model">birthday.report</field>
<field name="view_type">form</field>
<field name="view_mode">calendar</field>
<field name="view_id" eval="view_birthday_report_calendar"/>
<field name="domain">[]</field>
</record>
<menuitem id="menu_birthday" name="Birthday" parent="hr.menu_hr_root" groups="base.group_user"/>
<menuitem id="menu_view_birthday" parent="menu_birthday" action="action_birthday_view" groups="base.group_user"/>
</data>
</openerp>
当我导航到 1 月或上一年的 12 月时出现错误,出现以下错误:
未捕获错误:“2016-”不是正确的日期、日期时间或时间。
我是 Odoo 中 sql 查询的新手,任何对此有建议的人都将不胜感激。谢谢!!
首先,我建议使用 ||
而不是 concat。这允许您进行多个连接。
date_part('Year',current_date) || '-' || to_char(h.birthday, 'mm-dd')
其次,我建议选角,所以
(date_part('Year',current_date) || '-' || to_char(h.birthday, 'mm-dd'))::date
第三,如果从视图中只使用 psql 和 select 会发生什么情况?是否有格式错误的日期?还是您的 Python 代码中的其他地方发生了其他事情?