2022-04-26 10:12:33 +00:00
|
|
|
import { t } from 'fyo';
|
2022-04-24 06:48:44 +00:00
|
|
|
import { Doc } from 'fyo/model/doc';
|
2022-04-26 10:12:33 +00:00
|
|
|
import {
|
|
|
|
DependsOnMap,
|
|
|
|
EmptyMessageMap,
|
|
|
|
FormulaMap,
|
|
|
|
ListsMap,
|
|
|
|
} from 'fyo/model/types';
|
2022-04-11 12:44:36 +00:00
|
|
|
import { stateCodeMap } from 'regional/in';
|
|
|
|
import { titleCase } from 'utils';
|
2022-04-23 09:23:44 +00:00
|
|
|
import { getCountryInfo } from 'utils/misc';
|
2022-04-11 12:44:36 +00:00
|
|
|
|
|
|
|
export class Address extends Doc {
|
|
|
|
formulas: FormulaMap = {
|
|
|
|
addressDisplay: async () => {
|
|
|
|
return [
|
|
|
|
this.addressLine1,
|
|
|
|
this.addressLine2,
|
|
|
|
this.city,
|
|
|
|
this.state,
|
|
|
|
this.country,
|
|
|
|
this.postalCode,
|
|
|
|
]
|
|
|
|
.filter(Boolean)
|
|
|
|
.join(', ');
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2022-04-26 10:12:33 +00:00
|
|
|
dependsOn: DependsOnMap = {
|
|
|
|
addressDisplay: [
|
|
|
|
'addressLine1',
|
|
|
|
'addressLine2',
|
|
|
|
'city',
|
|
|
|
'state',
|
|
|
|
'country',
|
|
|
|
'postalCode',
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
2022-04-11 12:44:36 +00:00
|
|
|
static lists: ListsMap = {
|
|
|
|
state(doc?: Doc) {
|
|
|
|
const country = doc?.country as string | undefined;
|
|
|
|
switch (country) {
|
|
|
|
case 'India':
|
|
|
|
return Object.keys(stateCodeMap).map(titleCase).sort();
|
|
|
|
default:
|
|
|
|
return [] as string[];
|
|
|
|
}
|
|
|
|
},
|
|
|
|
country() {
|
2022-04-23 09:23:44 +00:00
|
|
|
return Object.keys(getCountryInfo()).sort();
|
2022-04-11 12:44:36 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static emptyMessages: EmptyMessageMap = {
|
2022-04-26 10:12:33 +00:00
|
|
|
state: (doc: Doc) => {
|
2022-04-11 12:44:36 +00:00
|
|
|
if (doc.country) {
|
2022-04-26 10:12:33 +00:00
|
|
|
return t`Enter State`;
|
2022-04-11 12:44:36 +00:00
|
|
|
}
|
|
|
|
|
2022-04-26 10:12:33 +00:00
|
|
|
return t`Enter Country to load States`;
|
2022-04-11 12:44:36 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|