mirror of
https://github.com/frappe/books.git
synced 2025-01-03 07:12:21 +00:00
incr: change inventory enable trigger
This commit is contained in:
parent
1d61a870a5
commit
332bf93a1e
@ -4,7 +4,7 @@ import {
|
||||
FiltersMap,
|
||||
ListsMap,
|
||||
ReadOnlyMap,
|
||||
ValidationMap
|
||||
ValidationMap,
|
||||
} from 'fyo/model/types';
|
||||
import { validateEmail } from 'fyo/model/validationFunction';
|
||||
import { createDiscountAccount } from 'src/setup/setupInstance';
|
||||
@ -12,6 +12,8 @@ import { getCountryInfo } from 'utils/misc';
|
||||
|
||||
export class AccountingSettings extends Doc {
|
||||
enableDiscounting?: boolean;
|
||||
enableInventory?: boolean;
|
||||
|
||||
static filters: FiltersMap = {
|
||||
writeOffAccount: () => ({
|
||||
isGroup: false,
|
||||
@ -39,6 +41,9 @@ export class AccountingSettings extends Doc {
|
||||
enableDiscounting: () => {
|
||||
return !!this.enableDiscounting;
|
||||
},
|
||||
enableInventory: () => {
|
||||
return !!this.enableInventory;
|
||||
},
|
||||
};
|
||||
|
||||
async change(ch: ChangeArg) {
|
||||
|
@ -44,7 +44,7 @@ export class Defaults extends Doc {
|
||||
static createFilters: FiltersMap = this.commonFilters;
|
||||
|
||||
getInventoryHidden() {
|
||||
return () => !this.fyo.store.appFlags.isInventoryEnabled;
|
||||
return () => !this.fyo.singles.AccountingSettings?.enableInventory;
|
||||
}
|
||||
|
||||
hidden: HiddenMap = {
|
||||
|
@ -114,7 +114,9 @@ export class Item extends Doc {
|
||||
|
||||
hidden: HiddenMap = {
|
||||
trackItem: () =>
|
||||
this.itemType !== 'Product' || (this.inserted && !this.trackItem),
|
||||
!this.fyo.singles.AccountingSettings?.enableInventory ||
|
||||
this.itemType !== 'Product' ||
|
||||
(this.inserted && !this.trackItem),
|
||||
};
|
||||
|
||||
readOnly: ReadOnlyMap = {
|
||||
|
@ -282,7 +282,7 @@ export class GeneralLedger extends LedgerReport {
|
||||
{ label: t`Journal Entries`, value: 'JournalEntry' },
|
||||
];
|
||||
|
||||
if (this.fyo.store.appFlags.isInventoryEnabled) {
|
||||
if (!this.fyo.singles.AccountingSettings?.enableInventory) {
|
||||
refTypeOptions.push(
|
||||
{ label: t`Shipment`, value: 'Shipment' },
|
||||
{ label: t`Purchase Receipt`, value: 'PurchaseReceipt' }
|
||||
|
@ -70,11 +70,17 @@
|
||||
"default": false
|
||||
},
|
||||
{
|
||||
"label": "Discount Account",
|
||||
"fieldname": "discountAccount",
|
||||
"label": "Discount Account",
|
||||
"fieldtype": "Link",
|
||||
"target": "Account"
|
||||
},
|
||||
{
|
||||
"fieldname": "enableInventory",
|
||||
"label": "Enable Inventory",
|
||||
"fieldtype": "Check",
|
||||
"default": false
|
||||
},
|
||||
{
|
||||
"fieldname": "setupComplete",
|
||||
"label": "Setup Complete",
|
||||
|
@ -65,6 +65,8 @@ export default {
|
||||
FormContainer,
|
||||
},
|
||||
data() {
|
||||
const hasInventory = !!fyo.singles.AccountingSettings?.enableInventory;
|
||||
|
||||
return {
|
||||
activeTab: 0,
|
||||
updated: false,
|
||||
@ -88,12 +90,16 @@ export default {
|
||||
schemaName: 'Defaults',
|
||||
component: markRaw(TabBase),
|
||||
},
|
||||
{
|
||||
key: 'Inventory',
|
||||
label: t`Inventory`,
|
||||
schemaName: 'InventorySettings',
|
||||
component: markRaw(TabBase),
|
||||
},
|
||||
...(hasInventory
|
||||
? [
|
||||
{
|
||||
key: 'Inventory',
|
||||
label: t`Inventory`,
|
||||
schemaName: 'InventorySettings',
|
||||
component: markRaw(TabBase),
|
||||
},
|
||||
]
|
||||
: []),
|
||||
{
|
||||
key: 'System',
|
||||
label: t`System`,
|
||||
@ -118,7 +124,8 @@ export default {
|
||||
fieldnames.includes('displayPrecision') ||
|
||||
fieldnames.includes('hideGetStarted') ||
|
||||
fieldnames.includes('displayPrecision') ||
|
||||
fieldnames.includes('enableDiscounting')
|
||||
fieldnames.includes('enableDiscounting') ||
|
||||
fieldnames.includes('enableInventory')
|
||||
) {
|
||||
this.showReloadToast();
|
||||
}
|
||||
|
@ -34,6 +34,10 @@ export default defineComponent({
|
||||
fields.push('enableDiscounting');
|
||||
}
|
||||
|
||||
if (!this.doc?.enableInventory) {
|
||||
fields.push('enableInventory');
|
||||
}
|
||||
|
||||
if (this.doc?.enableDiscounting) {
|
||||
fields.push('discountAccount');
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ import { ConfigFile, ConfigKeys } from 'fyo/core/types';
|
||||
import { getRegionalModels, models } from 'models/index';
|
||||
import { ModelNameEnum } from 'models/types';
|
||||
import { getRandomString, getValueMapFromList } from 'utils/index';
|
||||
import { getIsInventoryEnabled } from './misc';
|
||||
|
||||
export async function initializeInstance(
|
||||
dbPath: string,
|
||||
@ -28,11 +27,6 @@ export async function initializeInstance(
|
||||
await setInstanceId(fyo);
|
||||
await setOpenCount(fyo);
|
||||
await setCurrencySymbols(fyo);
|
||||
await setAppFlags(fyo);
|
||||
}
|
||||
|
||||
async function setAppFlags(fyo: Fyo) {
|
||||
fyo.store.appFlags.isInventoryEnabled = await getIsInventoryEnabled(fyo);
|
||||
}
|
||||
|
||||
async function closeDbIfConnected(fyo: Fyo) {
|
||||
|
@ -129,12 +129,3 @@ export async function convertFileToDataURL(file: File, type: string) {
|
||||
const array = new Uint8Array(buffer);
|
||||
return await getDataURL(type, array);
|
||||
}
|
||||
|
||||
export async function getIsInventoryEnabled(fyo: Fyo) {
|
||||
const values = await fyo.db.getAllRaw('Item', {
|
||||
fields: ['name'],
|
||||
filters: { trackItem: true },
|
||||
});
|
||||
|
||||
return !!values.length;
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ async function openFormEditDoc(schemaName: string, fyo: Fyo) {
|
||||
}
|
||||
|
||||
function getCreateList(fyo: Fyo): SearchItem[] {
|
||||
const hasInventory = fyo.store.appFlags.isInventoryEnabled;
|
||||
const hasInventory = fyo.doc.singles.AccountingSettings?.enableInventory;
|
||||
const quickEditCreateList = [
|
||||
ModelNameEnum.Item,
|
||||
ModelNameEnum.Party,
|
||||
@ -176,7 +176,7 @@ function getCreateList(fyo: Fyo): SearchItem[] {
|
||||
|
||||
function getReportList(fyo: Fyo): SearchItem[] {
|
||||
const hasGstin = !!fyo.singles?.AccountingSettings?.gstin;
|
||||
const hasInventory = fyo.store.appFlags.isInventoryEnabled;
|
||||
const hasInventory = !!fyo.singles?.AccountingSettings?.enableInventory;
|
||||
return Object.keys(reports)
|
||||
.filter((r) => {
|
||||
const report = reports[r];
|
||||
@ -210,7 +210,8 @@ function getListViewList(fyo: Fyo): SearchItem[] {
|
||||
ModelNameEnum.Tax,
|
||||
];
|
||||
|
||||
if (fyo.store.appFlags.isInventoryEnabled) {
|
||||
const hasInventory = fyo.doc.singles.AccountingSettings?.enableInventory;
|
||||
if (hasInventory) {
|
||||
schemaNames.push(
|
||||
ModelNameEnum.StockMovement,
|
||||
ModelNameEnum.Shipment,
|
||||
|
@ -1,6 +1,5 @@
|
||||
import { t } from 'fyo';
|
||||
import { fyo } from '../initFyo';
|
||||
import { getIsInventoryEnabled } from './misc';
|
||||
import { SidebarConfig, SidebarRoot } from './types';
|
||||
|
||||
export async function getSidebarConfig(): Promise<SidebarConfig> {
|
||||
@ -55,8 +54,8 @@ function getRegionalSidebar(): SidebarRoot[] {
|
||||
}
|
||||
|
||||
async function getInventorySidebar(): Promise<SidebarRoot[]> {
|
||||
const showInventory = await getIsInventoryEnabled(fyo);
|
||||
if (!showInventory) {
|
||||
const hasInventory = !!fyo.singles.AccountingSettings?.enableInventory;
|
||||
if (!hasInventory) {
|
||||
return [];
|
||||
}
|
||||
|
||||
@ -121,7 +120,8 @@ async function getReportSidebar() {
|
||||
],
|
||||
};
|
||||
|
||||
if (await getIsInventoryEnabled(fyo)) {
|
||||
const hasInventory = !!fyo.singles.AccountingSettings?.enableInventory;
|
||||
if (hasInventory) {
|
||||
reports.items.push(
|
||||
{
|
||||
label: t`Stock Ledger`,
|
||||
|
Loading…
Reference in New Issue
Block a user