2
0
mirror of https://github.com/frappe/books.git synced 2024-11-08 23:00: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; 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) { _setValuesWithoutChecks(data: DocValueMap, convertToDocValue: boolean) {
for (const field of this.schema.fields) { for (const field of this.schema.fields) {
const { fieldname, fieldtype } = field; const { fieldname, fieldtype } = field;

View File

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

View File

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

View File

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

View File

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

View File

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