Skip to content
Snippets Groups Projects
Commit 8eea670e authored by anhe-odoo's avatar anhe-odoo
Browse files

[FIX] web: add preparse method for parsing dates in catalan


Observed Behaviour

When opening a pivot view with the catalan language activated
and grouping rows/cols by months, everything works fine. But if
we try to import this pivot view in a spreadsheet, all months
are converted to gener, which means 'January' in catalan

Expected Behaviour

When importing the pivot view in a spreadsheet, we should get
the correct date grouping

Reproducibility

This issue can be reproduced with the following steps
1. Activate the catalan language and set it
2. Got to Sales App
3. Select the pivot view
4. Group the rows/cols by order date > months
5. Try to import the pivot view in a spreadsheet

Fix Description

The isse was coming from the fact babel (the package used to
generate date as text in python) write the month as 'de gener',
'de febrer', 'de març', 'd'abril', while moment (the lib used
to handle date in JS) is looking for months as 'gener', 'febrer',
... (ie without "de" or "d'" prefix), causing it not to
recognize the date proposed by Babel. We then added a preparse
method to the catalan language, automatically used by moment when
present in the language definition.

Related Issues/PR
-opw-2817041

closes odoo/odoo#90466

Signed-off-by: default avatarNicolas Lempereur (nle) <nle@odoo.com>
parent f9500009
Branches
Tags
No related merge requests found
/**
* This file aim to contains the update/fix we have to do on moment.js localizations.
* By using updateLocale and/or defineLocale here, we avoid adding change in the official
* moment.js files, which could lead to conflict when updating the library.
*/
odoo.define('web.moment.extensions', function () {
'use strict';
const locale = moment.locale();
moment.updateLocale('ca', {
preparse: function (string) {
return string.replace(/\b(?:d’|de )(gener|febrer|març|abril|maig|juny|juliol|agost|setembre|octubre|novembre|desembre)/g, '$1');
}
});
if(locale !== 'ca'){
moment.locale(locale);
}
});
......@@ -131,6 +131,7 @@
<script type="text/javascript" src="/web/static/src/js/libs/underscore.js"></script>
<script type="text/javascript" src="/web/static/src/js/libs/popper.js"></script>
<script type="text/javascript" src="/web/static/src/js/libs/fullcalendar.js"></script>
<script type="text/javascript" src="/web/static/src/js/libs/moment.js"></script>
<script type="text/javascript" src="/web/static/src/js/chrome/keyboard_navigation_mixin.js"></script>
<script type="text/javascript" src="/web/static/src/js/core/abstract_service.js"></script>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment