mirror of
https://github.com/frappe/books.git
synced 2025-01-03 15:17:30 +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;
|
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) {
|
_setValuesWithoutChecks(data: DocValueMap) {
|
||||||
for (const field of this.schema.fields) {
|
for (const field of this.schema.fields) {
|
||||||
const fieldname = field.fieldname;
|
const fieldname = field.fieldname;
|
||||||
@ -694,7 +718,7 @@ export class Doc extends Observable<DocValue | Doc[]> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async delete() {
|
async delete() {
|
||||||
if (this.schema.isSubmittable && !this.isCancelled) {
|
if (!this.canDelete) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,7 +150,7 @@ export async function routeTo(route: string | RouteLocationRaw) {
|
|||||||
export async function deleteDocWithPrompt(doc: Doc) {
|
export async function deleteDocWithPrompt(doc: Doc) {
|
||||||
const schemaLabel = fyo.schemaMap[doc.schemaName]!.label;
|
const schemaLabel = fyo.schemaMap[doc.schemaName]!.label;
|
||||||
let detail = t`This action is permanent.`;
|
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.`;
|
detail = t`This action is permanent and will delete associated ledger entries.`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -291,9 +291,7 @@ function getDeleteAction(doc: Doc): Action {
|
|||||||
component: {
|
component: {
|
||||||
template: '<span class="text-red-700">{{ t`Delete` }}</span>',
|
template: '<span class="text-red-700">{{ t`Delete` }}</span>',
|
||||||
},
|
},
|
||||||
condition: (doc: Doc) =>
|
condition: (doc: Doc) => doc.canDelete,
|
||||||
(!doc.notInserted && !doc.schema.isSubmittable && !doc.schema.isSingle) ||
|
|
||||||
doc.isCancelled,
|
|
||||||
async action() {
|
async action() {
|
||||||
const res = await deleteDocWithPrompt(doc);
|
const res = await deleteDocWithPrompt(doc);
|
||||||
if (res) {
|
if (res) {
|
||||||
|
Loading…
Reference in New Issue
Block a user