mirror of
https://github.com/frappe/books.git
synced 2024-12-22 10:58:59 +00:00
fix(ux): allow delete when saved
This commit is contained in:
parent
9136e5e647
commit
c29c29bf82
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user