mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-26 08:24:47 +00:00
feat(Holiday List): display localized country name
This commit is contained in:
@@ -8,8 +8,12 @@ frappe.ui.form.on("Holiday List", {
|
|||||||
}
|
}
|
||||||
|
|
||||||
frm.call("get_supported_countries").then(r => {
|
frm.call("get_supported_countries").then(r => {
|
||||||
frm.subdivisions_by_country = r.message;
|
frm.subdivisions_by_country = r.message.subdivisions_by_country;
|
||||||
frm.set_df_property("country", "options", Object.keys(r.message));
|
frm.set_df_property(
|
||||||
|
"country",
|
||||||
|
"options",
|
||||||
|
r.message.countries.sort((a, b) => a.label.localeCompare(b.label))
|
||||||
|
);
|
||||||
|
|
||||||
if (frm.doc.country) {
|
if (frm.doc.country) {
|
||||||
frm.trigger("set_subdivisions");
|
frm.trigger("set_subdivisions");
|
||||||
@@ -31,7 +35,7 @@ frappe.ui.form.on("Holiday List", {
|
|||||||
},
|
},
|
||||||
set_subdivisions: function(frm) {
|
set_subdivisions: function(frm) {
|
||||||
const subdivisions = frm.subdivisions_by_country[frm.doc.country];
|
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", "options", frm.subdivisions_by_country[frm.doc.country]);
|
||||||
frm.set_df_property("subdivision", "hidden", 0);
|
frm.set_df_property("subdivision", "hidden", 0);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -141,7 +141,7 @@
|
|||||||
"icon": "fa fa-calendar",
|
"icon": "fa fa-calendar",
|
||||||
"idx": 1,
|
"idx": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2023-07-13 13:12:32.082690",
|
"modified": "2023-07-14 11:29:12.537263",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Setup",
|
"module": "Setup",
|
||||||
"name": "Holiday List",
|
"name": "Holiday List",
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import json
|
|||||||
from datetime import date
|
from datetime import date
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
|
from babel import Locale
|
||||||
from frappe import _, throw
|
from frappe import _, throw
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
from frappe.utils import formatdate, getdate, today
|
from frappe.utils import formatdate, getdate, today
|
||||||
@@ -39,7 +40,15 @@ class HolidayList(Document):
|
|||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_supported_countries(self):
|
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()
|
@frappe.whitelist()
|
||||||
def get_local_holidays(self):
|
def get_local_holidays(self):
|
||||||
@@ -157,3 +166,8 @@ def is_holiday(holiday_list, date=None):
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
return False
|
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)
|
||||||
|
|||||||
Reference in New Issue
Block a user