2
0
mirror of https://github.com/frappe/books.git synced 2024-12-23 03:19:01 +00:00

incr: get JournalEntryForm to render

This commit is contained in:
18alantom 2022-04-30 00:34:08 +05:30
parent 3e466c647c
commit e6b8c8a1b6
8 changed files with 98 additions and 76 deletions

View File

@ -3,6 +3,7 @@ import { Doc } from 'fyo/model/doc';
import { Action } from 'fyo/model/types'; import { Action } from 'fyo/model/types';
import { pesa } from 'pesa'; import { pesa } from 'pesa';
import { Field, OptionField, SelectOption } from 'schemas/types'; import { Field, OptionField, SelectOption } from 'schemas/types';
import { getIsNullOrUndef } from 'utils';
export function slug(str: string) { export function slug(str: string) {
return str return str
@ -77,7 +78,7 @@ export async function getSingleValue(
export function getOptionList( export function getOptionList(
field: Field, field: Field,
doc: Doc | undefined doc: Doc | undefined | null
): SelectOption[] { ): SelectOption[] {
const list = getRawOptionList(field, doc); const list = getRawOptionList(field, doc);
return list.map((option) => { return list.map((option) => {
@ -92,17 +93,17 @@ export function getOptionList(
}); });
} }
function getRawOptionList(field: Field, doc: Doc | undefined) { function getRawOptionList(field: Field, doc: Doc | undefined | null) {
const options = (field as OptionField).options; const options = (field as OptionField).options;
if (options && options.length > 0) { if (options && options.length > 0) {
return (field as OptionField).options; return (field as OptionField).options;
} }
if (doc === undefined) { if (getIsNullOrUndef(doc)) {
return []; return [];
} }
const Model = doc.fyo.models[doc.schemaName]; const Model = doc!.fyo.models[doc!.schemaName];
if (Model === undefined) { if (Model === undefined) {
return []; return [];
} }
@ -112,5 +113,5 @@ function getRawOptionList(field: Field, doc: Doc | undefined) {
return []; return [];
} }
return getList(doc); return getList(doc!);
} }

View File

@ -16,7 +16,6 @@
flex flex
items-center items-center
justify-between justify-between
bg-white
focus-within:bg-gray-200 focus-within:bg-gray-200
pr-2 pr-2
rounded rounded

View File

@ -4,13 +4,7 @@
{{ df.label }} {{ df.label }}
</div> </div>
<div <div
class=" class="flex items-center justify-between focus-within:bg-gray-200"
flex
items-center
justify-between
bg-white
focus-within:bg-gray-200
"
:class="inputClasses" :class="inputClasses"
> >
<select <select

View File

@ -89,9 +89,11 @@ export default {
Row, Row,
TableRow, TableRow,
}, },
inject: ['doc'], inject: {
mounted(){ doc: { default: null },
window.tab = this },
mounted() {
window.tab = this;
}, },
data: () => ({ rowContainerHeight: null }), data: () => ({ rowContainerHeight: null }),
watch: { watch: {

View File

@ -1,27 +1,30 @@
<template> <template>
<div class="flex flex-col"> <div class="flex flex-col">
<!-- Page Header (Title, Buttons, etc) -->
<PageHeader :backLink="true"> <PageHeader :backLink="true">
<template #actions v-if="doc"> <template #actions v-if="doc">
<StatusBadge :status="status" /> <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"
type="primary" type="primary"
class="text-white text-xs ml-2" class="text-white text-xs ml-2"
@click="onSaveClick" @click="sync"
> >
{{ t`Save` }} {{ t`Save` }}
</Button> </Button>
<Button <Button
v-if="!doc._dirty && !doc._notInserted && !doc.submitted" v-else-if="!doc.dirty && !doc.notInserted && !doc.submitted"
type="primary" type="primary"
class="text-white text-xs ml-2" class="text-white text-xs ml-2"
@click="onSubmitClick" @click="submit"
> >
{{ t`Submit` }} {{ t`Submit` }}
</Button> </Button>
</template> </template>
</PageHeader> </PageHeader>
<!-- Journal Entry Form -->
<div v-if="doc" class="flex justify-center flex-1 mb-8 mt-2"> <div v-if="doc" class="flex justify-center flex-1 mb-8 mt-2">
<div <div
class="border rounded-lg shadow h-full flex flex-col justify-between" class="border rounded-lg shadow h-full flex flex-col justify-between"
@ -30,12 +33,14 @@
<div> <div>
<div class="mt-8 px-6"> <div class="mt-8 px-6">
<h1 class="text-2xl font-semibold"> <h1 class="text-2xl font-semibold">
{{ doc._notInserted ? t`New Journal Entry` : doc.name }} {{ doc.notInserted ? t`New Journal Entry` : doc.name }}
</h1> </h1>
<!-- First Column of Fields -->
<div class="flex justify-between mt-2 gap-2"> <div class="flex justify-between mt-2 gap-2">
<div class="w-1/3"> <div class="w-1/3">
<FormControl <FormControl
:df="meta.getField('entryType')" :df="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)"
@ -45,7 +50,7 @@
/> />
<FormControl <FormControl
class="mt-2" class="mt-2"
:df="meta.getField('date')" :df="getField('date')"
:value="doc.date" :value="doc.date"
:placeholder="'Date'" :placeholder="'Date'"
@change="(value) => doc.set('date', value)" @change="(value) => doc.set('date', value)"
@ -54,9 +59,11 @@
:class="doc.submitted && 'pointer-events-none'" :class="doc.submitted && 'pointer-events-none'"
/> />
</div> </div>
<!-- Second Column of Fields -->
<div class="w-1/3"> <div class="w-1/3">
<FormControl <FormControl
:df="meta.getField('referenceNumber')" :df="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)"
@ -66,7 +73,7 @@
/> />
<FormControl <FormControl
class="mt-2" class="mt-2"
:df="meta.getField('referenceDate')" :df="getField('referenceDate')"
:value="doc.referenceDate" :value="doc.referenceDate"
:placeholder="'Reference Date'" :placeholder="'Reference Date'"
@change="(value) => doc.set('referenceDate', value)" @change="(value) => doc.set('referenceDate', value)"
@ -75,43 +82,52 @@
:class="doc.submitted && 'pointer-events-none'" :class="doc.submitted && 'pointer-events-none'"
/> />
</div> </div>
<!-- Third Column of Fields -->
<div class="w-1/3"> <div class="w-1/3">
<FormControl <FormControl
:df="meta.getField('numberSeries')" :df="getField('numberSeries')"
:value="doc.numberSeries" :value="doc.numberSeries"
@change="(value) => doc.set('numberSeries', value)" @change="(value) => doc.set('numberSeries', value)"
input-class="bg-gray-100 p-2 text-base" class="bg-gray-100 rounded"
:read-only="!doc._notInserted || doc.submitted" input-class="p-2 text-base bg-transparent"
:read-only="!doc.notInserted || doc.submitted"
:class="doc.submitted && 'pointer-events-none'" :class="doc.submitted && 'pointer-events-none'"
/> />
</div> </div>
</div> </div>
</div> </div>
<div class="mt-2 px-6 text-base">
<FormControl <!-- Account Entries Table -->
:df="meta.getField('accounts')" <FormControl
:value="doc.accounts" class="mt-2 px-6 text-base"
:showHeader="true" :df="getField('accounts')"
:max-rows-before-overflow="4" :value="doc.accounts"
@change="(value) => doc.set('accounts', value)" :showHeader="true"
:read-only="doc.submitted" :max-rows-before-overflow="4"
/> @change="(value) => doc.set('accounts', value)"
</div> :read-only="doc.submitted"
/>
</div> </div>
<!-- Footer -->
<div class="px-6 mb-6"> <div class="px-6 mb-6">
<div <div
class="grid items-center border-t pt-3 pr-2" class="grid items-center border-t pt-3 pr-2"
style="grid-template-columns: 1.3fr 1fr 1fr" style="grid-template-columns: 1.3fr 1fr 1fr"
> >
<!-- User Remark -->
<div class="text-sm"> <div class="text-sm">
<FormControl <FormControl
:df="meta.getField('userRemark')" :df="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"
/> />
</div> </div>
<!-- Debit and Credit -->
<div class="text-right font-semibold text-green-600 px-3"> <div class="text-right font-semibold text-green-600 px-3">
{{ totalDebit }} {{ totalDebit }}
</div> </div>
@ -125,13 +141,19 @@
</div> </div>
</template> </template>
<script> <script>
import { computed } from '@vue/reactivity';
import { ModelNameEnum } from 'models/types';
import Button from 'src/components/Button'; import Button from 'src/components/Button';
import FormControl from 'src/components/Controls/FormControl.vue'; import FormControl from 'src/components/Controls/FormControl.vue';
import DropdownWithActions from 'src/components/DropdownWithActions'; import DropdownWithActions from 'src/components/DropdownWithActions';
import PageHeader from 'src/components/PageHeader'; import PageHeader from 'src/components/PageHeader';
import StatusBadge from 'src/components/StatusBadge'; import StatusBadge from 'src/components/StatusBadge';
import { fyo } from 'src/initFyo'; import { fyo } from 'src/initFyo';
import { getActionsForDocument, routeTo, showMessageDialog } from 'src/utils'; import {
getActionsForDocument,
routeTo,
showMessageDialog
} from 'src/utils/ui';
import { handleErrorWithDialog } from '../errorHandling'; import { handleErrorWithDialog } from '../errorHandling';
export default { export default {
@ -146,22 +168,36 @@ export default {
}, },
provide() { provide() {
return { return {
doctype: 'JournalEntry', schemaName: this.schemaName,
name: this.name, name: this.name,
doc: computed(() => this.doc),
}; };
}, },
data() { data() {
return { return {
doctype: 'JournalEntry', schemaName: ModelNameEnum.JournalEntry,
doc: null, doc: null,
}; };
}, },
async mounted() {
try {
this.doc = await fyo.doc.getDoc(this.schemaName, this.name);
} catch (error) {
if (error instanceof fyo.errors.NotFoundError) {
routeTo(`/list/${this.schemaName}`);
return;
}
this.handleError(error);
}
if (fyo.store.isDevelopment) {
window.je = this;
}
},
computed: { computed: {
meta() {
return fyo.getMeta(this.doctype);
},
status() { status() {
if (this.doc._notInserted || !this.doc.submitted) { if (this.doc.notInserted || !this.doc.submitted) {
return 'Draft'; return 'Draft';
} }
@ -185,23 +221,14 @@ export default {
return getActionsForDocument(this.doc); return getActionsForDocument(this.doc);
}, },
}, },
async mounted() {
try {
this.doc = await fyo.doc.getDoc(this.doctype, this.name);
window.je = this.doc;
} catch (error) {
if (error instanceof fyo.errors.NotFoundError) {
routeTo(`/list/${this.doctype}`);
return;
}
this.handleError(error);
}
},
methods: { methods: {
async onSaveClick() { getField(fieldname) {
return fyo.getField(ModelNameEnum.JournalEntry, fieldname);
},
async sync() {
return this.doc.sync().catch(this.handleError); return this.doc.sync().catch(this.handleError);
}, },
async onSubmitClick() { async submit() {
showMessageDialog({ showMessageDialog({
message: this.t`Are you sure you want to submit this Journal Entry?`, message: this.t`Are you sure you want to submit this Journal Entry?`,
buttons: [ buttons: [

View File

@ -79,6 +79,7 @@
</template> </template>
<script> <script>
import { computed } from '@vue/reactivity';
import { t } from 'fyo'; import { t } from 'fyo';
import Button from 'src/components/Button.vue'; import Button from 'src/components/Button.vue';
import FormControl from 'src/components/Controls/FormControl.vue'; import FormControl from 'src/components/Controls/FormControl.vue';
@ -106,13 +107,19 @@ export default {
DropdownWithActions, DropdownWithActions,
}, },
provide() { provide() {
let vm = this;
return { return {
schemaName: this.schemaName, schemaName: this.schemaName,
name: this.name, name: this.name,
get doc() { doc: computed(() => this.doc),
return vm.doc; };
}, },
data() {
return {
doc: null,
values: null,
titleField: null,
imageField: null,
statusText: null,
}; };
}, },
mounted() { mounted() {
@ -124,15 +131,6 @@ export default {
window.qef = this; window.qef = this;
} }
}, },
data() {
return {
doc: null,
values: null,
titleField: null,
imageField: null,
statusText: null,
};
},
async created() { async created() {
await this.fetchFieldsAndDoc(); await this.fetchFieldsAndDoc();
}, },

View File

@ -29,6 +29,7 @@ import { setLanguageMap } from './utils/language';
const app = createApp({ const app = createApp({
template: '<App/>', template: '<App/>',
}); });
app.config.unwrapInjectedRef = true;
setErrorHandlers(app); setErrorHandlers(app);
app.use(router); app.use(router);

View File

@ -4,7 +4,7 @@ import Dashboard from 'src/pages/Dashboard/Dashboard.vue';
import GetStarted from 'src/pages/GetStarted.vue'; import GetStarted from 'src/pages/GetStarted.vue';
// import DataImport from 'src/pages/DataImport.vue'; // import DataImport from 'src/pages/DataImport.vue';
// import InvoiceForm from 'src/pages/InvoiceForm.vue'; // import InvoiceForm from 'src/pages/InvoiceForm.vue';
// import JournalEntryForm from 'src/pages/JournalEntryForm.vue'; import JournalEntryForm from 'src/pages/JournalEntryForm.vue';
import ListView from 'src/pages/ListView/ListView.vue'; import ListView from 'src/pages/ListView/ListView.vue';
// import PrintView from 'src/pages/PrintView/PrintView.vue'; // import PrintView from 'src/pages/PrintView/PrintView.vue';
import QuickEditForm from 'src/pages/QuickEditForm.vue'; import QuickEditForm from 'src/pages/QuickEditForm.vue';
@ -22,7 +22,6 @@ const routes: RouteRecordRaw[] = [
path: '/get-started', path: '/get-started',
component: GetStarted, component: GetStarted,
}, },
/*
{ {
path: '/edit/JournalEntry/:name', path: '/edit/JournalEntry/:name',
name: 'JournalEntryForm', name: 'JournalEntryForm',
@ -33,7 +32,7 @@ const routes: RouteRecordRaw[] = [
props: { props: {
default: (route) => { default: (route) => {
// for sidebar item active state // for sidebar item active state
route.params.doctype = 'JournalEntry'; route.params.schemaName = 'JournalEntry';
return { return {
doctype: 'JournalEntry', doctype: 'JournalEntry',
name: route.params.name, name: route.params.name,
@ -42,6 +41,7 @@ const routes: RouteRecordRaw[] = [
edit: (route) => route.query, edit: (route) => route.query,
}, },
}, },
/*
{ {
path: '/edit/:doctype/:name', path: '/edit/:doctype/:name',
name: 'InvoiceForm', name: 'InvoiceForm',