Fixed daqi being enforced on REPAIR

This commit is contained in:
SepehrYahyaee
2026-09-05 18:42:07 +03:30
parent e48dffef89
commit 233a16d96c
6 changed files with 107 additions and 26 deletions

View File

@@ -33,6 +33,20 @@ describe("getExpertReplyPricingValidationError", () => {
).toBeNull();
});
it("accepts a repair line without daghi", () => {
expect(
getExpertReplyPricingValidationError([
{
partId: 201,
typeOfDamage: TypeOfDamage.Repair,
price: "10000",
salary: "0",
totalPayment: "10000",
},
]),
).toBeNull();
});
it("rejects a repair line without a price", () => {
expect(
getExpertReplyPricingValidationError([

View File

@@ -42,9 +42,11 @@ export function getExpertReplyPricingValidationError(
return `${label} requires typeOfDamage to be either '${TypeOfDamage.Repair}' or '${TypeOfDamage.Change}'.`;
}
const daghi = part.daghi;
if (
!part.daghi ||
!Object.values(DaghiOption).includes(part.daghi.option as DaghiOption)
part.typeOfDamage === TypeOfDamage.Change &&
(!daghi ||
!Object.values(DaghiOption).includes(daghi.option as DaghiOption))
) {
return `${label} requires a valid daghi option.`;
}
@@ -52,7 +54,7 @@ export function getExpertReplyPricingValidationError(
const price = parseMoneyAmountToman(part.price);
const salary = parseMoneyAmountToman(part.salary);
const totalPayment = parseMoneyAmountToman(part.totalPayment);
const daghiPrice = parseMoneyAmountToman(part.daghi.price);
const daghiPrice = parseMoneyAmountToman(daghi?.price);
const hasPrice =
part.price != null &&
(typeof part.price !== "string" || part.price.trim() !== "");
@@ -80,7 +82,7 @@ export function getExpertReplyPricingValidationError(
}
if (
part.daghi.option === DaghiOption.RECYCLED_PARTS_VALUE &&
daghi?.option === DaghiOption.RECYCLED_PARTS_VALUE &&
(daghiPrice === null ||
daghiPrice < REPAIR_LINE_AMOUNT_TOMAN.MIN ||
daghiPrice > REPAIR_LINE_AMOUNT_TOMAN.MAX)