2022-04-24 06:48:44 +00:00
|
|
|
import { Doc } from 'fyo/model/doc';
|
2022-07-13 17:48:20 +00:00
|
|
|
import {
|
2022-07-14 12:33:31 +00:00
|
|
|
ChangeArg,
|
2022-07-13 17:48:20 +00:00
|
|
|
FiltersMap,
|
2023-03-01 08:13:04 +00:00
|
|
|
HiddenMap,
|
2022-07-13 17:48:20 +00:00
|
|
|
ListsMap,
|
|
|
|
ReadOnlyMap,
|
2022-11-30 05:54:05 +00:00
|
|
|
ValidationMap,
|
2022-07-13 17:48:20 +00:00
|
|
|
} 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';
|
2022-04-23 09:23:44 +00:00
|
|
|
import { getCountryInfo } from 'utils/misc';
|
2022-04-11 09:41:49 +00:00
|
|
|
|
|
|
|
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;
|
2023-06-06 08:59:08 +00:00
|
|
|
enablePriceList?: boolean;
|
2023-07-28 06:10:07 +00:00
|
|
|
enableFormCustomization?: boolean;
|
2023-09-23 11:12:21 +00:00
|
|
|
enableInvoiceReturns?: boolean;
|
2022-11-30 05:54:05 +00:00
|
|
|
|
2022-04-11 09:41:49 +00:00
|
|
|
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-11 09:41:49 +00:00
|
|
|
};
|
|
|
|
|
2022-04-22 11:02:03 +00:00
|
|
|
validations: ValidationMap = {
|
|
|
|
email: validateEmail,
|
|
|
|
};
|
|
|
|
|
2022-04-11 09:41:49 +00:00
|
|
|
static lists: ListsMap = {
|
2022-04-23 09:23:44 +00:00
|
|
|
country: () => Object.keys(getCountryInfo()),
|
2022-04-11 09:41:49 +00:00
|
|
|
};
|
2022-07-13 17:48:20 +00:00
|
|
|
|
|
|
|
readOnly: ReadOnlyMap = {
|
|
|
|
enableDiscounting: () => {
|
|
|
|
return !!this.enableDiscounting;
|
|
|
|
},
|
2022-11-30 05:54:05 +00:00
|
|
|
enableInventory: () => {
|
|
|
|
return !!this.enableInventory;
|
|
|
|
},
|
2023-09-23 11:12:21 +00:00
|
|
|
enableInvoiceReturns: () => {
|
|
|
|
return !!this.enableInvoiceReturns;
|
|
|
|
},
|
2022-07-13 17:48:20 +00:00
|
|
|
};
|
2022-07-14 12:33:31 +00:00
|
|
|
|
2023-03-01 08:13:04 +00:00
|
|
|
override hidden: HiddenMap = {
|
|
|
|
discountAccount: () => !this.enableDiscounting,
|
|
|
|
gstin: () => this.fyo.singles.SystemSettings?.countryCode !== 'in',
|
|
|
|
};
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2022-04-11 09:41:49 +00:00
|
|
|
}
|