odoo / odoo

Odoo. Open Source Apps To Grow Your Business.
https://www.odoo.com
Other
37.25k stars 24.23k forks source link

[16.0] datepicker and daterangepicker bug in Arabic and Persian #103875

Open MohammadSafaeii opened 1 year ago

MohammadSafaeii commented 1 year ago

datepicker in Persian won't work (nothing changes after selecting the date), daterangepicker won't work in both languages (Arabic and Persian) Persian and Arabic use different numbers I think you should convert them first and then use them. It is handled in datepicker for Arabic, but in Persian, it won't work daterangepicker has errors in both languages daterangepicker error:

Error: '۲۰۲۲/۱۰/۱۳ ۰۹:۳۰:۰۰' is not a correct date or datetime
    parseDateTime@http://127.0.0.1:8069/web/assets/debug/web.assets_backend.js:8560:15 (/web/static/src/core/l10n/dates.js:350)
    onPickerApply/dates<@http://127.0.0.1:8069/web/assets/debug/web.assets_backend.js:29374:20 (/web/static/src/views/fields/daterange/daterange_field.js:133)
    onPickerApply@http://127.0.0.1:8069/web/assets/debug/web.assets_backend.js:29373:36 (/web/static/src/views/fields/daterange/daterange_field.js:132)
    dispatch@http://127.0.0.1:8069/web/assets/debug/web.assets_common.js:27427:27 (/web/static/lib/jquery/jquery.js:5183)
    add/elemData.handle@http://127.0.0.1:8069/web/assets/debug/web.assets_common.js:27235:28 (/web/static/lib/jquery/jquery.js:4991)
    trigger@http://127.0.0.1:8069/web/assets/debug/web.assets_common.js:30493:12 (/web/static/lib/jquery/jquery.js:8249)
    trigger/<@http://127.0.0.1:8069/web/assets/debug/web.assets_common.js:30571:17 (/web/static/lib/jquery/jquery.js:8327)
    each@http://127.0.0.1:8069/web/assets/debug/web.assets_common.js:22598:19 (/web/static/lib/jquery/jquery.js:354)
    each@http://127.0.0.1:8069/web/assets/debug/web.assets_common.js:22433:17 (/web/static/lib/jquery/jquery.js:189)
    trigger@http://127.0.0.1:8069/web/assets/debug/web.assets_common.js:30570:15 (/web/static/lib/jquery/jquery.js:8326)
    clickApply@http://127.0.0.1:8069/web/static/lib/daterangepicker/daterangepicker.js:1403:26 (http://127.0.0.1:8069/web/static/lib/daterangepicker/daterangepicker.js:1403)
    proxy@http://127.0.0.1:8069/web/assets/debug/web.assets_common.js:32512:13 (/web/static/lib/jquery/jquery.js:10268)
    dispatch@http://127.0.0.1:8069/web/assets/debug/web.assets_common.js:27427:27 (/web/static/lib/jquery/jquery.js:5183)
    add/elemData.handle@http://127.0.0.1:8069/web/assets/debug/web.assets_common.js:27235:28 (/web/static/lib/jquery/jquery.js:4991)
saeed-raeisi commented 1 year ago

https://user-images.githubusercontent.com/38601142/204464567-c537f0dd-a0e7-41ab-88d3-9ae4ea8e6e3d.mp4 This problem exists in Persian language, The problem is solved by replacing the datepicker with a version that supports the Persian language. But the date display is not modified by jalali moment.

https://user-images.githubusercontent.com/38601142/204464954-b97da85b-8695-4aea-b228-ef5f9ced0c99.mp4

LinuxPlus commented 1 year ago

You can share module?

saeed-raeisi commented 1 year ago

You can share module?

Not yet completed on the other hand, oca does not accept the calendar module and odoo due to Iran embargo It is not possible to add this item

LinuxPlus commented 1 year ago

It is enough to solve the problem from right to left

mostafabarmshory commented 1 year ago

The root issue is about moment local support.

Moment uses a post process and replaces all digits with a local one. On the other hand, the moment is used by the date picker (tempusdominus).

So, the date picker converts the date into the local format and sets it into the input field.

The date field gets the string and tries to use Luxon and convert it into a date object.

Finally, Luxon fails and returns a null object.

How to resolve

Luxon supports an option named numberingSystem. So if the DateField sends this option based on the current local, everything goes well.

I`ve checked this solution locally.

saeed-raeisi commented 1 year ago

https://github.com/odoo/odoo/blob/16.0/addons/web/static/lib/luxon/luxon.js#L6834

photo_2023-02-01_13-40-43

parseFromTokens(localeToUse, text, fmt) text = "۲۰۲۳/۰۲/۰۵"

image

If datepicker does not return the date with Persian numbers, the problem will be solved image

mostafabarmshory commented 1 year ago

https://github.com/odoo/odoo/blob/16.0/addons/web/static/lib/luxon/luxon.js#L6834

photo_2023-02-01_13-40-43

parseFromTokens(localeToUse, text, fmt) text = "۲۰۲۳/۰۲/۰۵"

image

If datepicker does not return the date with Persian numbers, the problem will be solved image

the datepicker (tempusdominus) is designed base moments. I`ve made a patch to solve this issue. I'll submit it as a pull request soon.