2
0
mirror of https://github.com/frappe/books.git synced 2024-11-08 23:00:56 +00:00

fix(ux): allow delete when saved

This commit is contained in:
18alantom 2022-07-28 14:29:04 +05:30
parent 9136e5e647
commit c29c29bf82
2 changed files with 27 additions and 5 deletions

View File

@ -126,6 +126,30 @@ export class Doc extends Observable<DocValue | Doc[]> {
return this._syncing;
}
get canDelete() {
if (this.notInserted) {
return false;
}
if (this.schema.isSingle) {
return false;
}
if (!this.schema.isSubmittable) {
return true;
}
if (this.schema.isSubmittable && this.isCancelled) {
return true;
}
if (this.schema.isSubmittable && !this.isSubmitted) {
return true;
}
return false;
}
_setValuesWithoutChecks(data: DocValueMap) {
for (const field of this.schema.fields) {
const fieldname = field.fieldname;
@ -694,7 +718,7 @@ export class Doc extends Observable<DocValue | Doc[]> {
}
async delete() {
if (this.schema.isSubmittable && !this.isCancelled) {
if (!this.canDelete) {
return;
}

View File

@ -150,7 +150,7 @@ export async function routeTo(route: string | RouteLocationRaw) {
export async function deleteDocWithPrompt(doc: Doc) {
const schemaLabel = fyo.schemaMap[doc.schemaName]!.label;
let detail = t`This action is permanent.`;
if (doc.isTransactional) {
if (doc.isTransactional && doc.isSubmitted) {
detail = t`This action is permanent and will delete associated ledger entries.`;
}
@ -291,9 +291,7 @@ function getDeleteAction(doc: Doc): Action {
component: {
template: '<span class="text-red-700">{{ t`Delete` }}</span>',
},
condition: (doc: Doc) =>
(!doc.notInserted && !doc.schema.isSubmittable && !doc.schema.isSingle) ||
doc.isCancelled,
condition: (doc: Doc) => doc.canDelete,
async action() {
const res = await deleteDocWithPrompt(doc);
if (res) {