Skip to content

Commit 5a8fe5f

Browse files
committed
fix: filter Item Visibility
1 parent ad85b47 commit 5a8fe5f

File tree

3 files changed

+48
-9
lines changed

3 files changed

+48
-9
lines changed

models/baseModels/InvoiceItem/InvoiceItem.ts

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@ import { Item } from '../Item/Item';
1919
import { StockTransfer } from 'models/inventory/StockTransfer';
2020
import { isPesa } from 'fyo/utils';
2121
import { PricingRule } from '../PricingRule/PricingRule';
22-
import {
23-
getItemRateFromPriceList,
24-
getItemVisibility,
25-
getPricingRule,
26-
} from 'models/helpers';
22+
import { getItemRateFromPriceList, getPricingRule } from 'models/helpers';
2723
import { SalesInvoice } from '../SalesInvoice/SalesInvoice';
2824
import { QueryFilter } from 'utils/db/types';
2925

@@ -635,7 +631,7 @@ export abstract class InvoiceItem extends Doc {
635631
};
636632

637633
static filters: FiltersMap = {
638-
item: async (doc: Doc) => {
634+
item: (doc: Doc) => {
639635
let itemNotFor = 'Sales';
640636
if (doc.isSales) {
641637
itemNotFor = 'Purchases';
@@ -645,13 +641,32 @@ export abstract class InvoiceItem extends Doc {
645641
for: ['not in', [itemNotFor]],
646642
};
647643

648-
const itemVisibility = await getItemVisibility(doc.fyo);
644+
const accountingSettings = doc.fyo.singles?.AccountingSettings;
645+
const inventorySettings = doc.fyo.singles?.InventorySettings;
646+
647+
if (accountingSettings?.enablePointOfSaleWithOutInventory) {
648+
const posSettings = doc.fyo.singles?.POSSettings;
649+
650+
const posItemVisibility = posSettings?.itemVisibility;
651+
652+
if (posItemVisibility === 'Inventory Items') {
653+
return { ...baseFilter, trackItem: true };
654+
}
655+
656+
if (posItemVisibility === 'Non-Inventory Items') {
657+
return { ...baseFilter, trackItem: false };
658+
}
659+
660+
return baseFilter;
661+
}
662+
663+
const invItemVisibility = inventorySettings?.itemVisibility;
649664

650-
if (itemVisibility === 'Inventory Items') {
665+
if (invItemVisibility === 'Inventory Items') {
651666
return { ...baseFilter, trackItem: true };
652667
}
653668

654-
if (itemVisibility === 'Non-Inventory Items') {
669+
if (invItemVisibility === 'Non-Inventory Items') {
655670
return { ...baseFilter, trackItem: false };
656671
}
657672

schemas/app/inventory/InventorySettings.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,24 @@
1212
"create": true,
1313
"section": "Default"
1414
},
15+
{
16+
"fieldname": "itemVisibility",
17+
"label": "Item Visibility",
18+
"fieldtype": "Select",
19+
"options": [
20+
{
21+
"value": "Inventory Items",
22+
"label": "Inventory Items"
23+
},
24+
{
25+
"value": "Non-Inventory Items",
26+
"label": "Non-Inventory Items"
27+
}
28+
],
29+
"default": "Non-Inventory Items",
30+
"required": true,
31+
"section": "Default"
32+
},
1533
{
1634
"fieldname": "stockInHand",
1735
"label": "Stock In Hand Acc.",

src/utils/ui.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,15 @@ function getDuplicateAction(doc: Doc): Action {
292292
}
293293

294294
function getNewAction(doc: Doc): Action {
295+
const isSubmittable = !!doc.schema.isSubmittable;
295296
return {
296297
label: t`New Entry`,
297298
group: t`Create`,
299+
condition: (doc: Doc) =>
300+
!!(
301+
((isSubmittable && doc.submitted) || !isSubmittable) &&
302+
!doc.notInserted
303+
),
298304
async action() {
299305
try {
300306
const newDoc = fyo.doc.getNewDoc(doc.schemaName);

0 commit comments

Comments
 (0)