mirror of
https://github.com/frappe/books.git
synced 2024-11-08 14:50:56 +00:00
incr: add discountAccount
This commit is contained in:
parent
877cc0b8d4
commit
01c2d903b1
@ -50,7 +50,6 @@ export function getMissingMandatoryMessage(doc: Doc) {
|
||||
const value = doc.get(f.fieldname);
|
||||
const isNullOrUndef = getIsNullOrUndef(value);
|
||||
|
||||
console.log(f.fieldname, value);
|
||||
if (f.fieldtype === FieldTypeEnum.Table) {
|
||||
return isNullOrUndef || (value as Doc[])?.length === 0;
|
||||
}
|
||||
|
@ -1,14 +1,17 @@
|
||||
import { Doc } from 'fyo/model/doc';
|
||||
import {
|
||||
ChangeArg,
|
||||
FiltersMap,
|
||||
ListsMap,
|
||||
ReadOnlyMap,
|
||||
ValidationMap,
|
||||
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;
|
||||
static filters: FiltersMap = {
|
||||
writeOffAccount: () => ({
|
||||
isGroup: false,
|
||||
@ -18,6 +21,10 @@ export class AccountingSettings extends Doc {
|
||||
isGroup: false,
|
||||
rootType: 'Expense',
|
||||
}),
|
||||
discountAccount: () => ({
|
||||
isGroup: false,
|
||||
rootType: 'Income',
|
||||
}),
|
||||
};
|
||||
|
||||
validations: ValidationMap = {
|
||||
@ -33,4 +40,14 @@ export class AccountingSettings extends Doc {
|
||||
return !!this.enableDiscounting;
|
||||
},
|
||||
};
|
||||
|
||||
async change(ch: ChangeArg) {
|
||||
const discountingEnabled =
|
||||
ch.changed === 'enableDiscounting' && this.enableDiscounting;
|
||||
const discountAccountNotSet = !this.discountAccount;
|
||||
|
||||
if (discountingEnabled && discountAccountNotSet) {
|
||||
await createDiscountAccount(this.fyo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,15 +16,13 @@
|
||||
"label": "Write Off Account",
|
||||
"fieldname": "writeOffAccount",
|
||||
"fieldtype": "Link",
|
||||
"target": "Account",
|
||||
"default": "Write Off"
|
||||
"target": "Account"
|
||||
},
|
||||
{
|
||||
"label": "Round Off Account",
|
||||
"fieldname": "roundOffAccount",
|
||||
"fieldtype": "Link",
|
||||
"target": "Account",
|
||||
"default": "Rounded Off"
|
||||
"target": "Account"
|
||||
},
|
||||
{
|
||||
"fieldname": "country",
|
||||
@ -71,6 +69,12 @@
|
||||
"fieldtype": "Check",
|
||||
"default": false
|
||||
},
|
||||
{
|
||||
"label": "Discount Account",
|
||||
"fieldname": "discountAccount",
|
||||
"fieldtype": "Link",
|
||||
"target": "Account"
|
||||
},
|
||||
{
|
||||
"fieldname": "setupComplete",
|
||||
"label": "Setup Complete",
|
||||
|
@ -37,19 +37,33 @@ export default {
|
||||
},
|
||||
computed: {
|
||||
fields() {
|
||||
return [
|
||||
const fields = [
|
||||
'fullname',
|
||||
'companyName',
|
||||
'country',
|
||||
'bankName',
|
||||
'currency',
|
||||
'writeOffAccount',
|
||||
'roundOffAccount',
|
||||
'fiscalYearStart',
|
||||
'fiscalYearEnd',
|
||||
'enableDiscounting',
|
||||
'gstin',
|
||||
].map((fieldname) => fyo.getField('AccountingSettings', fieldname));
|
||||
'writeOffAccount',
|
||||
'roundOffAccount',
|
||||
];
|
||||
|
||||
if (!this.doc.enableDiscounting) {
|
||||
fields.push('enableDiscounting');
|
||||
}
|
||||
|
||||
if (this.doc.enableDiscounting) {
|
||||
fields.push('discountAccount');
|
||||
}
|
||||
|
||||
if (fyo.singles.SystemSettings.countryCode === 'in') {
|
||||
fields.push('gstin');
|
||||
}
|
||||
|
||||
return fields.map((fieldname) =>
|
||||
fyo.getField('AccountingSettings', fieldname)
|
||||
);
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
|
@ -5,8 +5,9 @@ import { createNumberSeries } from 'fyo/model/naming';
|
||||
import {
|
||||
DEFAULT_CURRENCY,
|
||||
DEFAULT_LOCALE,
|
||||
DEFAULT_SERIES_START,
|
||||
DEFAULT_SERIES_START
|
||||
} from 'fyo/utils/consts';
|
||||
import { AccountRootTypeEnum } from 'models/baseModels/Account/types';
|
||||
import { AccountingSettings } from 'models/baseModels/AccountingSettings/AccountingSettings';
|
||||
import { ModelNameEnum } from 'models/types';
|
||||
import { initializeInstance } from 'src/initFyo';
|
||||
@ -159,14 +160,65 @@ async function createAccountRecords(
|
||||
const createCOA = new CreateCOA(chartOfAccounts, fyo);
|
||||
await createCOA.run();
|
||||
const parentAccount = await getBankAccountParentName(country, fyo);
|
||||
const docObject = {
|
||||
const bankAccountDoc = {
|
||||
name: bankName,
|
||||
rootType: 'Asset',
|
||||
rootType: AccountRootTypeEnum.Asset,
|
||||
parentAccount,
|
||||
accountType: 'Bank',
|
||||
isGroup: false,
|
||||
};
|
||||
await checkAndCreateDoc('Account', docObject, fyo);
|
||||
|
||||
await checkAndCreateDoc('Account', bankAccountDoc, fyo);
|
||||
await createDiscountAccount(fyo);
|
||||
await setDefaultAccounts(fyo);
|
||||
}
|
||||
|
||||
export async function createDiscountAccount(fyo: Fyo) {
|
||||
const incomeAccountName = fyo.t`Indirect Income`;
|
||||
const accountExists = await fyo.db.exists(
|
||||
ModelNameEnum.Account,
|
||||
incomeAccountName
|
||||
);
|
||||
|
||||
if (!accountExists) {
|
||||
return;
|
||||
}
|
||||
|
||||
const discountAccountName = fyo.t`Discounts`;
|
||||
const discountAccountDoc = {
|
||||
name: discountAccountName,
|
||||
rootType: AccountRootTypeEnum.Income,
|
||||
parentAccount: incomeAccountName,
|
||||
accountType: 'Income Account',
|
||||
isGroup: false,
|
||||
};
|
||||
|
||||
await checkAndCreateDoc(ModelNameEnum.Account, discountAccountDoc, fyo);
|
||||
await fyo.singles.AccountingSettings!.setAndSync(
|
||||
'discountAccount',
|
||||
discountAccountName
|
||||
);
|
||||
}
|
||||
|
||||
async function setDefaultAccounts(fyo: Fyo) {
|
||||
const accountMap: Record<string, string> = {
|
||||
writeOffAccount: fyo.t`Write Off`,
|
||||
roundOffAccount: fyo.t`Rounded Off`,
|
||||
};
|
||||
|
||||
for (const key in accountMap) {
|
||||
const accountName = accountMap[key];
|
||||
const accountExists = await fyo.db.exists(
|
||||
ModelNameEnum.Account,
|
||||
accountName
|
||||
);
|
||||
|
||||
if (!accountExists) {
|
||||
continue;
|
||||
}
|
||||
|
||||
await fyo.singles.AccountingSettings!.setAndSync(key, accountName);
|
||||
}
|
||||
}
|
||||
|
||||
async function completeSetup(companyName: string, fyo: Fyo) {
|
||||
|
Loading…
Reference in New Issue
Block a user