2
0
mirror of https://github.com/frappe/books.git synced 2024-11-08 23:00:56 +00:00

fix: AutoComplete country, state, pos and place

This commit is contained in:
18alantom 2021-12-30 15:03:03 +05:30
parent bc39a26590
commit ddb46f8bee
4 changed files with 60 additions and 28 deletions

View File

@ -1,3 +1,16 @@
import { stateCodeMap } from '../../../accounting/gst';
import countryList from '../../../fixtures/countryInfo.json';
import { titleCase } from '../../../src/utils';
function getStates(doc) {
switch (doc.country) {
case 'India':
return Object.keys(stateCodeMap).map(titleCase).sort();
default:
return [];
}
}
export default {
name: 'Address',
doctype: 'DocType',
@ -9,7 +22,7 @@ export default {
'city',
'state',
'country',
'postalCode'
'postalCode',
],
fields: [
{
@ -23,69 +36,71 @@ export default {
fieldname: 'addressLine2',
label: 'Address Line 2',
placeholder: 'Address Line 2',
fieldtype: 'Data'
fieldtype: 'Data',
},
{
fieldname: 'city',
label: 'City / Town',
placeholder: 'City / Town',
fieldtype: 'Data',
required: 1
required: 1,
},
{
fieldname: 'state',
label: 'State',
placeholder: 'State',
fieldtype: 'Data',
fieldtype: 'AutoComplete',
getList: getStates,
},
{
fieldname: 'country',
label: 'Country',
placeholder: 'Country',
fieldtype: 'Data',
required: 1
fieldtype: 'AutoComplete',
getList: () => Object.keys(countryList).sort(),
required: 1,
},
{
fieldname: 'postalCode',
label: 'Postal Code',
placeholder: 'Postal Code',
fieldtype: 'Data'
fieldtype: 'Data',
},
{
fieldname: 'emailAddress',
label: 'Email Address',
placeholder: 'Email Address',
fieldtype: 'Data'
fieldtype: 'Data',
},
{
fieldname: 'phone',
label: 'Phone',
placeholder: 'Phone',
fieldtype: 'Data'
fieldtype: 'Data',
},
{
fieldname: 'fax',
label: 'Fax',
fieldtype: 'Data'
fieldtype: 'Data',
},
{
fieldname: 'addressDisplay',
fieldtype: 'Text',
label: 'Address Display',
readOnly: true,
formula: doc => {
formula: (doc) => {
return [
doc.addressLine1,
doc.addressLine2,
doc.city,
doc.state,
doc.country,
doc.postalCode
doc.postalCode,
]
.filter(Boolean)
.join(', ');
}
}
},
},
],
quickEditFields: [
'addressLine1',
@ -93,7 +108,7 @@ export default {
'city',
'state',
'country',
'postalCode'
'postalCode',
],
inlineEditDisplayField: 'addressDisplay'
inlineEditDisplayField: 'addressDisplay',
};

View File

@ -1,6 +1,7 @@
import { cloneDeep, capitalize } from 'lodash';
import AddressOriginal from './Address';
import { cloneDeep } from 'lodash';
import { stateCodeMap } from '../../../accounting/gst';
import { titleCase } from '../../../src/utils';
import AddressOriginal from './Address';
export default function getAugmentedAddress({ country }) {
const Address = cloneDeep(AddressOriginal);
@ -8,23 +9,22 @@ export default function getAugmentedAddress({ country }) {
return Address;
}
const stateList = Object.keys(stateCodeMap).map(titleCase).sort();
if (country === 'India') {
Address.fields = [
...Address.fields,
{
fieldname: 'pos',
label: 'Place of Supply',
fieldtype: 'Select',
fieldtype: 'AutoComplete',
placeholder: 'Place of Supply',
options: Object.keys(stateCodeMap).map((key) => capitalize(key)),
formula: (doc) => (stateList.includes(doc.state) ? doc.state : ''),
getList: () => stateList,
},
];
Address.quickEditFields = [
...Address.quickEditFields,
'pos',
];
Address.quickEditFields = [...Address.quickEditFields, 'pos'];
}
return Address;
}
}

View File

@ -1,5 +1,6 @@
import { DateTime } from 'luxon';
import { generateGstr1Json } from '../../accounting/gst';
import { generateGstr1Json, stateCodeMap } from '../../accounting/gst';
import { titleCase } from '../../src/utils';
const transferTypeMap = {
B2B: 'B2B',
@ -7,6 +8,7 @@ const transferTypeMap = {
B2CS: 'B2C-Small',
NR: 'Nil Rated, Exempted and Non GST supplies',
};
const stateList = Object.keys(stateCodeMap).map(titleCase).sort();
export default {
filterFields: [
@ -21,11 +23,12 @@ export default {
size: 'small',
},
{
fieldtype: 'Data',
fieldtype: 'AutoComplete',
label: 'Place',
size: 'small',
placeholder: 'Place',
fieldname: 'place',
getList: () => stateList,
},
{
fieldtype: 'Date',

View File

@ -4,6 +4,7 @@ import router from '@/router';
import { ipcRenderer } from 'electron';
import frappe from 'frappejs';
import { _ } from 'frappejs/utils';
import lodash from 'lodash';
import Vue from 'vue';
import { IPC_ACTIONS, IPC_MESSAGES } from './messages';
@ -337,3 +338,16 @@ export function showToast(props) {
},
});
}
export function titleCase(phrase) {
return phrase
.split(' ')
.map((word) => {
const wordLower = word.toLowerCase();
if (['and', 'an', 'a', 'from', 'by', 'on'].includes(wordLower)) {
return wordLower;
}
return lodash.capitalize(wordLower);
})
.join(' ');
}