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

fix: prevent Save and Submit appearing together

This commit is contained in:
18alantom 2022-12-14 14:32:09 +05:30
parent 66cfd2efd9
commit d1c2b17ae3
6 changed files with 81 additions and 32 deletions

View File

@ -157,6 +157,74 @@ export class Doc extends Observable<DocValue | Doc[]> {
return false;
}
get canSave() {
if (!!this.submitted) {
return false;
}
if (!!this.cancelled) {
return false;
}
if (!this.dirty) {
return false;
}
if (!this.notInserted) {
return false;
}
return true;
}
get canSubmit() {
if (!this.schema.isSubmittable) {
return false;
}
if (this.dirty) {
return false;
}
if (this.notInserted) {
return false;
}
if (!!this.submitted) {
return false;
}
if (!!this.cancelled) {
return false;
}
return true;
}
get canCancel() {
if (!this.schema.isSubmittable) {
return false;
}
if (this.dirty) {
return false;
}
if (this.notInserted) {
return false;
}
if (!!this.cancelled) {
return false;
}
if (!this.submitted) {
return false;
}
return true;
}
_setValuesWithoutChecks(data: DocValueMap, convertToDocValue: boolean) {
for (const field of this.schema.fields) {
const { fieldname, fieldtype } = field;

View File

@ -14,19 +14,12 @@
</p>
<feather-icon v-else name="more-horizontal" class="w-4 h-4" />
</DropdownWithActions>
<Button
v-if="doc?.notInserted || doc?.dirty"
type="primary"
@click="sync"
>
<Button v-if="doc.canSave" type="primary" @click="sync">
{{ t`Save` }}
</Button>
<Button
v-if="!doc?.dirty && !doc?.notInserted && !doc?.submitted"
type="primary"
@click="submit"
>{{ t`Submit` }}</Button
>
<Button v-else-if="doc.canSubmit" type="primary" @click="submit">{{
t`Submit`
}}</Button>
</template>
<!-- Form Header -->

View File

@ -38,19 +38,12 @@
</p>
<feather-icon v-else name="more-horizontal" class="w-4 h-4" />
</DropdownWithActions>
<Button
v-if="doc?.notInserted || doc?.dirty"
type="primary"
@click="sync"
>
<Button v-if="doc.canSave" type="primary" @click="sync">
{{ t`Save` }}
</Button>
<Button
v-if="!doc?.dirty && !doc?.notInserted && !doc?.submitted"
type="primary"
@click="submit"
>{{ t`Submit` }}</Button
>
<Button v-else-if="doc.canSubmit" type="primary" @click="submit">{{
t`Submit`
}}</Button>
</template>
<!-- Invoice Form -->

View File

@ -15,7 +15,7 @@
<feather-icon v-else name="more-horizontal" class="w-4 h-4" />
</DropdownWithActions>
<Button
v-if="doc?.notInserted || doc?.dirty"
v-if="doc.canSave"
type="primary"
class="text-white text-xs"
@click="sync"
@ -23,7 +23,7 @@
{{ t`Save` }}
</Button>
<Button
v-else-if="!doc.dirty && !doc.notInserted && !doc.submitted"
v-else-if="doc.canSubmit"
type="primary"
class="text-white text-xs"
@click="submit"

View File

@ -26,7 +26,7 @@
:icon="true"
@click="sync"
type="primary"
v-if="doc?.dirty || doc?.notInserted"
v-if="doc.canSave"
class="text-white text-xs"
>
{{ t`Save` }}
@ -35,12 +35,7 @@
:icon="true"
@click="submit"
type="primary"
v-if="
schema?.isSubmittable &&
!doc?.submitted &&
!doc?.notInserted &&
!(doc?.cancelled || false)
"
v-else-if="doc.canSubmit"
class="text-white text-xs"
>
{{ t`Submit` }}

View File

@ -318,7 +318,7 @@ function getCancelAction(doc: Doc): Action {
component: {
template: '<span class="text-red-700">{{ t`Cancel` }}</span>',
},
condition: (doc: Doc) => doc.isSubmitted,
condition: (doc: Doc) => doc.canCancel,
async action() {
const res = await cancelDocWithPrompt(doc);