2023-03-02 06:28:08 +00:00
|
|
|
import { Fyo, t } from 'fyo';
|
2022-04-24 06:48:44 +00:00
|
|
|
import { Doc } from 'fyo/model/doc';
|
2023-03-02 06:28:08 +00:00
|
|
|
import {
|
|
|
|
EmptyMessageMap,
|
|
|
|
FormulaMap,
|
|
|
|
ListsMap,
|
|
|
|
ListViewSettings,
|
|
|
|
} from 'fyo/model/types';
|
2022-05-17 12:12:57 +00:00
|
|
|
import { codeStateMap } from 'regional/in';
|
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 = {
|
2022-04-29 13:00:24 +00:00
|
|
|
addressDisplay: {
|
|
|
|
formula: async () => {
|
|
|
|
return [
|
|
|
|
this.addressLine1,
|
|
|
|
this.addressLine2,
|
|
|
|
this.city,
|
|
|
|
this.state,
|
|
|
|
this.country,
|
|
|
|
this.postalCode,
|
|
|
|
]
|
|
|
|
.filter(Boolean)
|
|
|
|
.join(', ');
|
|
|
|
},
|
|
|
|
dependsOn: [
|
|
|
|
'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':
|
2022-05-17 12:12:57 +00:00
|
|
|
return Object.values(codeStateMap).sort();
|
2022-04-11 12:44:36 +00:00
|
|
|
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
|
|
|
},
|
|
|
|
};
|
2023-03-02 06:28:08 +00:00
|
|
|
|
|
|
|
static override getListViewSettings(): ListViewSettings {
|
|
|
|
return {
|
|
|
|
columns: ['name', 'addressLine1', 'city', 'state', 'country'],
|
|
|
|
};
|
|
|
|
}
|
2022-04-11 12:44:36 +00:00
|
|
|
}
|