mirror of
https://github.com/frappe/books.git
synced 2025-01-03 15:17:30 +00:00
feat: validate serial number count in row
This commit is contained in:
parent
23f9fc97d6
commit
f86275da86
@ -232,10 +232,7 @@
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div
|
<div v-if="hasSerialNumber" class="px-2 pt-8 col-span-2">
|
||||||
v-if="row.links?.item && row.links?.item.hasSerialNumber"
|
|
||||||
class="px-2 pt-8 col-span-2"
|
|
||||||
>
|
|
||||||
<Text
|
<Text
|
||||||
:df="{
|
:df="{
|
||||||
label: t`Serial Number`,
|
label: t`Serial Number`,
|
||||||
@ -245,6 +242,7 @@
|
|||||||
:value="row.serialNumber"
|
:value="row.serialNumber"
|
||||||
:show-label="true"
|
:show-label="true"
|
||||||
:border="true"
|
:border="true"
|
||||||
|
:required="hasSerialNumber"
|
||||||
@change="(value:string)=> setSerialNumber(value)"
|
@change="(value:string)=> setSerialNumber(value)"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@ -264,6 +262,8 @@ import { defineComponent } from 'vue';
|
|||||||
import { SalesInvoiceItem } from 'models/baseModels/SalesInvoiceItem/SalesInvoiceItem';
|
import { SalesInvoiceItem } from 'models/baseModels/SalesInvoiceItem/SalesInvoiceItem';
|
||||||
import { Money } from 'pesa';
|
import { Money } from 'pesa';
|
||||||
import { DiscountType } from './types';
|
import { DiscountType } from './types';
|
||||||
|
import { t } from 'fyo';
|
||||||
|
import { validateSerialNumberCount } from 'src/utils/pos';
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: 'SelectedItemRow',
|
name: 'SelectedItemRow',
|
||||||
@ -293,6 +293,9 @@ export default defineComponent({
|
|||||||
isUOMConversionEnabled(): boolean {
|
isUOMConversionEnabled(): boolean {
|
||||||
return !!fyo.singles.InventorySettings?.enableUomConversions;
|
return !!fyo.singles.InventorySettings?.enableUomConversions;
|
||||||
},
|
},
|
||||||
|
hasSerialNumber(): boolean {
|
||||||
|
return !!(this.row.links?.item && this.row.links?.item.hasSerialNumber);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
async getAvailableQtyInBatch(): Promise<number> {
|
async getAvailableQtyInBatch(): Promise<number> {
|
||||||
@ -318,8 +321,13 @@ export default defineComponent({
|
|||||||
if (!serialNumber) {
|
if (!serialNumber) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.itemSerialNumbers[this.row.item as string] = serialNumber;
|
this.itemSerialNumbers[this.row.item as string] = serialNumber;
|
||||||
|
|
||||||
|
validateSerialNumberCount(
|
||||||
|
serialNumber,
|
||||||
|
this.row.quantity ?? 0,
|
||||||
|
this.row.item!
|
||||||
|
);
|
||||||
},
|
},
|
||||||
setItemDiscount(type: DiscountType, value: Money | number) {
|
setItemDiscount(type: DiscountType, value: Money | number) {
|
||||||
if (type === 'percent') {
|
if (type === 'percent') {
|
||||||
|
@ -257,3 +257,26 @@ export async function transferPOSCashAndWriteOff(
|
|||||||
|
|
||||||
await (await jvDoc.sync()).submit();
|
await (await jvDoc.sync()).submit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function validateSerialNumberCount(
|
||||||
|
serialNumbers: string | undefined,
|
||||||
|
quantity: number,
|
||||||
|
item: string
|
||||||
|
) {
|
||||||
|
let serialNumberCount = 0;
|
||||||
|
|
||||||
|
if (serialNumbers) {
|
||||||
|
serialNumberCount = serialNumbers.split('\n').length;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (quantity !== serialNumberCount) {
|
||||||
|
const errorMessage = t`Need ${quantity} Serial Numbers for Item ${item}. You have provided ${serialNumberCount}`;
|
||||||
|
|
||||||
|
showToast({
|
||||||
|
type: 'error',
|
||||||
|
message: errorMessage,
|
||||||
|
duration: 'long',
|
||||||
|
});
|
||||||
|
throw new ValidationError(errorMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user