Skip to content

Commit 76a0ddc

Browse files
Merge pull request #146 from VineetBala-AOT/main
fix amendments duplicating in consolidated conditions
2 parents 3ad98c5 + 71464b0 commit 76a0ddc

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

condition-api/src/condition_api/services/condition_service.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -521,13 +521,14 @@ def create_condition(project_id, document_id, conditions_data, allow_duplicate_c
521521
)
522522
final_document_id = document[0]
523523
# Check if a condition exists with the given document_id and condition_number
524-
existing_condition = (
524+
existing_conditions = (
525525
db.session.query(Condition)
526526
.filter(
527527
Condition.document_id == final_document_id,
528528
Condition.condition_number == conditions_data.get("condition_number"),
529+
Condition.is_active is True
529530
)
530-
.first()
531+
.all()
531532
)
532533

533534
ConditionService._check_duplicate_condition_number(
@@ -540,10 +541,11 @@ def create_condition(project_id, document_id, conditions_data, allow_duplicate_c
540541
)
541542

542543
# If it exists, update is_active to False
543-
if existing_condition and not allow_duplicate_condition:
544-
existing_condition.is_active = False
545-
existing_condition.effective_to = datetime.utcnow()
546-
db.session.add(existing_condition)
544+
if existing_conditions and not allow_duplicate_condition:
545+
for condition in existing_conditions:
546+
condition.is_active = False
547+
condition.effective_to = datetime.utcnow()
548+
db.session.add(condition)
547549
else:
548550
final_document_id = document_id
549551

condition-web/src/components/Conditions/CreateConditionModal.tsx

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ type ConditionModalProps = {
3232
documentId: string;
3333
};
3434

35+
type Subcondition = {
36+
subcondition_text: string;
37+
subconditions?: Subcondition[];
38+
};
39+
3540
export const ConditionModal: FC<ConditionModalProps> = ({ open, onClose, projectId, documentId }) => {
3641
const navigate = useNavigate();
3742
const [selectedDocumentId, setSelectedDocumentId] = useState<string | "">("");
@@ -50,6 +55,16 @@ export const ConditionModal: FC<ConditionModalProps> = ({ open, onClose, project
5055

5156
const { data: documentConditions, isPending: isConditionsLoading } = useGetConditions(loadCondition, true, projectId, selectedDocumentId);
5257

58+
const flattenSubconditions = (
59+
subconditions: Subcondition[] = [],
60+
level = 0
61+
): string[] => {
62+
return subconditions.flatMap(sub => [
63+
`${' '.repeat(level)}${sub.subcondition_text}`,
64+
...flattenSubconditions(sub.subconditions ?? [], level + 1),
65+
]);
66+
};
67+
5368
const handleCreateNewCondition = async (conditionDetails?: ConditionModel) => {
5469
try {
5570
const response = await createCondition(conditionDetails);
@@ -175,9 +190,13 @@ export const ConditionModal: FC<ConditionModalProps> = ({ open, onClose, project
175190
<Box sx={{ marginTop: 0 }}>
176191
<Typography variant="body1" marginBottom={"2px"}>Condition Preview</Typography>
177192
<TextField
178-
value={documentConditions.conditions
179-
.find(condition => condition.condition_id === selectedConditionId)
180-
?.subconditions?.map(subcondition => subcondition.subcondition_text).join(' ') || ""}
193+
value={
194+
flattenSubconditions(
195+
documentConditions.conditions
196+
.find(c => c.condition_id === selectedConditionId)
197+
?.subconditions
198+
).join('\n')
199+
}
181200
InputProps={{ readOnly: true }}
182201
fullWidth
183202
multiline

0 commit comments

Comments
 (0)