mirror of
https://github.com/frappe/books.git
synced 2026-08-24 10:04:45 -05:00
patch: create default payment methods
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
import { ModelNameEnum } from 'models/types';
|
||||
import { DatabaseManager } from '../database/manager';
|
||||
import { AccountTypeEnum } from 'models/baseModels/Account/types';
|
||||
import { getDefaultMetaFieldValueMap } from 'backend/helpers';
|
||||
|
||||
type AccountTypeMap = Record<AccountTypeEnum, string[] | undefined>;
|
||||
|
||||
async function execute(dm: DatabaseManager) {
|
||||
const accounts = (await dm.db?.getAll(ModelNameEnum.Account, {
|
||||
fields: ['name', 'accountType'],
|
||||
filters: {
|
||||
accountType: [
|
||||
'in',
|
||||
[
|
||||
AccountTypeEnum.Bank,
|
||||
AccountTypeEnum.Cash,
|
||||
AccountTypeEnum.Payable,
|
||||
AccountTypeEnum.Receivable,
|
||||
],
|
||||
],
|
||||
},
|
||||
})) as { name: string; accountType: AccountTypeEnum }[];
|
||||
|
||||
const accountsMap = accounts.reduce((acc, ac) => {
|
||||
acc[ac.accountType] ??= [];
|
||||
acc[ac.accountType]!.push(ac.name);
|
||||
return acc;
|
||||
}, {} as AccountTypeMap);
|
||||
|
||||
const defaults = getDefaultMetaFieldValueMap();
|
||||
|
||||
const paymentMethods = [
|
||||
{
|
||||
name: 'Cash',
|
||||
account: accountsMap[AccountTypeEnum.Cash]?.[0],
|
||||
...defaults,
|
||||
},
|
||||
{
|
||||
name: 'Bank',
|
||||
account: accountsMap[AccountTypeEnum.Bank]?.[0],
|
||||
...defaults,
|
||||
},
|
||||
{
|
||||
name: 'Transfer',
|
||||
account: accountsMap[AccountTypeEnum.Bank]?.[0],
|
||||
...defaults,
|
||||
},
|
||||
];
|
||||
|
||||
for (const paymentMethod of paymentMethods) {
|
||||
await dm.db?.insert(ModelNameEnum.PaymentMethod, paymentMethod);
|
||||
}
|
||||
}
|
||||
export default { execute };
|
||||
@@ -7,6 +7,7 @@ import updateSchemas from './updateSchemas';
|
||||
import setPaymentReferenceType from './setPaymentReferenceType';
|
||||
import fixLedgerDateTime from './v0_21_0/fixLedgerDateTime';
|
||||
import fixItemHSNField from './fixItemHSNField';
|
||||
import createPaymentMethods from './createPaymentMethods';
|
||||
|
||||
export default [
|
||||
{ name: 'testPatch', version: '0.5.0-beta.0', patch: testPatch },
|
||||
@@ -42,4 +43,9 @@ export default [
|
||||
patch: fixLedgerDateTime,
|
||||
},
|
||||
{ name: 'fixItemHSNField', version: '0.24.0', patch: fixItemHSNField },
|
||||
{
|
||||
name: 'createPaymentMethods',
|
||||
version: '0.25.1',
|
||||
patch: createPaymentMethods,
|
||||
},
|
||||
] as Patch[];
|
||||
|
||||
Reference in New Issue
Block a user