change
This commit is contained in:
@@ -14,6 +14,7 @@ from core.apps.evaluation.choices.auto import ObjectOwnerType
|
||||
from core.apps.documents.models import ExecutorInfoModel
|
||||
from core.apps.documents.serializers.contract import ContractPDFRequestSerializer
|
||||
from core.services import CurrencyService
|
||||
from core.services.didox import DidoxService
|
||||
|
||||
|
||||
UZ_MONTHS = {
|
||||
@@ -124,10 +125,10 @@ class ValuationReportPDFView(APIView):
|
||||
}
|
||||
"""
|
||||
|
||||
def get(self, request, pk, *args, **kwargs):
|
||||
def get(self, request, pk):
|
||||
return self._generate_pdf(request, pk, payload={})
|
||||
|
||||
def post(self, request, pk, *args, **kwargs):
|
||||
def post(self, request, pk):
|
||||
serializer = ContractPDFRequestSerializer(data=request.data or {})
|
||||
serializer.is_valid(raise_exception=True)
|
||||
return self._generate_pdf(request, pk, payload=serializer.validated_data)
|
||||
@@ -169,7 +170,6 @@ class ValuationReportPDFView(APIView):
|
||||
|
||||
def _build_context(self, auto, payload):
|
||||
vehicle = auto.vehicle
|
||||
user = auto.user
|
||||
|
||||
report_date = auto.rate_report_date or auto.contract_date or date.today()
|
||||
valuation_date = auto.rate_date or report_date
|
||||
@@ -190,7 +190,7 @@ class ValuationReportPDFView(APIView):
|
||||
comparative_final = final_value
|
||||
|
||||
vehicle_ctx = self._vehicle_context(auto, vehicle)
|
||||
customer_ctx = self._customer_context(user)
|
||||
customer_ctx = self._customer_context(auto)
|
||||
owner_ctx = self._owner_context(auto)
|
||||
contract_ctx = self._contract_context(auto, report_date)
|
||||
inspection_ctx = self._inspection_context(payload)
|
||||
@@ -308,31 +308,63 @@ class ValuationReportPDFView(APIView):
|
||||
"empty_weight": auto.empty_weight if auto.empty_weight is not None else "",
|
||||
}
|
||||
|
||||
def _customer_context(self, user):
|
||||
empty = {
|
||||
"name": "",
|
||||
"address": "",
|
||||
def _customer_context(self, auto):
|
||||
is_legal = auto.customer_type == ObjectOwnerType.LEGAL
|
||||
|
||||
if is_legal:
|
||||
name = auto.customer_legal_entity or ""
|
||||
tin = auto.customer_legal_inn or ""
|
||||
else:
|
||||
name = " ".join(
|
||||
filter(None, [
|
||||
auto.customer_individual_person_l_name,
|
||||
auto.customer_individual_person_f_name,
|
||||
auto.customer_individual_person_p_name,
|
||||
])
|
||||
).strip()
|
||||
tin = auto.customer_individual_person_passport_num or ""
|
||||
|
||||
ctx = {
|
||||
"name": name,
|
||||
"address": auto.customer_residence or "",
|
||||
"phone": "",
|
||||
"tin": "",
|
||||
"account": "",
|
||||
"bank": "",
|
||||
"mfo": "",
|
||||
}
|
||||
if not user:
|
||||
return empty
|
||||
full_name = " ".join(filter(None, [user.last_name, user.first_name])).strip()
|
||||
if not full_name:
|
||||
full_name = user.username or user.phone or ""
|
||||
return {
|
||||
"name": full_name,
|
||||
"address": "",
|
||||
"phone": user.phone or "",
|
||||
"tin": "",
|
||||
"tin": tin,
|
||||
"account": "",
|
||||
"bank": "",
|
||||
"mfo": "",
|
||||
}
|
||||
|
||||
if is_legal and auto.customer_legal_inn:
|
||||
self._enrich_customer_from_didox(ctx, auto.customer_legal_inn)
|
||||
|
||||
return ctx
|
||||
|
||||
def _enrich_customer_from_didox(self, ctx, lookup_id):
|
||||
try:
|
||||
tin_int = int(str(lookup_id).strip())
|
||||
except (TypeError, ValueError):
|
||||
return
|
||||
|
||||
data = DidoxService.get_company_info(tin_int) or {}
|
||||
if not data:
|
||||
return
|
||||
|
||||
def pick(*keys):
|
||||
for key in keys:
|
||||
value = data.get(key)
|
||||
if value:
|
||||
return str(value)
|
||||
return ""
|
||||
|
||||
if not ctx["name"]:
|
||||
ctx["name"] = pick("name", "fullName", "shortName")
|
||||
if not ctx["address"]:
|
||||
ctx["address"] = pick("address")
|
||||
if not ctx["account"]:
|
||||
ctx["account"] = pick("account", "bankAccount")
|
||||
if not ctx["mfo"]:
|
||||
ctx["mfo"] = pick("mfo", "bankCode")
|
||||
|
||||
def _owner_context(self, auto):
|
||||
if auto.object_owner_type == ObjectOwnerType.LEGAL:
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user