process/insurance: fix Harley-Davidson
This commit is contained in:
parent
79b8c491e9
commit
9f7776243f
@ -5,11 +5,11 @@ import { createValidationSchema } from './validation';
|
||||
import { selectLeaseObjectUseFor } from '@/config/default-options';
|
||||
import * as CRMTypes from '@/graphql/crm.types';
|
||||
import { normalizeOptions } from '@/utils/entity';
|
||||
import { debouncedReaction } from '@/utils/mobx';
|
||||
import { debouncedReaction, disposableReaction } from '@/utils/mobx';
|
||||
import { reaction } from 'mobx';
|
||||
|
||||
export function common({ store, apolloClient }: ProcessContext) {
|
||||
const { $calculation, $tables } = store;
|
||||
const { $calculation, $tables, $process } = store;
|
||||
|
||||
reaction(
|
||||
() => $calculation.element('selectGPSBrand').getValue(),
|
||||
@ -230,7 +230,8 @@ export function common({ store, apolloClient }: ProcessContext) {
|
||||
}
|
||||
);
|
||||
|
||||
reaction(
|
||||
disposableReaction(
|
||||
() => $process.has('LoadKP'),
|
||||
() => $calculation.element('selectBrand').getValue(),
|
||||
async (brandId) => {
|
||||
if (!brandId) {
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
/* eslint-disable sonarjs/cognitive-complexity */
|
||||
/* eslint-disable zod/require-strict */
|
||||
import type { ValidationContext } from '../types';
|
||||
import type * as Insurance from '@/Components/Calculation/Form/Insurance/InsuranceTable/types';
|
||||
@ -8,6 +9,7 @@ import { z } from 'zod';
|
||||
|
||||
export function createValidationSchema({ apolloClient }: ValidationContext) {
|
||||
return ValuesSchema.pick({
|
||||
brand: true,
|
||||
insDecentral: true,
|
||||
leasingPeriod: true,
|
||||
leasingWithoutKasko: true,
|
||||
@ -27,6 +29,7 @@ export function createValidationSchema({ apolloClient }: ValidationContext) {
|
||||
leasingWithoutKasko,
|
||||
insDecentral,
|
||||
insurance,
|
||||
brand: brandId,
|
||||
},
|
||||
ctx
|
||||
) => {
|
||||
@ -110,6 +113,41 @@ export function createValidationSchema({ apolloClient }: ValidationContext) {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (brandId) {
|
||||
const {
|
||||
data: { evo_brand },
|
||||
} = await apolloClient.query({
|
||||
query: CRMTypes.GetBrandDocument,
|
||||
variables: { brandId },
|
||||
});
|
||||
|
||||
const {
|
||||
data: { accounts },
|
||||
} = await apolloClient.query({
|
||||
query: CRMTypes.GetInsuranceCompaniesDocument,
|
||||
});
|
||||
|
||||
const defaultKaskoOptions = accounts?.filter((x) =>
|
||||
x?.evo_type_ins_policy?.includes(100_000_000)
|
||||
);
|
||||
|
||||
if (evo_brand?.evo_id === 'BRAND49') {
|
||||
const renessansCompany = defaultKaskoOptions?.find((x) => x?.evo_inn === '7725497022');
|
||||
|
||||
if (
|
||||
renessansCompany &&
|
||||
insurance.values.kasko.insuranceCompany !== renessansCompany.value
|
||||
) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message:
|
||||
'Для Harley-Davidson СК для КАСКО может быть только ' + renessansCompany.label,
|
||||
path: ['insurance'],
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user