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

incr: update dynamic hidden

- delete unused settings tab files
This commit is contained in:
18alantom 2023-03-01 13:43:04 +05:30
parent 09f194badc
commit e1920bd55e
8 changed files with 21 additions and 270 deletions

View File

@ -2,6 +2,7 @@ import { Doc } from 'fyo/model/doc';
import {
ChangeArg,
FiltersMap,
HiddenMap,
ListsMap,
ReadOnlyMap,
ValidationMap,
@ -46,6 +47,11 @@ export class AccountingSettings extends Doc {
},
};
override hidden: HiddenMap = {
discountAccount: () => !this.enableDiscounting,
gstin: () => this.fyo.singles.SystemSettings?.countryCode !== 'in',
};
async change(ch: ChangeArg) {
const discountingEnabled =
ch.changed === 'enableDiscounting' && this.enableDiscounting;

View File

@ -0,0 +1,8 @@
import { Doc } from 'fyo/model/doc';
import { HiddenMap } from 'fyo/model/types';
export class PrintSettings extends Doc {
override hidden: HiddenMap = {
displayBatch: () => !this.fyo.singles.InventorySettings?.enableBatches,
};
}

View File

@ -10,6 +10,7 @@ import { JournalEntryAccount } from './baseModels/JournalEntryAccount/JournalEnt
import { Party } from './baseModels/Party/Party';
import { Payment } from './baseModels/Payment/Payment';
import { PaymentFor } from './baseModels/PaymentFor/PaymentFor';
import { PrintSettings } from './baseModels/PrintSettings/PrintSettings';
import { PurchaseInvoice } from './baseModels/PurchaseInvoice/PurchaseInvoice';
import { PurchaseInvoiceItem } from './baseModels/PurchaseInvoiceItem/PurchaseInvoiceItem';
import { SalesInvoice } from './baseModels/SalesInvoice/SalesInvoice';
@ -17,6 +18,7 @@ import { SalesInvoiceItem } from './baseModels/SalesInvoiceItem/SalesInvoiceItem
import { SetupWizard } from './baseModels/SetupWizard/SetupWizard';
import { Tax } from './baseModels/Tax/Tax';
import { TaxSummary } from './baseModels/TaxSummary/TaxSummary';
import { Batch } from './inventory/Batch';
import { InventorySettings } from './inventory/InventorySettings';
import { Location } from './inventory/Location';
import { PurchaseReceipt } from './inventory/PurchaseReceipt';
@ -26,7 +28,6 @@ import { ShipmentItem } from './inventory/ShipmentItem';
import { StockLedgerEntry } from './inventory/StockLedgerEntry';
import { StockMovement } from './inventory/StockMovement';
import { StockMovementItem } from './inventory/StockMovementItem';
import { Batch } from './inventory/Batch';
export const models = {
Account,
@ -41,6 +42,7 @@ export const models = {
Party,
Payment,
PaymentFor,
PrintSettings,
PurchaseInvoice,
PurchaseInvoiceItem,
SalesInvoice,

View File

@ -18,8 +18,10 @@
<div
v-for="field of fields"
:key="field.fieldname"
:class="field.fieldtype === 'Table' ? 'col-span-2 text-base' : ''"
class="mb-auto"
:class="[
field.fieldtype === 'Table' ? 'col-span-2 text-base' : '',
field.fieldtype === 'Check' ? 'mt-auto' : 'mb-auto',
]"
>
<FormControl
:ref="field.fieldname === 'name' ? 'nameField' : 'fields'"

View File

@ -1,59 +0,0 @@
<template>
<div>
<TwoColumnForm
v-if="doc"
:doc="doc"
:fields="fields"
:autosave="true"
:emit-change="true"
@change="(...args:unknown[])=>$emit('change', ...args)"
/>
</div>
</template>
<script lang="ts">
import { Doc } from 'fyo/model/doc';
import TwoColumnForm from 'src/components/TwoColumnForm.vue';
import { defineComponent } from 'vue';
export default defineComponent({
name: 'TabGeneral',
emits: ['change'],
props: { schemaName: String },
components: {
TwoColumnForm,
},
async mounted() {
await this.setDoc();
},
watch: {
async schemaName() {
await this.setDoc();
},
},
methods: {
async setDoc() {
if (this.doc && this.schemaName === this.doc.schemaName) {
return;
}
if (!this.schemaName) {
return;
}
this.doc = await this.fyo.doc.getDoc(this.schemaName, this.schemaName, {
skipDocumentCache: true,
});
},
},
data() {
return {
doc: undefined,
} as { doc?: Doc };
},
computed: {
fields() {
return this.doc?.schema.fields;
},
},
});
</script>

View File

@ -1,49 +0,0 @@
<script lang="ts">
import { Field } from 'schemas/types';
import { fyo } from 'src/initFyo';
import { defineComponent } from 'vue';
import TabBase from './TabBase.vue';
export default defineComponent({
extends: TabBase,
name: 'TabGeneral',
async mounted() {
this.doc = await fyo.doc.getDoc(
'AccountingSettings',
'AccountingSettings',
{
skipDocumentCache: true,
}
);
},
computed: {
fields() {
const fields = [
'fullname',
'companyName',
'country',
'bankName',
'currency',
'fiscalYearStart',
'fiscalYearEnd',
'writeOffAccount',
'roundOffAccount',
'enableDiscounting',
'enableInventory',
];
if (this.doc?.enableDiscounting) {
fields.push('discountAccount');
}
if (fyo.singles.SystemSettings?.countryCode === 'in') {
fields.push('gstin');
}
return fields
.map((fieldname) => fyo.getField('AccountingSettings', fieldname))
.filter(Boolean) as Field[];
},
},
});
</script>

View File

@ -1,101 +0,0 @@
<template>
<div v-if="doc" class="pb-4">
<hr />
<div class="flex items-center gap-4 p-4">
<FormControl
:df="getField('logo')"
:value="doc.logo"
@change="
(value) => {
doc.setAndSync('logo', value);
forwardChangeEvent(getField('logo'));
}
"
/>
<div class="flex flex-col">
<span
class="bg-transparent font-semibold text-xl text-gray-900 px-3 py-2"
>
{{ companyName }}
</span>
<span class="text-lg text-gray-800 px-3 py-2">
{{ doc.email }}
</span>
</div>
</div>
<TwoColumnForm
:doc="doc"
:fields="fields"
:autosave="true"
:emit-change="true"
@change="forwardChangeEvent"
/>
</div>
</template>
<script>
import { ipcRenderer } from 'electron';
import TwoColumnForm from 'src/components/TwoColumnForm.vue';
import { fyo } from 'src/initFyo';
import { IPC_ACTIONS } from 'utils/messages';
import FormControl from '../../components/Controls/FormControl.vue';
export default {
name: 'TabInvoice',
components: {
TwoColumnForm,
FormControl,
},
emits: ['change'],
provide() {
return {
schemaName: 'PrintSettings',
name: 'PrintSettings',
};
},
data() {
return {
companyName: null,
doc: null,
showEdit: false,
};
},
async mounted() {
this.doc = await fyo.doc.getDoc('PrintSettings');
this.companyName = (await fyo.doc.getDoc('AccountingSettings')).companyName;
},
computed: {
fields() {
const fields = ['template', 'color', 'font', 'email', 'phone', 'address'];
if (this.doc.logo) {
fields.unshift('displayLogo');
}
return fields.map((field) => this.getField(field));
},
},
methods: {
getField(fieldname) {
return fyo.getField('PrintSettings', fieldname);
},
async openFileSelector() {
const options = {
title: t`Select Logo`,
properties: ['openFile'],
filters: [{ name: 'Invoice Logo', extensions: ['png', 'jpg', 'svg'] }],
};
const { filePaths } = await ipcRenderer.invoke(
IPC_ACTIONS.GET_OPEN_FILEPATH,
options
);
if (filePaths[0] !== undefined) {
this.doc.set('logo', `file://${files[0]}`);
this.doc.update;
}
},
forwardChangeEvent(...args) {
this.$emit('change', ...args);
},
},
};
</script>

View File

@ -1,58 +0,0 @@
<template>
<div class="flex flex-col justify-between h-full">
<TwoColumnForm
v-if="doc"
:doc="doc"
:fields="fields"
:autosave="true"
:emit-change="true"
@change="forwardChangeEvent"
/>
<div class="flex p-4 justify-between">
<LanguageSelector class="text-sm w-28" />
<p class="mt-auto text-gray-600 text-base select-none">
{{ `v${fyo.store.appVersion}` }}
</p>
</div>
</div>
</template>
<script>
import { ConfigKeys } from 'fyo/core/types';
import { ModelNameEnum } from 'models/types';
import LanguageSelector from 'src/components/Controls/LanguageSelector.vue';
import TwoColumnForm from 'src/components/TwoColumnForm';
import { fyo } from 'src/initFyo';
export default {
name: 'TabSystem',
components: {
TwoColumnForm,
LanguageSelector,
},
emits: ['change'],
data() {
return {
doc: null,
telemetry: '',
};
},
async mounted() {
this.doc = fyo.singles.SystemSettings;
this.companyName = fyo.singles.AccountingSettings.companyName;
this.telemetry = fyo.config.get(ConfigKeys.Telemetry);
},
computed: {
fields() {
return fyo.schemaMap.SystemSettings.quickEditFields.map((f) =>
fyo.getField(ModelNameEnum.SystemSettings, f)
);
},
},
methods: {
forwardChangeEvent(...args) {
this.$emit('change', ...args);
},
},
};
</script>