diff options
| author | Nicolas Lempereur <nle@odoo.com> | 2020-09-03 14:24:57 +0000 |
|---|---|---|
| committer | Nicolas Lempereur <nle@odoo.com> | 2020-09-08 07:20:16 +0000 |
| commit | f44d580cc665848c228d96dfb7a4e95dfa96c25c (patch) | |
| tree | 8f74c4b439474cc6b8594ab235fb7bd786b78922 | |
| parent | b1236c731da4c59a211c506b164a5d934ef6bc4a (diff) | |
[FIX] website_form: lang arabic for date/datetime
When we send dates with website_form, if the language of the website is
eg. in arabic we will send moment.js arabic dates that can't be parsed
by the server.
This also happens with norwegian and any language which doesn't use
ascii numbers or textual format of month or days (and possibly RTL
language).
With this changeset, if we detect we are in a use case where this matter
(an existing field and a date format that will fail) the date will be sent
as odoo server format.
Expected change:
- what worked still work with or without server restart
- what didn't work works after server restart
- special case such as "english" with custom format in res.language
containing textual month might now not work with code update without
server restart (probability of this is low).
opw-2326882
closes #57042
closes odoo/odoo#57214
Note: the saas-13.5 version always force isoformat for existing fields
X-original-commit: 9a5bb5e892bc40709fab77c2bc62adcba19e02d2
Signed-off-by: Nicolas Lempereur (nle) <nle@odoo.com>
| -rw-r--r-- | addons/website_form/controllers/main.py | 15 | ||||
| -rw-r--r-- | addons/website_form/static/src/snippets/s_website_form/000.js | 12 |
2 files changed, 14 insertions, 13 deletions
diff --git a/addons/website_form/controllers/main.py b/addons/website_form/controllers/main.py index 4c13c374d26..3a07fee8c57 100644 --- a/addons/website_form/controllers/main.py +++ b/addons/website_form/controllers/main.py @@ -84,17 +84,6 @@ class WebsiteForm(http.Controller): def boolean(self, field_label, field_input): return bool(field_input) - def date(self, field_label, field_input): - lang = request.env['ir.qweb.field'].user_lang() - return datetime.strptime(field_input, lang.date_format).strftime(DEFAULT_SERVER_DATE_FORMAT) - - def datetime(self, field_label, field_input): - lang = request.env['ir.qweb.field'].user_lang() - strftime_format = (u"%s %s" % (lang.date_format, lang.time_format)) - user_tz = pytz.timezone(request.context.get('tz') or request.env.user.tz or 'UTC') - dt = user_tz.localize(datetime.strptime(field_input, strftime_format)).astimezone(pytz.utc) - return dt.strftime(DEFAULT_SERVER_DATETIME_FORMAT) - def binary(self, field_label, field_input): return base64.b64encode(field_input.read()) @@ -108,8 +97,8 @@ class WebsiteForm(http.Controller): 'char': identity, 'text': identity, 'html': identity, - 'date': date, - 'datetime': datetime, + 'date': identity, + 'datetime': identity, 'many2one': integer, 'one2many': one2many, 'many2many':many2many, diff --git a/addons/website_form/static/src/snippets/s_website_form/000.js b/addons/website_form/static/src/snippets/s_website_form/000.js index b2f0f3370b4..573656d5b92 100644 --- a/addons/website_form/static/src/snippets/s_website_form/000.js +++ b/addons/website_form/static/src/snippets/s_website_form/000.js @@ -141,6 +141,18 @@ odoo.define('website_form.s_website_form', function (require) { } }); + // force server date format usage for existing fields + this.$target.find('.s_website_form_field:not(.s_website_form_custom)') + .find('.s_website_form_date, .s_website_form_datetime').each(function () { + var date = $(this).datetimepicker('viewDate').clone().locale('en'); + var format = 'YYYY-MM-DD'; + if ($(this).hasClass('s_website_form_datetime')) { + date = date.utc(); + format = 'YYYY-MM-DD HH:mm:ss'; + } + form_values[$(this).find('input').attr('name')] = date.format(format); + }); + const tokenObj = await this._recaptcha.getToken('website_form'); if (tokenObj.token) { form_values['recaptcha_token_response'] = tokenObj.token; |
