mirror of
https://github.com/frappe/books.git
synced 2024-12-22 19:09:01 +00:00
feat: allow account delete from coa
This commit is contained in:
parent
316f052c53
commit
93305344f9
@ -44,8 +44,9 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Add Account Buttons on Group Hover -->
|
<!-- 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
|
<button
|
||||||
|
v-if="account.isGroup"
|
||||||
class="
|
class="
|
||||||
text-xs text-gray-800
|
text-xs text-gray-800
|
||||||
hover:text-gray-900
|
hover:text-gray-900
|
||||||
@ -56,6 +57,7 @@
|
|||||||
{{ t`Add Account` }}
|
{{ t`Add Account` }}
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
|
v-if="account.isGroup"
|
||||||
class="
|
class="
|
||||||
ms-3
|
ms-3
|
||||||
text-xs text-gray-800
|
text-xs text-gray-800
|
||||||
@ -66,6 +68,17 @@
|
|||||||
>
|
>
|
||||||
{{ t`Add Group` }}
|
{{ t`Add Group` }}
|
||||||
</button>
|
</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>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -147,7 +160,7 @@ import { fyo } from 'src/initFyo';
|
|||||||
import { languageDirectionKey } from 'src/utils/injectionKeys';
|
import { languageDirectionKey } from 'src/utils/injectionKeys';
|
||||||
import { docsPathMap } from 'src/utils/misc';
|
import { docsPathMap } from 'src/utils/misc';
|
||||||
import { docsPathRef } from 'src/utils/refs';
|
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 { getMapFromList, removeAtIndex } from 'utils/index';
|
||||||
import { defineComponent, nextTick } from 'vue';
|
import { defineComponent, nextTick } from 'vue';
|
||||||
import Button from '../components/Button.vue';
|
import Button from '../components/Button.vue';
|
||||||
@ -158,6 +171,7 @@ import { TreeViewSettings } from 'fyo/model/types';
|
|||||||
import { Doc } from 'fyo/model/doc';
|
import { Doc } from 'fyo/model/doc';
|
||||||
import { Component } from 'vue';
|
import { Component } from 'vue';
|
||||||
import { uicolors } from 'src/utils/colors';
|
import { uicolors } from 'src/utils/colors';
|
||||||
|
import { showDialog } from 'src/utils/interactive';
|
||||||
|
|
||||||
type AccountItem = {
|
type AccountItem = {
|
||||||
name: string;
|
name: string;
|
||||||
@ -346,6 +360,34 @@ export default defineComponent({
|
|||||||
this.removeAccount(doc.name!, account, parentAccount);
|
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(
|
removeAccount(
|
||||||
name: string,
|
name: string,
|
||||||
account?: AccountItem,
|
account?: AccountItem,
|
||||||
|
@ -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);
|
const res = await deleteDocWithPrompt(doc);
|
||||||
if (!res) {
|
if (!res) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
showActionToast(doc, 'delete');
|
showActionToast(doc, 'delete');
|
||||||
|
if (routeBack) {
|
||||||
router.back();
|
router.back();
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user