如何解决Odoo - ValueError:时间数据“19/05/2022”与格式“%Y-%m-%d”
我正在尝试向电子商务网站的“额外信息”部分添加自定义日期输入字段。我有以下新模块的代码(我使用表单生成器从日期字段复制的视图中的代码)。它不断给我错误:
ValueError: 时间数据“19/05/2022”与格式“%Y-%m-%d”不匹配
当我提交额外信息页面时。如果我从输入字段中删除日期选择器并以 %Y-%m-%d 格式(例如 2021-02-19)手动输入它,它就可以工作......我怎样才能让日期选择器和输入字段工作.. ..由于浏览器兼容性问题,我不想使用 type='date'。
模型
# -*- coding: utf-8 -*-
from odoo import models,fields,api
# Override the Customer Model to include Area Field
class WebsiteSaleOrderExtraInfo(models.Model):
_name = 'sale.order'
_inherit = ['sale.order']
x_website_delivery_date = fields.Date(string='Delivery Date',required=True)
观看次数
<odoo>
<data>
<!-- Override for Website Sale Addrees View -->
<template id="extra_info_custom" name="Checkout Extra Info with Delivery Date" inherit_id="website_sale.extra_info">
<xpath expr="//div[contains(@class,'s_website_form_submit')]" position="before">
<!-- Adding in Delivery Date at bottom of Form -->
<div class="form-group s_website_form_field col-12 s_website_form_custom" data-type="date" data-name="Field">
<div class="row s_col_no_resize s_col_no_bgcolor">
<label class="col-form-label col-sm-auto s_website_form_label " style="width: 200px" for="x_website_delivery_date">
<span class="s_website_form_label_content">Delivery Date</span>
</label>
<div class="col-sm">
<div class="s_website_form_date input-group date" id="datepicker_x_website_delivery_date" data-target-input="nearest">
<input type="text"
class="form-control datetimepicker-input s_website_form_input"
data-target="#datepicker_x_website_delivery_date"
name="x_website_delivery_date"
placeholder=""
id="x_website_delivery_date"
required="1"
/>
<div class="input-group-append" data-target="#datepicker_x_website_delivery_date" data-toggle="datetimepicker" options="{'datepicker':{'minDate': 0}}">
<div class="input-group-text">
<i class="fa fa-calendar"></i>
</div>
</div>
</div>
</div>
</div>
</div>
</xpath>
</template>
<!-- Allow x_website_delivery_date to be whitelisted in web forms -->
<function model="ir.model.fields" name="formbuilder_whitelist">
<value>sale.order</value>
<value eval="[
'x_website_delivery_date'
]"/>
</function>
</data>
</odoo>
后续调试:
Extra Info Next 按钮调用 website_sale 中的 /website_form/shop.sale.order 路由。它在以下方面失败: order.write(data['record']) 行 其中数据['记录'] = {'x_website_delivery_date':'20/04/2021'}
解决方法
我终于找到了一个“解决方法”,但仍然希望有人能告诉我一个更简单的方法。我很想看到一个解决方案,它是基础 odoo 安装的一部分。
https://www.odoo.com/forum/help-1/valueerror-time-data-19-05-2022-does-not-match-format-y-m-d-186354
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。