add job_internal id to integration
This commit is contained in:
parent
9bf0125121
commit
4e40d56412
@ -25,6 +25,7 @@ class ERPIntegrationService:
|
||||
Validate the incoming request from ERP system
|
||||
Returns: (is_valid, error_message)
|
||||
"""
|
||||
|
||||
# Check if source is active
|
||||
if not self.source.is_active:
|
||||
return False, "Source is not active"
|
||||
@ -70,6 +71,7 @@ class ERPIntegrationService:
|
||||
try:
|
||||
# Map ERP fields to JobPosting fields
|
||||
job_data = {
|
||||
'internal_job_id': request_data.get('job_id', '').strip(),
|
||||
'title': request_data.get('title', '').strip(),
|
||||
'department': request_data.get('department', '').strip(),
|
||||
'job_type': self.map_job_type(request_data.get('job_type', 'FULL_TIME')),
|
||||
|
||||
@ -187,7 +187,6 @@ class PersonCreateView(CreateView):
|
||||
template_name = "people/create_person.html"
|
||||
form_class = PersonForm
|
||||
success_url = reverse_lazy("person_list")
|
||||
print("from agency")
|
||||
def form_valid(self, form):
|
||||
if "HX-Request" in self.request.headers:
|
||||
instance = form.save()
|
||||
@ -196,7 +195,6 @@ class PersonCreateView(CreateView):
|
||||
slug = self.request.POST.get("agency")
|
||||
if slug:
|
||||
agency = HiringAgency.objects.get(slug=slug)
|
||||
print(agency)
|
||||
instance.agency = agency
|
||||
instance.save()
|
||||
return redirect("agency_portal_persons_list")
|
||||
|
||||
@ -202,11 +202,14 @@ class ApplicationCreateView(LoginRequiredMixin, StaffRequiredMixin, SuccessMessa
|
||||
job = get_object_or_404(models.JobPosting, slug=self.kwargs['slug'])
|
||||
form.instance.job = job
|
||||
return super().form_valid(form)
|
||||
def form_invalid(self, form):
|
||||
messages.error(self.request, f"{form.errors.as_text()}")
|
||||
return super().form_invalid(form)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
if self.request.method == 'GET':
|
||||
context['person_form'] = forms.PersonForm()
|
||||
# if self.request.method == 'GET':
|
||||
context['person_form'] = forms.PersonForm()
|
||||
return context
|
||||
|
||||
class ApplicationUpdateView(LoginRequiredMixin, StaffRequiredMixin, SuccessMessageMixin, UpdateView):
|
||||
|
||||
@ -81,6 +81,17 @@ class ERPIntegrationView(View):
|
||||
'message': 'Source not found'
|
||||
}, status=404)
|
||||
|
||||
job_id = data.get('job_id')
|
||||
if not job_id:
|
||||
return JsonResponse({
|
||||
'status': 'error',
|
||||
'message': 'Job ID is required and must be unique'
|
||||
})
|
||||
if JobPosting.objects.filter(internal_job_id=job_id).exists():
|
||||
return JsonResponse({
|
||||
'status': 'error',
|
||||
'message': 'Job with this ID already exists'
|
||||
}, status=400)
|
||||
# Create integration service
|
||||
service = ERPIntegrationService(source)
|
||||
|
||||
@ -144,6 +155,7 @@ class ERPIntegrationView(View):
|
||||
def _create_job(self, service: ERPIntegrationService, data: Dict[str, Any]) -> tuple[Dict[str, Any], str]:
|
||||
"""Create a new job from ERP data"""
|
||||
# Validate ERP data
|
||||
# print(data)
|
||||
is_valid, error_msg = service.validate_erp_data(data)
|
||||
if not is_valid:
|
||||
return None, error_msg
|
||||
@ -152,7 +164,6 @@ class ERPIntegrationView(View):
|
||||
job, error_msg = service.create_job_from_erp(data)
|
||||
if error_msg:
|
||||
return None, error_msg
|
||||
|
||||
# Prepare response data
|
||||
response_data = {
|
||||
'job_id': job.internal_job_id,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user