2
0
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:
akshayitzme 2023-09-25 12:10:41 +05:30 committed by akshayitzme
parent 23f9fc97d6
commit f86275da86
2 changed files with 36 additions and 5 deletions

View File

@ -232,10 +232,7 @@
/>
</div>
<div
v-if="row.links?.item && row.links?.item.hasSerialNumber"
class="px-2 pt-8 col-span-2"
>
<div v-if="hasSerialNumber" class="px-2 pt-8 col-span-2">
<Text
:df="{
label: t`Serial Number`,
@ -245,6 +242,7 @@
:value="row.serialNumber"
:show-label="true"
:border="true"
:required="hasSerialNumber"
@change="(value:string)=> setSerialNumber(value)"
/>
</div>
@ -264,6 +262,8 @@ import { defineComponent } from 'vue';
import { SalesInvoiceItem } from 'models/baseModels/SalesInvoiceItem/SalesInvoiceItem';
import { Money } from 'pesa';
import { DiscountType } from './types';
import { t } from 'fyo';
import { validateSerialNumberCount } from 'src/utils/pos';
export default defineComponent({
name: 'SelectedItemRow',
@ -293,6 +293,9 @@ export default defineComponent({
isUOMConversionEnabled(): boolean {
return !!fyo.singles.InventorySettings?.enableUomConversions;
},
hasSerialNumber(): boolean {
return !!(this.row.links?.item && this.row.links?.item.hasSerialNumber);
},
},
methods: {
async getAvailableQtyInBatch(): Promise<number> {
@ -318,8 +321,13 @@ export default defineComponent({
if (!serialNumber) {
return;
}
this.itemSerialNumbers[this.row.item as string] = serialNumber;
validateSerialNumberCount(
serialNumber,
this.row.quantity ?? 0,
this.row.item!
);
},
setItemDiscount(type: DiscountType, value: Money | number) {
if (type === 'percent') {

View File

@ -257,3 +257,26 @@ export async function transferPOSCashAndWriteOff(
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);
}
}