Select persian language in wizards

Why do in need this selection

As you know odoo supports persian language and it had done lots of translations out of the box. However, all the dates are based on Gregorian calendar. It means that if you want to have Jalaali calendar, there is no option.

For this reason, you need to customize some modules to have Jalaali converts. The suggested python snippet helps you to have selection of language.

You can use jdatetime python package to convert Gregorian to Jalaali. 


calendar = fields.Selection([('fa_IR', 'Persian'), ('en_US', 'Gregorian')],
    default=lambda self: 'fa_IR' if self.env.context.get('lang') == 'fa_IR' else 'en_US')


    <field name="calendar" invisible="context.get('lang') != 'fa_IR'"/>

Inside the wizard or everywhere else, you can use the following function to convert datetime variable to a separated date and time. It also gets a lang argument to pass desired language code.

If you pass 'fa_IR' as lang in date_converter function, it will return date and time in a dictionary. This function would be useful if you want to pass date and time as string to a report template.

    def date_converter(self, date_time, lang):

date_time = {'date': date_time.strftime("%Y/%m/%d"),
'time': date_time.strftime("%H:%M:%S")}
else:
date_time = {'date': date_time.strftime("%Y/%m/%d"),
'time': date_time.strftime("%H:%M:%S")}
return date_time


You can use the following snippet to find the first day of the month. If the language is 'fa_IR', the first_day will be the gregorian date of the start_date in percian.

start_date = '2023-06-20'

  • Gregorian first day of the month: 2023-06-01
  • Jalaali first day of the month: 2023-05-22
        if calendar == 'fa_IR':
first_day = jdatetime.date.fromgregorian(date=start_date).replace(day=1).togregorian()
else:
first_day = start_date.replace(day=1)
Views
1 Total Views
1 Members Views
0 Public Views
Actions
0 Likes
0 Dislikes
0 Comments
Share on Social Networks
Share Link
Share by mail

Please login to share this webpage by email.