2
0
mirror of https://github.com/frappe/books.git synced 2024-11-14 01:14:03 +00:00
books/models/baseModels/Account/Account.ts
18alantom de7e5ba807 refactor: rename 'frappe' to 'fyo' outside src
- cause now most of it is different from what it was
2022-05-23 16:18:22 +05:30

60 lines
1.3 KiB
TypeScript

import { Fyo } from 'fyo';
import Doc from 'fyo/model/doc';
import {
FiltersMap,
ListViewSettings,
TreeViewSettings,
} from 'fyo/model/types';
import { QueryFilter } from 'utils/db/types';
import { AccountRootType, AccountType } from './types';
export class Account extends Doc {
rootType?: AccountRootType;
accountType?: AccountType;
parentAccount?: string;
async beforeInsert() {
if (this.accountType || !this.parentAccount) {
return;
}
const account = await this.fyo.db.get(
'Account',
this.parentAccount as string
);
this.accountType = account.accountType as AccountType;
}
static getListViewSettings(): ListViewSettings {
return {
columns: ['name', 'parentAccount', 'rootType'],
};
}
static getTreeSettings(fyo: Fyo): void | TreeViewSettings {
return {
parentField: 'parentAccount',
async getRootLabel(): Promise<string> {
const accountingSettings = await fyo.doc.getSingle(
'AccountingSettings'
);
return accountingSettings.companyName as string;
},
};
}
static filters: FiltersMap = {
parentAccount: (doc: Account) => {
const filter: QueryFilter = {
isGroup: true,
};
if (doc.rootType) {
filter.rootType = doc.rootType as string;
}
return filter;
},
};
}