feat(Holiday List): display localized country name

This commit is contained in:
barredterra 2023-07-14 11:59:45 +02:00
parent fd23bd0434
commit 4888d75e72
3 changed files with 23 additions and 5 deletions

View File

@ -8,8 +8,12 @@ frappe.ui.form.on("Holiday List", {
}
frm.call("get_supported_countries").then(r => {
frm.subdivisions_by_country = r.message;
frm.set_df_property("country", "options", Object.keys(r.message));
frm.subdivisions_by_country = r.message.subdivisions_by_country;
frm.set_df_property(
"country",
"options",
r.message.countries.sort((a, b) => a.label.localeCompare(b.label))
);
if (frm.doc.country) {
frm.trigger("set_subdivisions");
@ -31,7 +35,7 @@ frappe.ui.form.on("Holiday List", {
},
set_subdivisions: function(frm) {
const subdivisions = frm.subdivisions_by_country[frm.doc.country];
if (subdivisions.length > 0) {
if (subdivisions && subdivisions.length > 0) {
frm.set_df_property("subdivision", "options", frm.subdivisions_by_country[frm.doc.country]);
frm.set_df_property("subdivision", "hidden", 0);
} else {

View File

@ -141,7 +141,7 @@
"icon": "fa fa-calendar",
"idx": 1,
"links": [],
"modified": "2023-07-13 13:12:32.082690",
"modified": "2023-07-14 11:29:12.537263",
"modified_by": "Administrator",
"module": "Setup",
"name": "Holiday List",

View File

@ -6,6 +6,7 @@ import json
from datetime import date
import frappe
from babel import Locale
from frappe import _, throw
from frappe.model.document import Document
from frappe.utils import formatdate, getdate, today
@ -39,7 +40,15 @@ class HolidayList(Document):
@frappe.whitelist()
def get_supported_countries(self):
return list_supported_countries()
subdivisions_by_country = list_supported_countries()
countries = [
{"value": country, "label": local_country_name(country)}
for country in subdivisions_by_country.keys()
]
return {
"countries": countries,
"subdivisions_by_country": subdivisions_by_country,
}
@frappe.whitelist()
def get_local_holidays(self):
@ -157,3 +166,8 @@ def is_holiday(holiday_list, date=None):
)
else:
return False
def local_country_name(country_code: str) -> str:
"""Return the localized country name for the given country code."""
return Locale.parse(frappe.local.lang).territories.get(country_code, country_code)