mirror of
https://github.com/frappe/books.git
synced 2026-08-24 02:24:17 -05:00
fix: return batch quantity resetting
This commit is contained in:
@@ -770,6 +770,9 @@ export abstract class Invoice extends Transactional {
|
||||
...docItem,
|
||||
name: undefined,
|
||||
quantity: -(totalQtyOfReturnedItems[docItem.item as string] || 0),
|
||||
qty:
|
||||
-(totalQtyOfReturnedItems[docItem.item as string] as number) /
|
||||
(item.unitConversionFactor as number),
|
||||
transferQuantity: -(
|
||||
(totalQtyOfReturnedItems[docItem.item as string] as number) /
|
||||
(item.unitConversionFactor as number)
|
||||
@@ -835,6 +838,7 @@ export abstract class Invoice extends Transactional {
|
||||
serialNumber,
|
||||
name: undefined,
|
||||
quantity: quantity,
|
||||
qty: transferQuantity,
|
||||
transferQuantity,
|
||||
});
|
||||
}
|
||||
@@ -1611,6 +1615,20 @@ 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,9 +118,13 @@ export class SalesInvoice extends Invoice {
|
||||
today.setHours(0, 0, 0, 0);
|
||||
|
||||
if (toDate && new Date(toDate).getTime() < today.getTime()) {
|
||||
throw new ValidationError(
|
||||
t`Loyalty program has expired and cannot be applied`
|
||||
);
|
||||
const { showToast } = await import('src/utils/interactive');
|
||||
showToast({
|
||||
type: 'warning',
|
||||
message: t`Loyalty program has expired and cannot be applied`,
|
||||
duration: 'short',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this?.grandTotal) {
|
||||
|
||||
+14
-11
@@ -1632,20 +1632,18 @@ export async function validateLoyaltyProgram(
|
||||
filters: { name: loyaltyProgramName },
|
||||
});
|
||||
|
||||
if (!loyaltyProgram[0]?.isEnabled) {
|
||||
throw new ValidationError(
|
||||
'Loyalty program cannot be applied as it is not enabled'
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
(loyaltyProgram[0]?.maximumUse as number) > 0 &&
|
||||
(loyaltyProgram[0]?.used as number) >=
|
||||
(loyaltyProgram[0]?.maximumUse as number)
|
||||
) {
|
||||
throw new ValidationError(
|
||||
'Loyalty program has reached maximum usage limit'
|
||||
);
|
||||
const { showToast } = await import('src/utils/interactive');
|
||||
showToast({
|
||||
type: 'warning',
|
||||
message: t`Loyalty program has reached maximum usage`,
|
||||
duration: 'short',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
@@ -1662,9 +1660,14 @@ export async function validateLoyaltyProgram(
|
||||
const normalizedToDate = new Date(toDate);
|
||||
normalizedToDate.setHours(0, 0, 0, 0);
|
||||
|
||||
// Only throw error if toDate is clearly in the past
|
||||
if (normalizedToDate.getTime() < today.getTime()) {
|
||||
throw new ValidationError('Loyalty program has expired');
|
||||
const { showToast } = await import('src/utils/interactive');
|
||||
showToast({
|
||||
type: 'warning',
|
||||
message: t`Loyalty program has expired`,
|
||||
duration: 'short',
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user