Skip to content

Commit

Permalink
feat: allow account delete from coa
Browse files Browse the repository at this point in the history
  • Loading branch information
18alantom committed Sep 21, 2023
1 parent 316f052 commit 9330534
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 4 deletions.
46 changes: 44 additions & 2 deletions src/pages/ChartOfAccounts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@
</div>

<!-- Add Account Buttons on Group Hover -->
<div v-if="account.isGroup" class="ms-6 hidden group-hover:block">
<div class="ms-6 hidden group-hover:block">
<button
v-if="account.isGroup"
class="
text-xs text-gray-800
hover:text-gray-900
Expand All @@ -56,6 +57,7 @@
{{ t`Add Account` }}
</button>
<button
v-if="account.isGroup"
class="
ms-3
text-xs text-gray-800
Expand All @@ -66,6 +68,17 @@
>
{{ t`Add Group` }}
</button>
<button
class="
ms-3
text-xs text-gray-800
hover:text-gray-900
focus:outline-none
"
@click.stop="deleteAccount(account)"
>
{{ account.isGroup ? t`Delete Group` : t`Delete Account` }}
</button>
</div>
</div>

Expand Down Expand Up @@ -147,7 +160,7 @@ import { fyo } from 'src/initFyo';
import { languageDirectionKey } from 'src/utils/injectionKeys';
import { docsPathMap } from 'src/utils/misc';
import { docsPathRef } from 'src/utils/refs';
import { openQuickEdit } from 'src/utils/ui';
import { commongDocDelete, openQuickEdit } from 'src/utils/ui';
import { getMapFromList, removeAtIndex } from 'utils/index';
import { defineComponent, nextTick } from 'vue';
import Button from '../components/Button.vue';
Expand All @@ -158,6 +171,7 @@ import { TreeViewSettings } from 'fyo/model/types';
import { Doc } from 'fyo/model/doc';
import { Component } from 'vue';
import { uicolors } from 'src/utils/colors';
import { showDialog } from 'src/utils/interactive';
type AccountItem = {
name: string;
Expand Down Expand Up @@ -346,6 +360,34 @@ export default defineComponent({
this.removeAccount(doc.name!, account, parentAccount);
});
},
async deleteAccount(account: AccountItem) {
const canDelete = await this.canDeleteAccount(account);
if (!canDelete) {
return;
}
const doc = await fyo.doc.getDoc(ModelNameEnum.Account, account.name);
this.setOpenAccountDocListener(doc, account);
await commongDocDelete(doc, false);
},
async canDeleteAccount(account: AccountItem) {
if (account.isGroup && !account.children?.length) {
await this.fetchChildren(account);
}
if (!account.children?.length) {
return true;
}
await showDialog({
type: 'error',
title: t`Cannot Delete Account`,
detail: t`${account.name} has linked child accounts.`,
});
return false;
},
removeAccount(
name: string,
account?: AccountItem,
Expand Down
9 changes: 7 additions & 2 deletions src/utils/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,14 +498,19 @@ export function getShortcutKeyMap(
};
}

export async function commongDocDelete(doc: Doc): Promise<boolean> {
export async function commongDocDelete(
doc: Doc,
routeBack = true
): Promise<boolean> {
const res = await deleteDocWithPrompt(doc);
if (!res) {
return false;
}

showActionToast(doc, 'delete');
router.back();
if (routeBack) {
router.back();
}
return true;
}

Expand Down

0 comments on commit 9330534

Please sign in to comment.