2022-04-19 05:59:36 +00:00
|
|
|
import { DocValue } from 'fyo/core/types';
|
2022-04-24 06:48:44 +00:00
|
|
|
import { Doc } from 'fyo/model/doc';
|
2022-04-27 08:37:06 +00:00
|
|
|
import { ListsMap, ValidationMap } from 'fyo/model/types';
|
2022-04-19 05:59:36 +00:00
|
|
|
import { ValidationError } from 'fyo/utils/errors';
|
|
|
|
import { t } from 'fyo/utils/translation';
|
2022-04-27 08:37:06 +00:00
|
|
|
import { SelectOption } from 'schemas/types';
|
|
|
|
import { getCountryInfo } from 'utils/misc';
|
2022-04-07 09:27:01 +00:00
|
|
|
|
|
|
|
export default class SystemSettings extends Doc {
|
2022-09-29 11:04:35 +00:00
|
|
|
dateFormat?: string;
|
|
|
|
locale?: string;
|
|
|
|
displayPrecision?: number;
|
|
|
|
internalPrecision?: number;
|
|
|
|
hideGetStarted?: boolean;
|
|
|
|
countryCode?: string;
|
|
|
|
currency?: string;
|
|
|
|
version?: string;
|
|
|
|
instanceId?: string;
|
|
|
|
|
2022-04-07 09:27:01 +00:00
|
|
|
validations: ValidationMap = {
|
2023-06-22 08:52:54 +00:00
|
|
|
displayPrecision(value: DocValue) {
|
2022-04-07 09:27:01 +00:00
|
|
|
if ((value as number) >= 0 && (value as number) <= 9) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new ValidationError(
|
|
|
|
t`Display Precision should have a value between 0 and 9.`
|
|
|
|
);
|
|
|
|
},
|
|
|
|
};
|
2022-04-27 08:37:06 +00:00
|
|
|
|
|
|
|
static lists: ListsMap = {
|
|
|
|
locale() {
|
|
|
|
const countryInfo = getCountryInfo();
|
|
|
|
return Object.keys(countryInfo)
|
|
|
|
.filter((c) => !!countryInfo[c]?.locale)
|
|
|
|
.map(
|
|
|
|
(c) =>
|
|
|
|
({
|
|
|
|
value: countryInfo[c]?.locale,
|
2023-06-22 08:52:54 +00:00
|
|
|
label: `${c} (${countryInfo[c]?.locale ?? t`Not Found`})`,
|
2022-04-27 08:37:06 +00:00
|
|
|
} as SelectOption)
|
|
|
|
);
|
|
|
|
},
|
|
|
|
currency() {
|
|
|
|
const countryInfo = getCountryInfo();
|
|
|
|
const currencies = Object.values(countryInfo)
|
|
|
|
.map((ci) => ci?.currency as string)
|
|
|
|
.filter(Boolean);
|
|
|
|
return [...new Set(currencies)];
|
|
|
|
},
|
|
|
|
};
|
2022-04-07 09:27:01 +00:00
|
|
|
}
|