2
0
mirror of https://github.com/frappe/books.git synced 2024-11-10 07:40:55 +00:00

fix: set party default account only if it exists

- refactor conditionals
- formatting
This commit is contained in:
18alantom 2021-11-10 17:00:47 +05:30
parent 0cabca4205
commit a9c54b814e
2 changed files with 27 additions and 29 deletions

View File

@ -62,10 +62,7 @@ export default {
} }
const accountExists = await frappe.db.exists('Account', accountName); const accountExists = await frappe.db.exists('Account', accountName);
if (!accountExists) { return accountExists ? accountName : '';
return '';
}
return accountName;
}, },
}, },
{ {

View File

@ -11,22 +11,22 @@ export default {
label: 'Name', label: 'Name',
fieldtype: 'Data', fieldtype: 'Data',
required: 1, required: 1,
placeholder: 'Full Name' placeholder: 'Full Name',
}, },
{ {
fieldname: 'image', fieldname: 'image',
label: 'Image', label: 'Image',
fieldtype: 'AttachImage' fieldtype: 'AttachImage',
}, },
{ {
fieldname: 'customer', fieldname: 'customer',
label: 'Customer', label: 'Customer',
fieldtype: 'Check' fieldtype: 'Check',
}, },
{ {
fieldname: 'supplier', fieldname: 'supplier',
label: 'Supplier', label: 'Supplier',
fieldtype: 'Check' fieldtype: 'Check',
}, },
{ {
fieldname: 'defaultAccount', fieldname: 'defaultAccount',
@ -36,22 +36,23 @@ export default {
getFilters: (query, doc) => { getFilters: (query, doc) => {
return { return {
isGroup: 0, isGroup: 0,
accountType: doc.customer ? 'Receivable' : 'Payable' accountType: doc.customer ? 'Receivable' : 'Payable',
}; };
}, },
formula: doc => { async formula(doc) {
if (doc.customer) { let accountName = 'Debtors'; // if Party is a Customer
return 'Debtors';
}
if (doc.supplier) { if (doc.supplier) {
return 'Creditors'; accountName = 'Creditors';
}
} }
const accountExists = await frappe.db.exists('Account', accountName);
return accountExists ? accountName : '';
},
}, },
{ {
fieldname: 'outstandingAmount', fieldname: 'outstandingAmount',
label: 'Outstanding Amount', label: 'Outstanding Amount',
fieldtype: 'Currency' fieldtype: 'Currency',
}, },
{ {
fieldname: 'currency', fieldname: 'currency',
@ -59,7 +60,7 @@ export default {
fieldtype: 'Link', fieldtype: 'Link',
target: 'Currency', target: 'Currency',
placeholder: 'INR', placeholder: 'INR',
formula: () => frappe.AccountingSettings.currency formula: () => frappe.AccountingSettings.currency,
}, },
{ {
fieldname: 'email', fieldname: 'email',
@ -67,8 +68,8 @@ export default {
fieldtype: 'Data', fieldtype: 'Data',
placeholder: 'john@doe.com', placeholder: 'john@doe.com',
validate: { validate: {
type: 'email' type: 'email',
} },
}, },
{ {
fieldname: 'phone', fieldname: 'phone',
@ -76,8 +77,8 @@ export default {
fieldtype: 'Data', fieldtype: 'Data',
placeholder: 'Phone', placeholder: 'Phone',
validate: { validate: {
type: 'phone' type: 'phone',
} },
}, },
{ {
fieldname: 'address', fieldname: 'address',
@ -85,27 +86,27 @@ export default {
fieldtype: 'Link', fieldtype: 'Link',
target: 'Address', target: 'Address',
placeholder: _('Click to create'), placeholder: _('Click to create'),
inline: true inline: true,
}, },
{ {
fieldname: 'addressDisplay', fieldname: 'addressDisplay',
label: 'Address Display', label: 'Address Display',
fieldtype: 'Text', fieldtype: 'Text',
readOnly: true, readOnly: true,
formula: doc => { formula: (doc) => {
if (doc.address) { if (doc.address) {
return doc.getFrom('Address', doc.address, 'addressDisplay'); return doc.getFrom('Address', doc.address, 'addressDisplay');
} }
} },
}, },
{ {
fieldname: 'gstin', fieldname: 'gstin',
label: 'GSTIN No.', label: 'GSTIN No.',
fieldtype: 'Data', fieldtype: 'Data',
hidden: form => { hidden: (form) => {
return form.gstType === 'Registered Regular' ? 0 : 1; return form.gstType === 'Registered Regular' ? 0 : 1;
} },
} },
], ],
quickEditFields: [ quickEditFields: [
@ -114,6 +115,6 @@ export default {
'address', 'address',
'defaultAccount', 'defaultAccount',
'currency', 'currency',
'gstin' 'gstin',
] ],
}; };