mirror of
https://github.com/frappe/books.git
synced 2024-11-12 16:36:27 +00:00
fix: add item triggering multiple times
This commit is contained in:
parent
c483c4bf73
commit
3bbf5294c9
@ -83,7 +83,7 @@ export default defineComponent({
|
|||||||
tableFields() {
|
tableFields() {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
fieldname: 'item',
|
fieldname: 'name',
|
||||||
fieldtype: 'Data',
|
fieldtype: 'Data',
|
||||||
label: 'Item',
|
label: 'Item',
|
||||||
placeholder: 'Item',
|
placeholder: 'Item',
|
||||||
@ -145,7 +145,7 @@ export default defineComponent({
|
|||||||
|
|
||||||
this.items.push({
|
this.items.push({
|
||||||
availableQty,
|
availableQty,
|
||||||
item: item.name,
|
name: item.name,
|
||||||
rate: item.rate as Money,
|
rate: item.rate as Money,
|
||||||
unit: item.unit as string,
|
unit: item.unit as string,
|
||||||
hasBatch: !!item.hasBatch,
|
hasBatch: !!item.hasBatch,
|
||||||
|
@ -11,7 +11,7 @@ export type DiscountType = "percent" | "amount";
|
|||||||
export type ModalName = 'ShiftOpen' | 'ShiftClose' | 'Payment'
|
export type ModalName = 'ShiftOpen' | 'ShiftClose' | 'Payment'
|
||||||
|
|
||||||
export interface POSItem {
|
export interface POSItem {
|
||||||
item: string,
|
name: string,
|
||||||
rate: Money,
|
rate: Money,
|
||||||
availableQty: number,
|
availableQty: number,
|
||||||
unit: string,
|
unit: string,
|
||||||
|
@ -43,8 +43,11 @@
|
|||||||
}"
|
}"
|
||||||
:border="true"
|
:border="true"
|
||||||
:class="['w-full']"
|
:class="['w-full']"
|
||||||
value=""
|
:value="itemSearchTerm"
|
||||||
@change="async (item) => (item ? addItem(getItem(item, 0)) : null)"
|
@keyup.enter="
|
||||||
|
async () => await addItem(await getItem(itemSearchTerm))
|
||||||
|
"
|
||||||
|
@change="(item: string) =>itemSearchTerm= item"
|
||||||
/>
|
/>
|
||||||
<ItemsTable @add-item="addItem" />
|
<ItemsTable @add-item="addItem" />
|
||||||
</div>
|
</div>
|
||||||
@ -168,10 +171,10 @@ import OpenPOSShiftModal from './OpenPOSShiftModal.vue';
|
|||||||
import PageHeader from 'src/components/PageHeader.vue';
|
import PageHeader from 'src/components/PageHeader.vue';
|
||||||
import PaymentModal from './PaymentModal.vue';
|
import PaymentModal from './PaymentModal.vue';
|
||||||
import SelectedItemTable from 'src/components/NeuPOS/SelectedItemTable.vue';
|
import SelectedItemTable from 'src/components/NeuPOS/SelectedItemTable.vue';
|
||||||
import { routeTo, toggleSidebar } from 'src/utils/ui';
|
|
||||||
import { fyo } from 'src/initFyo';
|
|
||||||
import { computed, defineComponent } from 'vue';
|
|
||||||
import { ValuationMethod } from 'models/inventory/types';
|
import { ValuationMethod } from 'models/inventory/types';
|
||||||
|
import { computed, defineComponent } from 'vue';
|
||||||
|
import { fyo } from 'src/initFyo';
|
||||||
|
import { routeTo, toggleSidebar } from 'src/utils/ui';
|
||||||
import {
|
import {
|
||||||
getRawStockLedgerEntries,
|
getRawStockLedgerEntries,
|
||||||
getStockBalanceEntries,
|
getStockBalanceEntries,
|
||||||
@ -179,13 +182,13 @@ import {
|
|||||||
} from 'reports/inventory/helpers';
|
} from 'reports/inventory/helpers';
|
||||||
import { ModelNameEnum } from 'models/types';
|
import { ModelNameEnum } from 'models/types';
|
||||||
import { SalesInvoice } from 'models/baseModels/SalesInvoice/SalesInvoice';
|
import { SalesInvoice } from 'models/baseModels/SalesInvoice/SalesInvoice';
|
||||||
import { getItem } from 'models/inventory/tests/helpers';
|
|
||||||
import { t } from 'fyo';
|
import { t } from 'fyo';
|
||||||
import {
|
import {
|
||||||
ItemQtyMap,
|
ItemQtyMap,
|
||||||
ItemSerialNumbers,
|
ItemSerialNumbers,
|
||||||
POSItem,
|
POSItem,
|
||||||
} from 'src/components/NeuPOS/types';
|
} from 'src/components/NeuPOS/types';
|
||||||
|
import { Item } from 'models/baseModels/Item/Item';
|
||||||
import { ModalName } from 'src/components/NeuPOS/types';
|
import { ModalName } from 'src/components/NeuPOS/types';
|
||||||
import { Money } from 'pesa';
|
import { Money } from 'pesa';
|
||||||
import { Payment } from 'models/baseModels/Payment/Payment';
|
import { Payment } from 'models/baseModels/Payment/Payment';
|
||||||
@ -235,6 +238,7 @@ export default defineComponent({
|
|||||||
|
|
||||||
defaultCustomer: undefined as string | undefined,
|
defaultCustomer: undefined as string | undefined,
|
||||||
transferRefNo: undefined as string | undefined,
|
transferRefNo: undefined as string | undefined,
|
||||||
|
itemSearchTerm: '',
|
||||||
|
|
||||||
transferClearanceDate: undefined as Date | undefined,
|
transferClearanceDate: undefined as Date | undefined,
|
||||||
|
|
||||||
@ -340,23 +344,31 @@ export default defineComponent({
|
|||||||
this.setTotalQuantity();
|
this.setTotalQuantity();
|
||||||
this.setItemDiscounts();
|
this.setItemDiscounts();
|
||||||
},
|
},
|
||||||
async addItem(item: POSItem) {
|
async getItem(item: string): Promise<Item | undefined> {
|
||||||
|
if (!item) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const itemDoc = (await fyo.doc.getDoc(ModelNameEnum.Item, item)) as Item;
|
||||||
|
if (!itemDoc) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return itemDoc;
|
||||||
|
},
|
||||||
|
async addItem(item: POSItem | Item | undefined) {
|
||||||
if (!item) {
|
if (!item) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.sinvDoc.runFormulas();
|
if (this.itemQtyMap[item.name as string].availableQty === 0) {
|
||||||
|
|
||||||
if (this.itemQtyMap[item.item].availableQty === 0) {
|
|
||||||
showToast({
|
showToast({
|
||||||
type: 'error',
|
type: 'error',
|
||||||
message: t`Item ${item.item} has Zero Quantity`,
|
message: t`Item ${item.name as string} has Zero Quantity`,
|
||||||
duration: 'short',
|
duration: 'short',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const existingItems =
|
const existingItems =
|
||||||
this.sinvDoc.items?.filter((item) => item.item === item.item) ?? [];
|
this.sinvDoc.items?.filter((item) => item.item === item.name) ?? [];
|
||||||
|
|
||||||
if (item.hasBatch) {
|
if (item.hasBatch) {
|
||||||
for (const item of existingItems) {
|
for (const item of existingItems) {
|
||||||
@ -372,9 +384,8 @@ export default defineComponent({
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await this.sinvDoc.append('items', {
|
await this.sinvDoc.append('items', {
|
||||||
...item,
|
rate: item.rate as Money,
|
||||||
item: item.item,
|
item: item.name,
|
||||||
name: undefined,
|
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
showToast({
|
showToast({
|
||||||
@ -391,9 +402,8 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
|
|
||||||
await this.sinvDoc.append('items', {
|
await this.sinvDoc.append('items', {
|
||||||
...item,
|
rate: item.rate as Money,
|
||||||
name: undefined,
|
item: item.name,
|
||||||
item: item.item,
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
setSinvDoc() {
|
setSinvDoc() {
|
||||||
@ -513,7 +523,6 @@ export default defineComponent({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getItem,
|
|
||||||
showToast,
|
showToast,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user