2022-04-24 12:18:44 +05:30
|
|
|
import { Doc } from 'fyo/model/doc';
|
2022-07-13 23:18:20 +05:30
|
|
|
import {
|
2022-07-14 18:03:31 +05:30
|
|
|
ChangeArg,
|
2022-07-13 23:18:20 +05:30
|
|
|
FiltersMap,
|
2023-03-01 13:43:04 +05:30
|
|
|
HiddenMap,
|
2022-07-13 23:18:20 +05:30
|
|
|
ListsMap,
|
|
|
|
ReadOnlyMap,
|
2022-11-30 11:24:05 +05:30
|
|
|
ValidationMap,
|
2022-07-13 23:18:20 +05:30
|
|
|
} from 'fyo/model/types';
|
2022-04-22 16:32:03 +05:30
|
|
|
import { validateEmail } from 'fyo/model/validationFunction';
|
2022-07-14 18:03:31 +05:30
|
|
|
import { createDiscountAccount } from 'src/setup/setupInstance';
|
2022-04-23 14:53:44 +05:30
|
|
|
import { getCountryInfo } from 'utils/misc';
|
2022-04-11 15:11:49 +05:30
|
|
|
|
|
|
|
export class AccountingSettings extends Doc {
|
2022-07-14 18:03:31 +05:30
|
|
|
enableDiscounting?: boolean;
|
2022-11-30 11:24:05 +05:30
|
|
|
enableInventory?: boolean;
|
2023-06-06 14:29:08 +05:30
|
|
|
enablePriceList?: boolean;
|
2022-11-30 11:24:05 +05:30
|
|
|
|
2022-04-11 15:11:49 +05:30
|
|
|
static filters: FiltersMap = {
|
|
|
|
writeOffAccount: () => ({
|
|
|
|
isGroup: false,
|
|
|
|
rootType: 'Expense',
|
|
|
|
}),
|
|
|
|
roundOffAccount: () => ({
|
|
|
|
isGroup: false,
|
|
|
|
rootType: 'Expense',
|
|
|
|
}),
|
2022-07-14 18:03:31 +05:30
|
|
|
discountAccount: () => ({
|
|
|
|
isGroup: false,
|
|
|
|
rootType: 'Income',
|
|
|
|
}),
|
2022-04-11 15:11:49 +05:30
|
|
|
};
|
|
|
|
|
2022-04-22 16:32:03 +05:30
|
|
|
validations: ValidationMap = {
|
|
|
|
email: validateEmail,
|
|
|
|
};
|
|
|
|
|
2022-04-11 15:11:49 +05:30
|
|
|
static lists: ListsMap = {
|
2022-04-23 14:53:44 +05:30
|
|
|
country: () => Object.keys(getCountryInfo()),
|
2022-04-11 15:11:49 +05:30
|
|
|
};
|
2022-07-13 23:18:20 +05:30
|
|
|
|
|
|
|
readOnly: ReadOnlyMap = {
|
|
|
|
enableDiscounting: () => {
|
|
|
|
return !!this.enableDiscounting;
|
|
|
|
},
|
2022-11-30 11:24:05 +05:30
|
|
|
enableInventory: () => {
|
|
|
|
return !!this.enableInventory;
|
|
|
|
},
|
2022-07-13 23:18:20 +05:30
|
|
|
};
|
2022-07-14 18:03:31 +05:30
|
|
|
|
2023-03-01 13:43:04 +05:30
|
|
|
override hidden: HiddenMap = {
|
|
|
|
discountAccount: () => !this.enableDiscounting,
|
|
|
|
gstin: () => this.fyo.singles.SystemSettings?.countryCode !== 'in',
|
|
|
|
};
|
|
|
|
|
2022-07-14 18:03:31 +05:30
|
|
|
async change(ch: ChangeArg) {
|
|
|
|
const discountingEnabled =
|
|
|
|
ch.changed === 'enableDiscounting' && this.enableDiscounting;
|
|
|
|
const discountAccountNotSet = !this.discountAccount;
|
|
|
|
|
|
|
|
if (discountingEnabled && discountAccountNotSet) {
|
|
|
|
await createDiscountAccount(this.fyo);
|
|
|
|
}
|
|
|
|
}
|
2022-04-11 15:11:49 +05:30
|
|
|
}
|