2
0
mirror of https://github.com/frappe/books.git synced 2025-01-23 07:08:36 +00:00
books/models/baseModels/AccountingSettings/AccountingSettings.ts

85 lines
2.1 KiB
TypeScript
Raw Normal View History

import { Doc } from 'fyo/model/doc';
import {
2022-07-14 18:03:31 +05:30
ChangeArg,
FiltersMap,
HiddenMap,
ListsMap,
ReadOnlyMap,
2022-11-30 11:24:05 +05:30
ValidationMap,
} 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';
import { getCountryInfo } from 'utils/misc';
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;
2024-08-09 10:41:54 +05:30
enableLead?: boolean;
2024-08-21 11:11:43 +05:30
enableCouponCode?: boolean;
enableFormCustomization?: boolean;
enableInvoiceReturns?: boolean;
enableLoyaltyProgram?: boolean;
2024-01-30 18:25:50 +05:30
enablePricingRule?: boolean;
2022-11-30 11:24:05 +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-22 16:32:03 +05:30
validations: ValidationMap = {
email: validateEmail,
};
static lists: ListsMap = {
country: () => Object.keys(getCountryInfo()),
};
readOnly: ReadOnlyMap = {
enableDiscounting: () => {
return !!this.enableDiscounting;
},
2022-11-30 11:24:05 +05:30
enableInventory: () => {
return !!this.enableInventory;
},
2024-08-09 10:41:54 +05:30
enableLead: () => {
return !!this.enableLead;
},
enableInvoiceReturns: () => {
return !!this.enableInvoiceReturns;
},
enableLoyaltyProgram: () => {
return !!this.enableLoyaltyProgram;
},
};
2022-07-14 18:03:31 +05:30
override hidden: HiddenMap = {
discountAccount: () => !this.enableDiscounting,
gstin: () => this.fyo.singles.SystemSettings?.countryCode !== 'in',
2024-01-30 18:25:50 +05:30
enablePricingRule: () =>
!this.fyo.singles.AccountingSettings?.enableDiscounting,
2024-08-21 11:11:43 +05:30
enableCouponCode: () =>
!this.fyo.singles.AccountingSettings?.enablePricingRule,
};
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);
}
}
}