2
0
mirror of https://github.com/frappe/books.git synced 2024-09-20 11:29:00 +00:00
books/models/baseModels/AccountingSettings/AccountingSettings.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

59 lines
1.3 KiB
TypeScript
Raw Normal View History

import { Doc } from 'fyo/model/doc';
import {
2022-07-14 12:33:31 +00:00
ChangeArg,
FiltersMap,
ListsMap,
ReadOnlyMap,
2022-11-30 05:54:05 +00:00
ValidationMap,
} from 'fyo/model/types';
2022-04-22 11:02:03 +00:00
import { validateEmail } from 'fyo/model/validationFunction';
2022-07-14 12:33:31 +00:00
import { createDiscountAccount } from 'src/setup/setupInstance';
import { getCountryInfo } from 'utils/misc';
export class AccountingSettings extends Doc {
2022-07-14 12:33:31 +00:00
enableDiscounting?: boolean;
2022-11-30 05:54:05 +00:00
enableInventory?: boolean;
static filters: FiltersMap = {
writeOffAccount: () => ({
isGroup: false,
rootType: 'Expense',
}),
roundOffAccount: () => ({
isGroup: false,
rootType: 'Expense',
}),
2022-07-14 12:33:31 +00:00
discountAccount: () => ({
isGroup: false,
rootType: 'Income',
}),
};
2022-04-22 11:02:03 +00:00
validations: ValidationMap = {
email: validateEmail,
};
static lists: ListsMap = {
country: () => Object.keys(getCountryInfo()),
};
readOnly: ReadOnlyMap = {
enableDiscounting: () => {
return !!this.enableDiscounting;
},
2022-11-30 05:54:05 +00:00
enableInventory: () => {
return !!this.enableInventory;
},
};
2022-07-14 12:33:31 +00:00
async change(ch: ChangeArg) {
const discountingEnabled =
ch.changed === 'enableDiscounting' && this.enableDiscounting;
const discountAccountNotSet = !this.discountAccount;
if (discountingEnabled && discountAccountNotSet) {
await createDiscountAccount(this.fyo);
}
}
}