2
0
mirror of https://github.com/frappe/books.git synced 2024-09-20 11:29:00 +00:00
books/models/baseModels/Address/Address.ts
18alantom 024687c1b9 fix: get Invoice settings to render and work
- remove "computed"
- fix a few formcontrols
- simplify doc.ts a bit more
2022-05-23 16:18:22 +05:30

65 lines
1.3 KiB
TypeScript

import { t } from 'fyo';
import { Doc } from 'fyo/model/doc';
import {
DependsOnMap,
EmptyMessageMap,
FormulaMap,
ListsMap,
} from 'fyo/model/types';
import { stateCodeMap } from 'regional/in';
import { titleCase } from 'utils';
import { getCountryInfo } from 'utils/misc';
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(', ');
},
};
dependsOn: DependsOnMap = {
addressDisplay: [
'addressLine1',
'addressLine2',
'city',
'state',
'country',
'postalCode',
],
};
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() {
return Object.keys(getCountryInfo()).sort();
},
};
static emptyMessages: EmptyMessageMap = {
state: (doc: Doc) => {
if (doc.country) {
return t`Enter State`;
}
return t`Enter Country to load States`;
},
};
}