2
0
mirror of https://github.com/frappe/books.git synced 2025-02-13 09:29:18 +00:00

fix(ui): show draft status for JE and non-submitables, set Cash as default

This commit is contained in:
18alantom 2021-11-11 15:05:34 +05:30
parent de25de1fd4
commit f25ccd8aa8
7 changed files with 73 additions and 31 deletions

View File

@ -74,6 +74,7 @@ export default {
placeholder: 'Payment Method', placeholder: 'Payment Method',
fieldtype: 'Select', fieldtype: 'Select',
options: ['', 'Cash', 'Cheque', 'Transfer'], options: ['', 'Cash', 'Cheque', 'Transfer'],
default: 'Cash',
required: 1, required: 1,
}, },
{ {

View File

@ -1,6 +1,6 @@
import frappe from 'frappejs'; import frappe from 'frappejs';
import utils from '../../../accounting/utils'; import utils from '../../../accounting/utils';
import { openQuickEdit, getStatusAndColor } from '@/utils'; import { openQuickEdit, getInvoiceStatus, statusColor } from '@/utils';
import Badge from '@/components/Badge'; import Badge from '@/components/Badge';
export function getStatusColumn() { export function getStatusColumn() {
@ -9,7 +9,8 @@ export function getStatusColumn() {
fieldname: 'status', fieldname: 'status',
fieldtype: 'Select', fieldtype: 'Select',
render(doc) { render(doc) {
const { status, color } = getStatusAndColor(doc); const status = getInvoiceStatus(doc);
const color = statusColor[status];
return { return {
template: `<Badge class="text-xs" color="${color}">${status}</Badge>`, template: `<Badge class="text-xs" color="${color}">${status}</Badge>`,
components: { Badge }, components: { Badge },

View File

@ -0,0 +1,23 @@
<template>
<Badge class="text-xs flex-center px-3 ml-2" :color="color" v-if="status">{{
status
}}</Badge>
</template>
<script>
import frappe from 'frappejs';
import { statusColor } from '@/utils';
import Badge from '@/components/Badge';
export default {
name: 'StatusBadge',
props: ['status'],
components: {
Badge,
},
computed: {
color() {
return statusColor[this.status];
},
},
};
</script>

View File

@ -3,9 +3,7 @@
<PageHeader> <PageHeader>
<BackLink slot="title" /> <BackLink slot="title" />
<template slot="actions"> <template slot="actions">
<Badge class="text-xs flex-center px-3 ml-2" :color="color">{{ <StatusBadge :status="status" />
status
}}</Badge>
<Button <Button
v-if="doc.submitted" v-if="doc.submitted"
class="text-gray-900 text-xs ml-2" class="text-gray-900 text-xs ml-2"
@ -175,16 +173,17 @@
</template> </template>
<script> <script>
import frappe from 'frappejs'; import frappe from 'frappejs';
import Badge from '@/components/Badge'; import StatusBadge from '@/components/StatusBadge';
import PageHeader from '@/components/PageHeader'; import PageHeader from '@/components/PageHeader';
import Button from '@/components/Button'; import Button from '@/components/Button';
import FormControl from '@/components/Controls/FormControl'; import FormControl from '@/components/Controls/FormControl';
import DropdownWithActions from '@/components/DropdownWithActions'; import DropdownWithActions from '@/components/DropdownWithActions';
import BackLink from '@/components/BackLink'; import BackLink from '@/components/BackLink';
import { openSettings, getStatusAndColor } from '@/utils';
import { import {
openSettings,
handleErrorWithDialog, handleErrorWithDialog,
getActionsForDocument, getActionsForDocument,
getInvoiceStatus,
showMessageDialog, showMessageDialog,
} from '@/utils'; } from '@/utils';
@ -193,7 +192,7 @@ export default {
props: ['doctype', 'name'], props: ['doctype', 'name'],
components: { components: {
PageHeader, PageHeader,
Badge, StatusBadge,
Button, Button,
FormControl, FormControl,
DropdownWithActions, DropdownWithActions,
@ -255,9 +254,10 @@ export default {
if (query.values && query.doctype === this.doctype) { if (query.values && query.doctype === this.doctype) {
this.doc.set(this.$router.currentRoute.query.values); this.doc.set(this.$router.currentRoute.query.values);
} }
this.status = getInvoiceStatus(this.doc);
}, },
updated() { updated() {
this.setStatus(); this.status = getInvoiceStatus(this.doc);
}, },
methods: { methods: {
async onSaveClick() { async onSaveClick() {
@ -304,11 +304,6 @@ export default {
let df = doc.meta.getField(fieldname); let df = doc.meta.getField(fieldname);
return frappe.format(doc[fieldname], df, doc); return frappe.format(doc[fieldname], df, doc);
}, },
setStatus() {
const { status, color } = getStatusAndColor(this.doc);
this.status = status;
this.color = color;
},
}, },
}; };
</script> </script>

View File

@ -3,6 +3,7 @@
<PageHeader> <PageHeader>
<BackLink slot="title" /> <BackLink slot="title" />
<template slot="actions" v-if="doc"> <template slot="actions" v-if="doc">
<StatusBadge :status="status" />
<DropdownWithActions class="ml-2" :actions="actions" /> <DropdownWithActions class="ml-2" :actions="actions" />
<Button <Button
v-if="doc._notInserted || doc._dirty" v-if="doc._notInserted || doc._dirty"
@ -38,7 +39,7 @@
:df="meta.getField('entryType')" :df="meta.getField('entryType')"
:value="doc.entryType" :value="doc.entryType"
placeholder="Entry Type" placeholder="Entry Type"
@change="value => doc.set('entryType', value)" @change="(value) => doc.set('entryType', value)"
input-class="bg-gray-100 px-3 py-2 text-base" input-class="bg-gray-100 px-3 py-2 text-base"
:show-label="true" :show-label="true"
:read-only="doc.submitted" :read-only="doc.submitted"
@ -49,7 +50,7 @@
:df="meta.getField('date')" :df="meta.getField('date')"
:value="doc.date" :value="doc.date"
:placeholder="'Date'" :placeholder="'Date'"
@change="value => doc.set('date', value)" @change="(value) => doc.set('date', value)"
input-class="bg-gray-100 px-3 py-2 text-base" input-class="bg-gray-100 px-3 py-2 text-base"
:show-label="true" :show-label="true"
:read-only="doc.submitted" :read-only="doc.submitted"
@ -61,7 +62,7 @@
:df="meta.getField('referenceNumber')" :df="meta.getField('referenceNumber')"
:value="doc.referenceNumber" :value="doc.referenceNumber"
:placeholder="'Reference Number'" :placeholder="'Reference Number'"
@change="value => doc.set('referenceNumber', value)" @change="(value) => doc.set('referenceNumber', value)"
input-class="bg-gray-100 p-2 text-base" input-class="bg-gray-100 p-2 text-base"
:show-label="true" :show-label="true"
:read-only="doc.submitted" :read-only="doc.submitted"
@ -72,7 +73,7 @@
:df="meta.getField('referenceDate')" :df="meta.getField('referenceDate')"
:value="doc.date" :value="doc.date"
:placeholder="'Reference Date'" :placeholder="'Reference Date'"
@change="value => doc.set('referenceDate', value)" @change="(value) => doc.set('referenceDate', value)"
input-class="bg-gray-100 px-3 py-2 text-base" input-class="bg-gray-100 px-3 py-2 text-base"
:show-label="true" :show-label="true"
:read-only="doc.submitted" :read-only="doc.submitted"
@ -87,7 +88,7 @@
:value="doc.accounts" :value="doc.accounts"
:showHeader="true" :showHeader="true"
:max-rows-before-overflow="4" :max-rows-before-overflow="4"
@change="value => doc.set('accounts', value)" @change="(value) => doc.set('accounts', value)"
:read-only="doc.submitted" :read-only="doc.submitted"
/> />
</div> </div>
@ -101,7 +102,7 @@
<FormControl <FormControl
:df="meta.getField('userRemark')" :df="meta.getField('userRemark')"
:value="doc.userRemark" :value="doc.userRemark"
@change="value => doc.set('userRemark', value)" @change="(value) => doc.set('userRemark', value)"
:class="doc.submitted && 'pointer-events-none'" :class="doc.submitted && 'pointer-events-none'"
:read-only="doc.submitted" :read-only="doc.submitted"
/> />
@ -125,6 +126,7 @@ import Button from '@/components/Button';
import DropdownWithActions from '@/components/DropdownWithActions'; import DropdownWithActions from '@/components/DropdownWithActions';
import FormControl from '@/components/Controls/FormControl'; import FormControl from '@/components/Controls/FormControl';
import BackLink from '@/components/BackLink'; import BackLink from '@/components/BackLink';
import StatusBadge from '@/components/StatusBadge';
import { handleErrorWithDialog, getActionsForDocument } from '@/utils'; import { handleErrorWithDialog, getActionsForDocument } from '@/utils';
export default { export default {
@ -134,25 +136,33 @@ export default {
PageHeader, PageHeader,
Button, Button,
DropdownWithActions, DropdownWithActions,
StatusBadge,
FormControl, FormControl,
BackLink BackLink,
}, },
provide() { provide() {
return { return {
doctype: 'JournalEntry', doctype: 'JournalEntry',
name: this.name name: this.name,
}; };
}, },
data() { data() {
return { return {
doctype: 'JournalEntry', doctype: 'JournalEntry',
doc: null doc: null,
}; };
}, },
computed: { computed: {
meta() { meta() {
return frappe.getMeta(this.doctype); return frappe.getMeta(this.doctype);
}, },
status() {
if (this.doc._notInserted || !this.doc.submitted) {
return 'Draft';
}
return '';
},
totalDebit() { totalDebit() {
let value = 0; let value = 0;
if (this.doc.accounts) { if (this.doc.accounts) {
@ -169,7 +179,7 @@ export default {
}, },
actions() { actions() {
return getActionsForDocument(this.doc); return getActionsForDocument(this.doc);
} },
}, },
async mounted() { async mounted() {
try { try {
@ -192,7 +202,7 @@ export default {
}, },
handleError(e) { handleError(e) {
handleErrorWithDialog(e, this.doc); handleErrorWithDialog(e, this.doc);
} },
} },
}; };
</script> </script>

View File

@ -11,6 +11,7 @@
</div> </div>
<div class="flex items-stretch"> <div class="flex items-stretch">
<DropdownWithActions :actions="actions" /> <DropdownWithActions :actions="actions" />
<StatusBadge :status="status" />
<Button <Button
:icon="true" :icon="true"
@click="insertDoc" @click="insertDoc"
@ -78,6 +79,7 @@
import frappe from 'frappejs'; import frappe from 'frappejs';
import { _ } from 'frappejs'; import { _ } from 'frappejs';
import Button from '@/components/Button'; import Button from '@/components/Button';
import StatusBadge from '@/components/StatusBadge';
import FormControl from '@/components/Controls/FormControl'; import FormControl from '@/components/Controls/FormControl';
import TwoColumnForm from '@/components/TwoColumnForm'; import TwoColumnForm from '@/components/TwoColumnForm';
import DropdownWithActions from '@/components/DropdownWithActions'; import DropdownWithActions from '@/components/DropdownWithActions';
@ -93,6 +95,7 @@ export default {
components: { components: {
Button, Button,
FormControl, FormControl,
StatusBadge,
TwoColumnForm, TwoColumnForm,
DropdownWithActions, DropdownWithActions,
}, },
@ -121,6 +124,12 @@ export default {
meta() { meta() {
return frappe.getMeta(this.doctype); return frappe.getMeta(this.doctype);
}, },
status() {
if (this.doc && this.doc._notInserted) {
return "Draft";
}
return "";
},
fields() { fields() {
return this.meta return this.meta
.getQuickEditFields() .getQuickEditFields()

View File

@ -266,16 +266,19 @@ export async function runWindowAction(name) {
return name; return name;
} }
export function getStatusAndColor(doc) { export const statusColor = {
Draft: 'gray',
Unpaid: 'orange',
Paid: 'green',
};
export function getInvoiceStatus(doc) {
let status = 'Unpaid'; let status = 'Unpaid';
let color = 'orange';
if (!doc.submitted) { if (!doc.submitted) {
status = 'Draft'; status = 'Draft';
color = 'gray';
} }
if (doc.submitted === 1 && doc.outstandingAmount === 0.0) { if (doc.submitted === 1 && doc.outstandingAmount === 0.0) {
status = 'Paid'; status = 'Paid';
color = 'green';
} }
return { status, color }; return status;
} }