fix(fanavaran): preserve assessed part ids in hull expertise

Use each saved expert-reply partId as AccessoryKindId and preserve its label. Resolve policy coverage separately so factory-bundle and caption matches cannot overwrite the selected part identity. Add coverage for the six-part expert reply and document the mapping.
This commit is contained in:
2026-11-21 14:45:31 +03:30
parent 7bff702514
commit 61ef4faaf4
5 changed files with 89 additions and 31 deletions
+2 -2
View File
@@ -152,9 +152,9 @@ Not ثالث GEN.08: no `DmgCaseId`, `InspectionPlaceId`, `RepairWage` on the ro
| AccidentPercent | درصد حادثه | number | yes | null | | AccidentPercent | درصد حادثه | number | yes | null |
| TheftCases | موارد سرقت | array | empty `[]` | system | | TheftCases | موارد سرقت | array | empty `[]` | system |
| DmgSections[].Count | تعداد | number | **no** | **system** `1` | | DmgSections[].Count | تعداد | number | **no** | **system** `1` |
| DmgSections[].Desc | شرح قطعه | string | **no** | **user** part label | | DmgSections[].Desc | شرح قطعه | string | **no** | Saved expert-reply part label (`carPartDamage.label_fa`) |
| DmgSections[].WasteValue | داغی ردیف | number | **no** | **user** | | DmgSections[].WasteValue | داغی ردیف | number | **no** | **user** |
| DmgSections[].AccessoryKindId | نوع قطعه کاتالوگ | number | preferred | **user** `partId` · lookup `car-components` | | DmgSections[].AccessoryKindId | نوع قطعه کاتالوگ | number | preferred | Saved `evaluation.damageExpertReply.parts[].partId`, passed through directly; policy matching and factory bundles must never replace it |
| DmgSections[].DmgKindId | نوع آسیب بدنه | number | **no** | Current `vehicle-hull-dmg-kind` API row caption تخریب; no numeric fallback | | DmgSections[].DmgKindId | نوع آسیب بدنه | number | **no** | Current `vehicle-hull-dmg-kind` API row caption تخریب; no numeric fallback |
| DmgSections[].VehicleHullAccessoryId | شناسه لوازم بدنه | number | preferred | Current policy `dmg-accessories`: exact `AccessoryKindId` or caption match; else the «کليه قطعات فابريک» factory-bundle row `Id`. Keep selected car-components `AccessoryKindId` + part `Desc` | | DmgSections[].VehicleHullAccessoryId | شناسه لوازم بدنه | number | preferred | Current policy `dmg-accessories`: exact `AccessoryKindId` or caption match; else the «کليه قطعات فابريک» factory-bundle row `Id`. Keep selected car-components `AccessoryKindId` + part `Desc` |
| DmgSections[].DmgSectionCosts[].Caption | عنوان هزینه | string | **no** | **user** label | | DmgSections[].DmgSectionCosts[].Caption | عنوان هزینه | string | **no** | **user** label |
@@ -214,7 +214,6 @@ import {
import { import {
FANAVARAN_HULL_DMG_COST_KIND_CAPTION, FANAVARAN_HULL_DMG_COST_KIND_CAPTION,
FANAVARAN_HULL_DMG_KIND_CAPTION, FANAVARAN_HULL_DMG_KIND_CAPTION,
findLookupCaptionById,
findLookupIdByCaption, findLookupIdByCaption,
findHullFactoryBundleAccessory, findHullFactoryBundleAccessory,
asHullDmgAccessoryRows, asHullDmgAccessoryRows,
@@ -2848,6 +2847,7 @@ export class ClaimRequestManagementService {
contractOptions, contractOptions,
) )
: Promise.resolve(null), : Promise.resolve(null),
// Validate saved part IDs against the catalogue without remapping them.
input.parts.length ? this.getFanavaranLookupRows(input.clientKey, 'car-components', true) : Promise.resolve([]), input.parts.length ? this.getFanavaranLookupRows(input.clientKey, 'car-components', true) : Promise.resolve([]),
]); ]);
@@ -2936,29 +2936,19 @@ export class ClaimRequestManagementService {
const factoryBundle = findHullFactoryBundleAccessory(accessories); const factoryBundle = findHullFactoryBundleAccessory(accessories);
const hullSections = input.parts.map((part: any, index: number) => { const hullSections = input.parts.map((part: any, index: number) => {
const partKindId = parseFanavaranId(part?.partId); const partKindId = parseFanavaranId(part?.partId);
// Prefer live car-components Caption so Desc matches the frontend catalogue. // The saved expert reply already identifies the selected catalogue part.
const catalogueCaption = findLookupCaptionById(componentRows, partKindId); const partLabel = this.fanavaranPartLabel(part);
const localLabel = this.fanavaranPartLabel(part);
const partLabel = catalogueCaption || localLabel;
const resolved = resolveHullDmgSectionAccessory( const resolved = resolveHullDmgSectionAccessory(
accessories, accessories,
partKindId, partKindId,
partLabel, partLabel,
); );
// No per-part policy row → cover under «کليه قطعات فابريک» Id (e.g. 3061139). // Policy coverage is resolved separately from the assessed part identity.
// Use the bundle's own AccessoryKindId (e.g. 112) so Fanavaran receives a
// coherent Id/AccessoryKindId pair from the policy row.
let vehicleHullAccessoryId = resolved?.vehicleHullAccessoryId ?? null; let vehicleHullAccessoryId = resolved?.vehicleHullAccessoryId ?? null;
let accessoryKindId: number | string | null | undefined =
resolved?.accessoryKindId ?? part?.partId;
if (!resolved && factoryBundle) { if (!resolved && factoryBundle) {
vehicleHullAccessoryId = factoryBundle.vehicleHullAccessoryId; vehicleHullAccessoryId = factoryBundle.vehicleHullAccessoryId;
// Replace the unrecognised per-part AccessoryKindId with the bundle's own
// kind (e.g. 112 = «کليه قطعات فابريک»). Fanavaran requires Id and
// AccessoryKindId to come from the same policy dmg-accessories row.
accessoryKindId = factoryBundle.accessoryKindId ?? accessoryKindId;
input.infoWarnings.push( input.infoWarnings.push(
`DmgSections[${index}] (${partLabel || part?.partId || 'part'}): AccessoryKindId=${part?.partId ?? '(missing)'} is a fabrique part (no separate policy row); mapped to factory bundle VehicleHullAccessoryId=${factoryBundle.vehicleHullAccessoryId} AccessoryKindId=${accessoryKindId} («کليه قطعات فابريک»).`, `DmgSections[${index}] (${partLabel || part?.partId || 'part'}): AccessoryKindId=${part?.partId ?? '(missing)'} is a fabrique part (no separate policy row); mapped to factory bundle VehicleHullAccessoryId=${factoryBundle.vehicleHullAccessoryId}; preserving AccessoryKindId=${partKindId} («کليه قطعات فابريک»).`,
); );
} else if (!resolved) { } else if (!resolved) {
input.warnings.push( input.warnings.push(
@@ -2966,7 +2956,7 @@ export class ClaimRequestManagementService {
); );
} }
return toFanavaranHullExpertiseDmgSection({ return toFanavaranHullExpertiseDmgSection({
partId: accessoryKindId, partId: partKindId,
desc: partLabel, desc: partLabel,
wasteValue: this.fanavaranDaghiWasteValue(part?.daghi), wasteValue: this.fanavaranDaghiWasteValue(part?.daghi),
amount: amount:
@@ -10,7 +10,7 @@ function setup(accessories: unknown) {
"vehicle-hull-dmg-cost-kinds": [ "vehicle-hull-dmg-cost-kinds": [
{ Id: 8002, Caption: "مجموع لوازم", IsActive: 1 }, { Id: 8002, Caption: "مجموع لوازم", IsActive: 1 },
], ],
"car-components": [{ Id: 9 }, { Id: 13 }, { Id: 112 }], "car-components": [9, 13, 112, 10, 48, 76, 29, 100, 37].map(Id => ({ Id })),
})[name] ?? [], })[name] ?? [],
); );
service.fanavaranLookupService = { service.fanavaranLookupService = {
@@ -19,16 +19,19 @@ function setup(accessories: unknown) {
.fn() .fn()
.mockResolvedValue(accessories), .mockResolvedValue(accessories),
}; };
const build = (policyId = 123) => const build = (
policyId = 123,
parts: any[] = [
{ partId: 9, partName: "سپر جلو", price: 50000000, salary: 25000000 },
{ partId: 13, partName: "چراغ جلو چپ", price: 0, salary: 2000000 },
],
) =>
service.buildCarBodyFanavaranExpertisePayload({ service.buildCarBodyFanavaranExpertisePayload({
clientKey: "parsian", clientKey: "parsian",
claimCase: { fanavaranSync: { baseClaim: { policyId } } }, claimCase: { fanavaranSync: { baseClaim: { policyId } } },
blame: { parties: [] }, blame: { parties: [] },
profile: {}, profile: {},
parts: [ parts,
{ partId: 9, partName: "سپر جلو", price: 50000000, salary: 25000000 },
{ partId: 13, partName: "چراغ جلو چپ", price: 0, salary: 2000000 },
],
claimExpertId: 4044, claimExpertId: 4044,
submittedAt: new Date("2026-11-11T09:09:00Z"), submittedAt: new Date("2026-11-11T09:09:00Z"),
priceDropTotal: 0, priceDropTotal: 0,
@@ -82,12 +85,14 @@ describe("hull expertise policy accessory mapping", () => {
payload.DmgSections.map((row: any) => row.VehicleHullAccessoryId), payload.DmgSections.map((row: any) => row.VehicleHullAccessoryId),
).toEqual([3061139, 3061139]); ).toEqual([3061139, 3061139]);
expect(payload.DmgSections.map((row: any) => row.AccessoryKindId)).toEqual([ expect(payload.DmgSections.map((row: any) => row.AccessoryKindId)).toEqual([
112, 112, 9, 13,
]); ]);
expect(warnings).toEqual([]); expect(warnings).toEqual([]);
expect(infoWarnings).toEqual( expect(infoWarnings).toEqual(
expect.arrayContaining([ expect.arrayContaining([
expect.stringContaining("mapped to factory bundle VehicleHullAccessoryId=3061139 AccessoryKindId=112"), expect.stringContaining(
"mapped to factory bundle VehicleHullAccessoryId=3061139; preserving AccessoryKindId=9",
),
]), ]),
); );
}); });
@@ -157,7 +162,7 @@ describe("hull expertise policy accessory mapping", () => {
}, },
); );
it("matches by part caption and keeps AccessoryKindId from that policy row", async () => { it("resolves the policy reference by caption without replacing the evaluated partId", async () => {
const { build } = setup([ const { build } = setup([
{ {
Id: 900010, Id: 900010,
@@ -168,9 +173,71 @@ describe("hull expertise policy accessory mapping", () => {
const { payload, warnings } = await build(); const { payload, warnings } = await build();
expect(payload.DmgSections[0]).toMatchObject({ expect(payload.DmgSections[0]).toMatchObject({
VehicleHullAccessoryId: 900010, VehicleHullAccessoryId: 900010,
AccessoryKindId: 44, AccessoryKindId: 9,
}); });
expect(payload.DmgSections[1].VehicleHullAccessoryId).toBeNull(); expect(payload.DmgSections[1].VehicleHullAccessoryId).toBeNull();
expect(warnings.some((w) => w.includes("چراغ جلو چپ"))).toBe(true); expect(warnings.some((w) => w.includes("چراغ جلو چپ"))).toBe(true);
}); });
it("preserves the six saved expert-reply part IDs under shared factory coverage", async () => {
const savedReplyParts = [
{
partId: 10,
carPartDamage: { id: 10, label_fa: "سپر عقب" },
typeOfDamage: "تعویض",
price: "150000000",
salary: "30000000",
daghi: { option: "ارزش لوازم بازیافتی", price: "20000000" },
},
{
partId: 48,
carPartDamage: { id: 48, label_fa: "درب صندوق عقب" },
typeOfDamage: "تعمیر",
salary: "80000000",
},
{
partId: 76,
carPartDamage: { id: 76, label_fa: "سيني عقب" },
typeOfDamage: "تعمیر",
salary: "70000000",
},
{
partId: 29,
carPartDamage: { id: 29, label_fa: "راهنماي عقب راست" },
typeOfDamage: "تعویض",
price: "95000000",
salary: "5000000",
},
{
partId: 100,
carPartDamage: { id: 100, label_fa: "سنسور دنده عقب" },
typeOfDamage: "تعویض",
price: "25000000",
salary: "5000000",
},
{
partId: 37,
carPartDamage: { id: 37, label_fa: "گلگير عقب سمت سرنشين" },
typeOfDamage: "تعمیر",
salary: "40000000",
},
];
const { build } = setup([
{ Id: 3092174, AccessoryKindId: 112, AccessoryDesc: "کليه قطعات فابريک" },
]);
const { payload, warnings } = await build(123, savedReplyParts);
expect(warnings).toEqual([]);
expect(payload.DmgSections.map((row: any) => row.AccessoryKindId)).toEqual([
10, 48, 76, 29, 100, 37,
]);
expect(
payload.DmgSections.map((row: any) => row.VehicleHullAccessoryId),
).toEqual(Array(6).fill(3092174));
expect(payload.DmgSections.map((row: any) => row.Desc)).toEqual(
savedReplyParts.map((part) => part.carPartDamage.label_fa),
);
expect(
payload.DmgSections.map((row: any) => row.DmgSectionCosts[0].Amount),
).toEqual([180000000, 80000000, 70000000, 100000000, 30000000, 40000000]);
expect(payload.DmgSections[0].WasteValue).toBe(20000000);
});
}); });
@@ -134,13 +134,14 @@ function normalizeAccessoryCaption(value: unknown): string {
export type ResolvedHullDmgAccessory = { export type ResolvedHullDmgAccessory = {
vehicleHullAccessoryId: number; vehicleHullAccessoryId: number;
/** Must come from the same policy dmg-accessories row (Fanavaran filter rule). */ /** Policy-row metadata; does not replace the saved expert-reply partId. */
accessoryKindId: number; accessoryKindId: number;
}; };
/** /**
* GEN.06 accessory pair from `GET …/vehicle-hull-policies/{policyId}/dmg-accessories`. * GEN.06 accessory pair from `GET …/vehicle-hull-policies/{policyId}/dmg-accessories`.
* Only returns a coherent Id + AccessoryKindId from one policy row. * Returns the policy coverage reference and that policy row's metadata.
* The caller preserves the evaluated partId as DmgSections[].AccessoryKindId.
* Exact/caption match only. Factory-bundle fallback for unmatched parts is applied * Exact/caption match only. Factory-bundle fallback for unmatched parts is applied
* by the expertise builder (VehicleHullAccessoryId from «کليه قطعات فابريک»). * by the expertise builder (VehicleHullAccessoryId from «کليه قطعات فابريک»).
*/ */
@@ -199,7 +199,7 @@ export function collectFanavaranExpertiseReadinessWarnings(
if (!thirdPartyLookups) { if (!thirdPartyLookups) {
// VehicleHullAccessoryId may be null: many hull policies only list the // VehicleHullAccessoryId may be null: many hull policies only list the
// factory bundle (کليه قطعات فابريک), not every car-components part. // factory bundle (کليه قطعات فابريک), not every car-components part.
// Do not invent a factory Id with a mismatched AccessoryKindId. // A shared coverage bundle must not replace the evaluated part kind.
if (row.AccessoryKindId == null || row.AccessoryKindId === "") { if (row.AccessoryKindId == null || row.AccessoryKindId === "") {
warnings.push( warnings.push(
`DmgSections[${index}].AccessoryKindId is required from car-components (selected part).`, `DmgSections[${index}].AccessoryKindId is required from car-components (selected part).`,