fix: resolve batch quantity mismatch during return

This commit is contained in:
Gadha2311
2026-02-24 12:40:40 +05:30
parent ae4664446a
commit f958e63f50
3 changed files with 30 additions and 38 deletions
+29 -20
View File
@@ -199,6 +199,23 @@ export abstract class Invoice extends Transactional {
if (this.isQuote) {
return;
}
if (!this.submitted && this.loyaltyProgram) {
const isExpiredOrMaxed = await isLoyaltyProgramExpiredAndMaxed(
this.fyo,
this.loyaltyProgram
);
if (isExpiredOrMaxed) {
const { showToast } = await import('src/utils/interactive');
showToast({
type: 'warning',
message: t`Loyalty program has expired or reached maximum usage`,
duration: 'short',
});
}
}
if (
this.enableDiscounting &&
!this.fyo.singles?.AccountingSettings?.discountAccount
@@ -759,14 +776,20 @@ export abstract class Invoice extends Transactional {
if (item.batch) {
const returnData = totalQtyOfReturnedItems[item.item as string];
if (typeof returnData === 'object' && returnData?.batches) {
returnDocItems = docItems.map((docItem) => ({
...docItem,
name: undefined,
quantity: -returnData?.batches![docItem.batch as string] || 0,
}));
returnDocItems = docItems.map((docItem: DocValueMap) => {
const qty = -returnData?.batches![docItem.batch as string] || 0;
const transferQty =
qty / ((docItem.unitConversionFactor as number) || 1);
return {
...docItem,
name: undefined,
quantity: qty,
transferQuantity: transferQty,
};
});
}
} else {
returnDocItems = docItems.map((docItem) => ({
returnDocItems = docItems.map((docItem: DocValueMap) => ({
...docItem,
name: undefined,
quantity: -(totalQtyOfReturnedItems[docItem.item as string] || 0),
@@ -1615,20 +1638,6 @@ export abstract class Invoice extends Transactional {
async beforeSync(): Promise<void> {
await super.beforeSync();
if (this.loyaltyProgram) {
const isExpiredOrMaxed = await isLoyaltyProgramExpiredAndMaxed(
this.fyo,
this.loyaltyProgram
);
if (isExpiredOrMaxed) {
const { showToast } = await import('src/utils/interactive');
showToast({
type: 'warning',
message: t`Loyalty program has expired or reached maximum usage`,
duration: 'short',
});
}
}
if (this.pricingRuleDetail?.length) {
await this.applyProductDiscount();
@@ -118,12 +118,6 @@ export class SalesInvoice extends Invoice {
today.setHours(0, 0, 0, 0);
if (toDate && new Date(toDate).getTime() < today.getTime()) {
const { showToast } = await import('src/utils/interactive');
showToast({
type: 'warning',
message: t`Loyalty program has expired and cannot be applied`,
duration: 'short',
});
return;
}
+1 -12
View File
@@ -1637,12 +1637,6 @@ export async function validateLoyaltyProgram(
(loyaltyProgram[0]?.used as number) >=
(loyaltyProgram[0]?.maximumUse as number)
) {
const { showToast } = await import('src/utils/interactive');
showToast({
type: 'warning',
message: t`Loyalty program has reached maximum usage`,
duration: 'short',
});
return;
}
@@ -1661,12 +1655,7 @@ export async function validateLoyaltyProgram(
normalizedToDate.setHours(0, 0, 0, 0);
if (normalizedToDate.getTime() < today.getTime()) {
const { showToast } = await import('src/utils/interactive');
showToast({
type: 'warning',
message: t`Loyalty program has expired`,
duration: 'short',
});
// Toast is already shown in beforeSync(), no need to duplicate
return;
}
}