2
0
mirror of https://github.com/frappe/books.git synced 2024-11-09 23:30:56 +00:00

incr: move Shipments and PRec to common form

- remove GeneralForm.vue
This commit is contained in:
18alantom 2023-02-21 12:12:06 +05:30
parent 332307bdd1
commit d946c960a0
8 changed files with 80 additions and 385 deletions

View File

@ -1,7 +1,13 @@
import { Fyo, t } from 'fyo';
import { Attachment } from 'fyo/core/types';
import { Doc } from 'fyo/model/doc';
import { Action, DefaultMap, FiltersMap, FormulaMap } from 'fyo/model/types';
import {
Action,
DefaultMap,
FiltersMap,
FormulaMap,
HiddenMap,
} from 'fyo/model/types';
import { ValidationError } from 'fyo/utils/errors';
import { Defaults } from 'models/baseModels/Defaults/Defaults';
import { Invoice } from 'models/baseModels/Invoice/Invoice';
@ -33,6 +39,14 @@ export abstract class StockTransfer extends Transfer {
},
};
hidden: HiddenMap = {
backReference: () =>
!(this.backReference || !(this.isSubmitted || this.isCancelled)),
terms: () => !(this.terms || !(this.isSubmitted || this.isCancelled)),
attachment: () =>
!(this.attachment || !(this.isSubmitted || this.isCancelled)),
};
static defaults: DefaultMap = {
numberSeries: (doc) => getNumberSeries(doc.schemaName, doc.fyo),
terms: (doc) => {

View File

@ -5,14 +5,6 @@
"naming": "numberSeries",
"showTitle": true,
"fields": [
{
"fieldname": "items",
"label": "Items",
"fieldtype": "Table",
"target": "PurchaseReceiptItem",
"required": true,
"edit": true
},
{
"fieldname": "numberSeries",
"label": "Number Series",
@ -20,14 +12,24 @@
"target": "NumberSeries",
"create": true,
"required": true,
"default": "PREC-"
"default": "PREC-",
"section": "Default"
},
{
"fieldname": "backReference",
"label": "Back Reference",
"fieldtype": "Link",
"target": "PurchaseInvoice",
"readOnly": true
"readOnly": true,
"section": "References"
},
{
"fieldname": "items",
"label": "Items",
"fieldtype": "Table",
"target": "PurchaseReceiptItem",
"required": true,
"edit": true
}
],
"keywordFields": ["name", "party"]

View File

@ -5,14 +5,6 @@
"naming": "numberSeries",
"showTitle": true,
"fields": [
{
"fieldname": "items",
"label": "Items",
"fieldtype": "Table",
"target": "ShipmentItem",
"required": true,
"edit": true
},
{
"fieldname": "numberSeries",
"label": "Number Series",
@ -20,14 +12,25 @@
"target": "NumberSeries",
"create": true,
"required": true,
"default": "SHPM-"
"default": "SHPM-",
"section": "Default"
},
{
"fieldname": "backReference",
"label": "Back Reference",
"fieldtype": "Link",
"target": "SalesInvoice",
"readOnly": true
"readOnly": true,
"section": "References"
},
{
"fieldname": "items",
"label": "Items",
"fieldtype": "Table",
"target": "ShipmentItem",
"required": true,
"edit": true,
"section": "Items"
}
],
"keywordFields": ["name", "party"]

View File

@ -11,13 +11,13 @@
"fieldname": "name",
"fieldtype": "Data",
"required": true,
"readOnly": true
"readOnly": true,
"section": "Default"
},
{
"fieldname": "date",
"label": "Date",
"fieldtype": "Datetime",
"required": true
"abstract": true,
"fieldname": "numberSeries",
"section": "Default"
},
{
"fieldname": "party",
@ -25,25 +25,46 @@
"fieldtype": "Link",
"target": "Party",
"create": true,
"required": true
"required": true,
"section": "Default"
},
{
"fieldname": "terms",
"label": "Notes",
"placeholder": "Add transfer terms",
"fieldtype": "Text"
"fieldname": "date",
"label": "Date",
"fieldtype": "Datetime",
"required": true,
"section": "Default"
},
{
"fieldname": "attachment",
"placeholder": "Add attachment",
"label": "Attachment",
"fieldtype": "Attachment"
"abstract": true,
"fieldname": "items",
"section": "Items"
},
{
"fieldname": "grandTotal",
"label": "Grand Total",
"fieldtype": "Currency",
"readOnly": true
"readOnly": true,
"section": "Items"
},
{
"fieldname": "terms",
"label": "Notes",
"placeholder": "Add transfer terms",
"fieldtype": "Text",
"section": "References"
},
{
"fieldname": "attachment",
"placeholder": "Add attachment",
"label": "Attachment",
"fieldtype": "Attachment",
"section": "References"
},
{
"abstract": true,
"fieldname": "backReference",
"section": "References"
}
],
"keywordFields": ["name", "party"]

View File

@ -66,6 +66,7 @@ export interface BaseField {
computed?: boolean; // Computed values are not stored in the database.
section?: string; // UI Facing config, for grouping by sections
tab?: string; // UI Facing config, for grouping by tabs
abstract?: string; // Uused to mark the location of a field in an Abstract schema
}
export type SelectOption = { value: string; label: string };

View File

@ -289,7 +289,6 @@ export default defineComponent({
},
async onValueChange(field: Field, value: DocValue) {
const { fieldname } = field;
console.log(fieldname, value);
delete this.errors[fieldname];
try {

View File

@ -1,320 +0,0 @@
<template>
<FormContainer>
<!-- Page Header (Title, Buttons, etc) -->
<template #header v-if="doc">
<StatusBadge :status="status" />
<Barcode
v-if="showBarcode"
@item-selected="(name) => doc.addItem(name)"
/>
<DropdownWithActions
v-for="group of groupedActions"
:key="group.label"
:type="group.type"
:actions="group.actions"
>
<p v-if="group.group">
{{ group.group }}
</p>
<feather-icon v-else name="more-horizontal" class="w-4 h-4" />
</DropdownWithActions>
<Button v-if="doc?.canSave" type="primary" @click="sync">
{{ t`Save` }}
</Button>
<Button v-else-if="doc?.canSubmit" type="primary" @click="submit">{{
t`Submit`
}}</Button>
</template>
<!-- Form Header -->
<template #body v-if="doc">
<FormHeader
:form-title="doc.notInserted ? t`New Entry` : doc.name"
:form-sub-title="doc.schema?.label ?? ''"
/>
<hr />
<div>
<!-- Form Data Entry -->
<div class="m-4 grid grid-cols-3 gap-4">
<FormControl
input-class="font-semibold"
:border="true"
:df="getField('party')"
:value="doc.party"
@change="(value) => doc.set('party', value, true)"
@new-doc="(party) => doc.set('party', party.name, true)"
:read-only="doc?.submitted"
/>
<FormControl
input-class="text-end"
:border="true"
:df="getField('date')"
:value="doc.date"
@change="(value) => doc.set('date', value)"
:read-only="doc?.submitted"
/>
<FormControl
input-class="text-end"
:border="true"
:df="getField('numberSeries')"
:value="doc.numberSeries"
@change="(value) => doc.set('numberSeries', value)"
:read-only="!doc.notInserted || doc?.submitted"
/>
<FormControl
v-if="doc.backReference"
:border="true"
:df="getField('backReference')"
:value="doc.backReference"
:read-only="true"
/>
<FormControl
v-if="doc.attachment || !(doc.isSubmitted || doc.isCancelled)"
:border="true"
:df="getField('attachment')"
:value="doc.attachment"
@change="(value) => doc.set('attachment', value)"
:read-only="doc?.submitted"
/>
</div>
<hr />
<!-- Items Table -->
<Table
class="text-base"
:df="getField('items')"
:value="doc.items"
:showHeader="true"
:max-rows-before-overflow="4"
@change="(value) => doc.set('items', value)"
@editrow="toggleQuickEditDoc"
:read-only="doc?.submitted"
/>
</div>
<!-- Form Footer -->
<div v-if="doc.items?.length ?? 0" class="mt-auto">
<hr />
<div class="flex justify-between text-base m-4 gap-12">
<div class="w-1/2 flex flex-col justify-between">
<!-- Form Terms-->
<FormControl
:border="true"
v-if="!doc?.submitted || doc.terms"
:df="getField('terms')"
:value="doc.terms"
class="mt-auto"
@change="(value) => doc.set('terms', value)"
:read-only="doc?.submitted"
/>
</div>
<div class="w-1/2" v-if="doc.grandTotal">
<!-- Grand Total -->
<div
class="
flex
justify-between
text-green-600
font-semibold
text-base
"
>
<div>{{ t`Grand Total` }}</div>
<div>{{ formattedValue('grandTotal') }}</div>
</div>
</div>
</div>
</div>
</template>
<template #quickedit v-if="quickEditDoc">
<QuickEditForm
:name="quickEditDoc.name"
:show-name="false"
:show-save="false"
:source-doc="quickEditDoc"
:source-fields="quickEditFields"
:schema-name="quickEditDoc.schemaName"
:white="true"
:route-back="false"
:load-on-close="false"
@close="toggleQuickEditDoc(null)"
/>
</template>
</FormContainer>
</template>
<script>
import { computed } from '@vue/reactivity';
import { t } from 'fyo';
import { getDocStatus } from 'models/helpers';
import { ModelNameEnum } from 'models/types';
import Button from 'src/components/Button.vue';
import Barcode from 'src/components/Controls/Barcode.vue';
import FormControl from 'src/components/Controls/FormControl.vue';
import Table from 'src/components/Controls/Table.vue';
import DropdownWithActions from 'src/components/DropdownWithActions.vue';
import FormContainer from 'src/components/FormContainer.vue';
import FormHeader from 'src/components/FormHeader.vue';
import StatusBadge from 'src/components/StatusBadge.vue';
import { fyo } from 'src/initFyo';
import { docsPathMap } from 'src/utils/misc';
import { docsPathRef, focusedDocsRef } from 'src/utils/refs';
import {
getGroupedActionsForDoc,
routeTo,
showMessageDialog,
} from 'src/utils/ui';
import { nextTick } from 'vue';
import { handleErrorWithDialog } from '../errorHandling';
import QuickEditForm from './QuickEditForm.vue';
export default {
name: 'InvoiceForm',
props: { schemaName: String, name: String },
components: {
StatusBadge,
Button,
FormControl,
DropdownWithActions,
Table,
FormContainer,
QuickEditForm,
FormHeader,
Barcode,
},
provide() {
return {
schemaName: this.schemaName,
name: this.name,
doc: computed(() => this.doc),
};
},
data() {
return {
chstatus: false,
doc: null,
quickEditDoc: null,
quickEditFields: [],
printSettings: null,
};
},
updated() {
this.chstatus = !this.chstatus;
},
computed: {
status() {
this.chstatus;
return getDocStatus(this.doc);
},
groupedActions() {
return getGroupedActionsForDoc(this.doc);
},
showBarcode() {
if (!this.doc) {
return false;
}
if (!this.doc.canEdit) {
return false;
}
if (!fyo.singles.InventorySettings?.enableBarcodes) {
return false;
}
return [
ModelNameEnum.Shipment,
ModelNameEnum.PurchaseReceipt,
ModelNameEnum.StockMovement,
].includes(this.schemaName);
},
},
activated() {
docsPathRef.value = docsPathMap[this.schemaName];
focusedDocsRef.add(this.doc);
},
deactivated() {
docsPathRef.value = '';
focusedDocsRef.delete(this.doc);
},
async mounted() {
try {
this.doc = await fyo.doc.getDoc(this.schemaName, this.name);
focusedDocsRef.add(this.doc);
} catch (error) {
if (error instanceof fyo.errors.NotFoundError) {
routeTo(`/list/${this.schemaName}`);
return;
}
await this.handleError(error);
}
let query = this.$route.query;
if (query.values && query.schemaName === this.schemaName) {
this.doc.set(this.$router.currentRoute.value.query.values);
}
if (fyo.store.isDevelopment) {
window.frm = this;
}
},
methods: {
routeTo,
async toggleQuickEditDoc(doc, fields = []) {
if (this.quickEditDoc && doc) {
this.quickEditDoc = null;
this.quickEditFields = [];
await nextTick();
}
this.quickEditDoc = doc;
this.quickEditFields = fields;
},
getField(fieldname) {
return fyo.getField(this.schemaName, fieldname);
},
async sync() {
try {
await this.doc.sync();
} catch (err) {
await this.handleError(err);
}
},
async submit() {
const message = t`Submit ${this.doc.name}`;
const ref = this;
await showMessageDialog({
message,
buttons: [
{
label: t`Yes`,
async action() {
try {
await ref.doc.submit();
} catch (err) {
await ref.handleError(err);
}
},
},
{
label: t`No`,
action() {},
},
],
});
},
async handleError(e) {
await handleErrorWithDialog(e, this.doc);
},
formattedValue(fieldname, doc) {
if (!doc) {
doc = this.doc;
}
const df = this.getField(fieldname);
return fyo.format(doc[fieldname], df, doc);
},
},
};
</script>

View File

@ -2,7 +2,6 @@ import { ModelNameEnum } from 'models/types';
import ChartOfAccounts from 'src/pages/ChartOfAccounts.vue';
import CommonForm from 'src/pages/CommonForm/CommonForm.vue';
import Dashboard from 'src/pages/Dashboard/Dashboard.vue';
import GeneralForm from 'src/pages/GeneralForm.vue';
import GetStarted from 'src/pages/GetStarted.vue';
import ImportWizard from 'src/pages/ImportWizard.vue';
import InvoiceForm from 'src/pages/InvoiceForm.vue';
@ -15,36 +14,13 @@ import {
createRouter,
createWebHistory,
RouteLocationRaw,
RouteRecordRaw
RouteRecordRaw,
} from 'vue-router';
function getGeneralFormItems(): RouteRecordRaw[] {
return [ModelNameEnum.Shipment, ModelNameEnum.PurchaseReceipt].map(
(schemaName) => {
return {
path: `/edit/${schemaName}/:name`,
name: `${schemaName}Form`,
components: {
default: GeneralForm,
edit: QuickEditForm,
},
props: {
default: (route) => {
route.params.schemaName = schemaName;
return {
schemaName,
name: route.params.name,
};
},
edit: (route) => route.query,
},
};
}
);
}
function getCommonFormItems(): RouteRecordRaw[] {
return [
ModelNameEnum.Shipment,
ModelNameEnum.PurchaseReceipt,
ModelNameEnum.JournalEntry,
ModelNameEnum.Payment,
ModelNameEnum.StockMovement,
@ -80,7 +56,6 @@ const routes: RouteRecordRaw[] = [
path: '/get-started',
component: GetStarted,
},
...getGeneralFormItems(),
...getCommonFormItems(),
{
path: '/edit/:schemaName/:name',