File size: 1,415 Bytes
b4f2238
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""Client export serialization helpers shared by admin modules."""

from __future__ import annotations

from typing import Any


class ClientExportSerializerService:
    """Service facade for client export serialization."""

    def serialize_client_obj(self, obj: Any) -> dict[str, Any]:
        return serialize_client_obj(obj)


def serialize_client_obj(obj: Any) -> dict[str, Any]:
    """Serialize a Client-like object for export."""
    return {
        "name": obj.name,
        "client_type": obj.client_type,
        "id_number": obj.id_number,
        "phone": obj.phone,
        "address": getattr(obj, "address", None),
        "legal_representative": obj.legal_representative,
        "legal_representative_id_number": getattr(obj, "legal_representative_id_number", None),
        "is_our_client": obj.is_our_client,
        "identity_docs": [
            {"doc_type": doc.doc_type, "file_path": doc.file_path} for doc in obj.identity_docs.all() if doc.file_path
        ],
        "property_clues": [
            {
                "clue_type": clue.clue_type,
                "content": clue.content,
                "attachments": [
                    {"file_path": att.file_path, "file_name": att.file_name}
                    for att in clue.attachments.all()
                    if att.file_path
                ],
            }
            for clue in obj.property_clues.all()
        ],
    }