mirror of
https://github.com/frappe/books.git
synced 2024-11-14 17:34:04 +00:00
78 lines
1.9 KiB
TypeScript
78 lines
1.9 KiB
TypeScript
import { Doc } from 'fyo/model/doc';
|
|
import {
|
|
ChangeArg,
|
|
FiltersMap,
|
|
HiddenMap,
|
|
ListsMap,
|
|
ReadOnlyMap,
|
|
ValidationMap,
|
|
} from 'fyo/model/types';
|
|
import { validateEmail } from 'fyo/model/validationFunction';
|
|
import { createDiscountAccount } from 'src/setup/setupInstance';
|
|
import { getCountryInfo } from 'utils/misc';
|
|
|
|
export class AccountingSettings extends Doc {
|
|
enableDiscounting?: boolean;
|
|
enableInventory?: boolean;
|
|
enablePriceList?: boolean;
|
|
enableLead?: boolean;
|
|
enableFormCustomization?: boolean;
|
|
enableInvoiceReturns?: boolean;
|
|
enablePricingRule?: boolean;
|
|
|
|
static filters: FiltersMap = {
|
|
writeOffAccount: () => ({
|
|
isGroup: false,
|
|
rootType: 'Expense',
|
|
}),
|
|
roundOffAccount: () => ({
|
|
isGroup: false,
|
|
rootType: 'Expense',
|
|
}),
|
|
discountAccount: () => ({
|
|
isGroup: false,
|
|
rootType: 'Income',
|
|
}),
|
|
};
|
|
|
|
validations: ValidationMap = {
|
|
email: validateEmail,
|
|
};
|
|
|
|
static lists: ListsMap = {
|
|
country: () => Object.keys(getCountryInfo()),
|
|
};
|
|
|
|
readOnly: ReadOnlyMap = {
|
|
enableDiscounting: () => {
|
|
return !!this.enableDiscounting;
|
|
},
|
|
enableInventory: () => {
|
|
return !!this.enableInventory;
|
|
},
|
|
enableLead: () => {
|
|
return !!this.enableLead;
|
|
},
|
|
enableInvoiceReturns: () => {
|
|
return !!this.enableInvoiceReturns;
|
|
},
|
|
};
|
|
|
|
override hidden: HiddenMap = {
|
|
discountAccount: () => !this.enableDiscounting,
|
|
gstin: () => this.fyo.singles.SystemSettings?.countryCode !== 'in',
|
|
enablePricingRule: () =>
|
|
!this.fyo.singles.AccountingSettings?.enableDiscounting,
|
|
};
|
|
|
|
async change(ch: ChangeArg) {
|
|
const discountingEnabled =
|
|
ch.changed === 'enableDiscounting' && this.enableDiscounting;
|
|
const discountAccountNotSet = !this.discountAccount;
|
|
|
|
if (discountingEnabled && discountAccountNotSet) {
|
|
await createDiscountAccount(this.fyo);
|
|
}
|
|
}
|
|
}
|