2022-04-19 05:59:36 +00:00
|
|
|
import { FormulaMap, ListsMap } from 'fyo/model/types';
|
2022-04-11 12:44:36 +00:00
|
|
|
import { Address as BaseAddress } from 'models/baseModels/Address/Address';
|
2022-05-17 12:12:57 +00:00
|
|
|
import { codeStateMap } from 'regional/in';
|
2022-04-11 12:44:36 +00:00
|
|
|
|
|
|
|
export class Address extends BaseAddress {
|
|
|
|
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
|
|
|
},
|
|
|
|
|
2022-04-29 13:00:24 +00:00
|
|
|
pos: {
|
|
|
|
formula: async () => {
|
2022-05-17 12:12:57 +00:00
|
|
|
const stateList = Object.values(codeStateMap).sort();
|
2022-04-29 13:00:24 +00:00
|
|
|
const state = this.state as string;
|
|
|
|
if (stateList.includes(state)) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
return '';
|
|
|
|
},
|
|
|
|
dependsOn: ['state'],
|
2022-04-11 12:44:36 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static lists: ListsMap = {
|
|
|
|
...BaseAddress.lists,
|
|
|
|
pos: () => {
|
2022-05-17 12:12:57 +00:00
|
|
|
return Object.values(codeStateMap).sort();
|
2022-04-11 12:44:36 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|