From b873bda1e560bc49ab707aa238fdc962f23bc1e4 Mon Sep 17 00:00:00 2001 From: "Achraf (abz)" Date: Thu, 3 Dec 2020 12:13:33 +0000 Subject: [FIX] survey, web, web_editor, website, website_form: Prevent invalid date stock.picking What are the steps to reproduce your issue? 1. Install "stock" 2. Go to Inventory/Inventory Overview/Internal Transfer 3. Create new record and set manually a date with year < 1000 like "0008-10-10 18:35:00" 4. Save What is currently happening? An error arises when saving the record, and it is then no longer possible to reopen the records or any view containing it. This also prevents us from correcting the date to no longer have the error Why is this happening? The root cause is an inconsistency in `strftime` for years < 1000 [1, 2]. To take it into account, a zero-padding is needed in the DateTime parser. How to fix the bug? The missing padding is added. However, such dates lead to problematic behaviors in Python: ``` DT_FORMAT = "%Y-%m-%d %H:%M:%S" new_date = "0008-02-05 18:10:10" datetime.strptime( datetime.strptime( new_date, DT_FORMAT ).strftime(DT_FORMAT), DT_FORMAT ) ``` This raises: ``` ValueError: time data '8-02-05 18:10:10' does not match format '%Y-%m-%d %H:%M:%S' ``` As of today there was no reported business cases where dates with year < 1000 would be necessary. Therefore, we limit the range to years >= 1000. [1] https://bugs.python.org/issue13305 [2] https://docs.python.org/dev/library/datetime.html#strftime-strptime-behavior opw-2408260 closes odoo/odoo#62818 Signed-off-by: Nicolas Martinelli (nim) --- addons/web/static/src/js/widgets/date_picker.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/web/static/src/js/widgets') diff --git a/addons/web/static/src/js/widgets/date_picker.js b/addons/web/static/src/js/widgets/date_picker.js index b989cc87355..fdbd1f7d891 100644 --- a/addons/web/static/src/js/widgets/date_picker.js +++ b/addons/web/static/src/js/widgets/date_picker.js @@ -30,7 +30,7 @@ var DateWidget = Widget.extend({ this.options = _.extend({ locale: moment.locale(), format : this.type_of_date === 'datetime' ? time.getLangDatetimeFormat() : time.getLangDateFormat(), - minDate: moment({ y: 1 }), + minDate: moment({ y: 1000 }), maxDate: moment({ y: 9999, M: 11, d: 31 }), useCurrent: false, icons: { -- cgit v1.2.3