Commit 31ad58a7 authored by John Red Medrano's avatar John Red Medrano

replace company key to company object on change request template list

parent 617c68a3
from app.entities import models from app.entities import models
from rest_framework import serializers from rest_framework import serializers
from django.db.models import Q from django.db.models import Q
from django.forms.models import model_to_dict
from drf_writable_nested import WritableNestedModelSerializer from drf_writable_nested import WritableNestedModelSerializer
from app.applicationlayer.cms.utils_cr import (get_account_details, from app.applicationlayer.cms.utils_cr import (get_account_details,
get_dept_details, get_dept_details,
...@@ -13,24 +14,11 @@ class ChangeRequestTemplateApproversSerializer( ...@@ -13,24 +14,11 @@ class ChangeRequestTemplateApproversSerializer(
def to_representation(self, instance): def to_representation(self, instance):
ret = super().to_representation(instance) ret = super().to_representation(instance)
try: try:
user = instance.user ret['company'] = model_to_dict(instance.user.department.company)
ret['department'] = model_to_dict(instance.user.department)
user_details = get_account_details(user.code) ret['name'] = instance.user.name
name = user_details.values_list('name', flat=True)[0] ret['email'] = instance.user.email
email = user_details.values_list('email', flat=True)[0] ret['contact_no'] = instance.user.contact_no
contact_no = user_details.values_list('contact_no', flat=True)[0]
dept_code = user_details.values_list('department', flat=True)[0]
department_details = get_dept_details(dept_code)
department = department_details.values_list('name', flat=True)[0]
comp_code = department_details.values_list('company', flat=True)[0]
company_details = get_companies_details(comp_code)
company = company_details.values_list('name', flat=True)[0]
ret['company'] = company
ret['department'] = department
ret['name'] = name
ret['email'] = email
ret['contact_no'] = contact_no
return ret return ret
...@@ -54,23 +42,11 @@ class ChangeRequestTemplateStakeHoldersSerializer( ...@@ -54,23 +42,11 @@ class ChangeRequestTemplateStakeHoldersSerializer(
def to_representation(self, instance): def to_representation(self, instance):
ret = super().to_representation(instance) ret = super().to_representation(instance)
try: try:
user = instance.user
ret['company'] = model_to_dict(instance.user.department.company)
user_details = get_account_details(user.code) ret['department'] = model_to_dict(instance.user.department)
name = user_details.values_list('name', flat=True)[0] ret['name'] = instance.user.name
email = user_details.values_list('email', flat=True)[0] ret['email'] = instance.user.email
contact_no = user_details.values_list('contact_no', flat=True)[0]
dept_code = user_details.values_list('department', flat=True)[0]
department_details = get_dept_details(dept_code)
department = department_details.values_list('name', flat=True)[0]
comp_code = department_details.values_list('company', flat=True)[0]
company_details = get_companies_details(comp_code)
company = company_details.values_list('name', flat=True)[0]
ret['company'] = company
ret['department'] = department
ret['name'] = name
ret['email'] = email
ret['contact_no'] = contact_no ret['contact_no'] = contact_no
return ret return ret
...@@ -122,34 +98,21 @@ class ChangeRequestTemplatesSerializer( ...@@ -122,34 +98,21 @@ class ChangeRequestTemplatesSerializer(
def to_representation(self, instance): def to_representation(self, instance):
ret = super().to_representation(instance) ret = super().to_representation(instance)
try: try:
company = instance.requested_to_company.code
department = instance.requested_to_department.code
point_of_contact = instance.requested_to_user.code
created_by = instance.created_by_user.code
company = get_companies_details(company)
company = company.values_list('name', flat=True)[0]
department = get_dept_details(department)
department = department.values_list('name', flat=True)[0]
point_of_contact = get_account_details(point_of_contact) ret['company'] = model_to_dict(instance.user.department.company)
point_of_contact = point_of_contact.values_list('name', flat=True)[0] ret['department'] = model_to_dict(instance.user.department)
ret['point_of_contact'] = model_to_dict(instance.requested_to_user)
ret['created_by'] = instance.created_by_user.code
created_by = get_account_details(created_by)
created_by = created_by.values_list('name', flat=True)[0]
ret['company'] = company
ret['department'] = department
ret['point_of_contact'] = point_of_contact
ret['created_by'] = created_by
return ret return ret
except Exception as e: except Exception as e:
ret['company'] = "none" ret['company'] = "none"
ret['department'] = "none" ret['department'] = "none"
ret['point_of_contact'] = "none" ret['point_of_contact'] = "none"
ret['created_by'] = "none" ret['created_by'] = "none"
return ret return ret
class Meta: class Meta:
......
...@@ -1215,7 +1215,7 @@ ...@@ -1215,7 +1215,7 @@
], ],
"body": { "body": {
"mode": "raw", "mode": "raw",
"raw": "{\r\n\t\"requested_to_template_name\": \"Sample Template\",\r\n\t\"requested_to_template_id\": \"JTC21\",\r\n\t\"requested_to_objective\": \"Sample Objective\",\r\n\t\"requested_to_target_date\": \"10\",\r\n\t\"requested_to_priority\": \"High\",\r\n\t\"description\": \"sample description\",\r\n\t\"created_by_department\": \"admin\",\r\n\t\"created_by_user\": \"USER-20190913-0000006\",\r\n\t\"requested_to_company\": \"COMPANY-20190909-0000002\",\r\n\t\"requested_to_department\": \"DEPARTMENT-20190909-0000002\",\r\n\t\"requested_to_user\": \"USER-20190913-0000007\",\r\n\t\r\n\t\r\n\t\"tmp_approvers\": [{\r\n\t\t\t\"level\": \"1\",\r\n\t\t\t\"delegation\": \"HOD\",\r\n\t\t\t\"user\": \"\"\r\n\t\t},\r\n\t\t{\r\n\t\t\t\"level\": \"2\",\r\n\t\t\t\"delegation\": \"Approver\",\r\n\t\t\t\"user\": \"USER-20190913-0000009\"\r\n\t\t},\r\n\t\t{\r\n\t\t\t\"level\": \"3\",\r\n\t\t\t\"delegation\": \"Approver\",\r\n\t\t\t\"user\": \"USER-20190913-0000008\"\r\n\t\t}\r\n\t],\r\n\t\r\n\t\"tmp_stakes\": [{\r\n\t\t\t\"delegation\": \"Mandatory Stakeholder\",\r\n\t\t\t\"user\": \"USER-20190913-0000009\"\r\n\t\t},\r\n\t\t{\r\n\t\t\t\"delegation\": \"Stake Approver\",\r\n\t\t\t\"user\": \"USER-20190913-0000008\"\r\n\t\t}\r\n\t],\r\n\t\r\n\t\"tmp_attachments\": [{\r\n\t\t\t\"attachment_type\": \"Hello\",\r\n\t\t\t\"attachment_name\": \"heyu\",\r\n\t\t\t\"file_name\": \"Sample\",\r\n\t\t\t\"description\": \"Sameple Desc\",\r\n\t\t\t\"uploaded_by\": \"USER-20190913-0000006\"\r\n\t\t},\r\n\t\t{\r\n\t\t\t\"attachment_type\": \"Hello\",\r\n\t\t\t\"attachment_name\": \"heyu\",\r\n\t\t\t\"file_name\": \"Sample\",\r\n\t\t\t\"description\": \"Sameple Desc\",\r\n\t\t\t\"uploaded_by\": \"USER-20190913-0000006\"\r\n\t\t}\r\n\t],\r\n\t\r\n\t\"tmp_details\": [{\r\n\t\t\t\"field_idx\": \"Hello\",\r\n\t\t\t\"field_ref\": \"heyu\",\r\n\t\t\t\"field_val\": \"Sample\",\r\n\t\t\t\"field_props\": \"Sameple Desc\"\r\n\t\t},\r\n\t\t{\r\n\t\t\t\"field_idx\": \"Hello\",\r\n\t\t\t\"field_ref\": \"heyu\",\r\n\t\t\t\"field_val\": \"Sample\",\r\n\t\t\t\"field_props\": \"Sameple Desc\"\r\n\t\t}\r\n\t]\r\n}" "raw": "{\r\n\t\"requested_to_template_name\": \"Sample Template\",\r\n\t\"requested_to_template_id\": \"JTC21\",\r\n\t\"requested_to_objective\": \"Sample Objective\",\r\n\t\"requested_to_target_date\": \"10\",\r\n\t\"requested_to_priority\": \"High\",\r\n\t\"description\": \"sample description\",\r\n\t\"created_by_department\": \"admin\",\r\n\t\"created_by_user\": \"USER-20190913-0000006\",\r\n\t\"requested_to_company\": \"COMPANY-20190909-0000002\",\r\n\t\"requested_to_department\": \"DEPARTMENT-20190909-0000002\",\r\n\t\"requested_to_user\": \"USER-20190913-0000007\",\r\n\t\r\n\t\r\n\t\"tmp_approvers\": [{\r\n\t\t\t\"level\": \"1\",\r\n\t\t\t\"delegation\": \"HOD\",\r\n\t\t\t\"user\": \"\"\r\n\t\t},\r\n\t\t{\r\n\t\t\t\"level\": \"2\",\r\n\t\t\t\"delegation\": \"Approver\",\r\n\t\t\t\"user\": \"USER-20190913-0000009\"\r\n\t\t},\r\n\t\t{\r\n\t\t\t\"level\": \"3\",\r\n\t\t\t\"delegation\": \"Approver\",\r\n\t\t\t\"user\": \"USER-20190913-0000008\"\r\n\t\t}\r\n\t],\r\n\t\r\n\t\"tmp_stakes\": [{\r\n\t\t\t\"delegation\": \"Mandatory Stakeholder\",\r\n\t\t\t\"user\": \"USER-20190913-0000009\"\r\n\t\t},\r\n\t\t{\r\n\t\t\t\"delegation\": \"Stake Approver\",\r\n\t\t\t\"user\": \"USER-20190913-0000008\"\r\n\t\t}\r\n\t],\r\n\t\r\n\t\"tmp_attachments\": [{\r\n\t\t\t\"attachment_type\": \"Hello\",\r\n\t\t\t\"attachment_name\": \"heyu\",\r\n\t\t\t\"file_name\": \"Sample\",\r\n\t\t\t\"description\": \"Sameple Desc\",\r\n\t\t\t\"file_upload\": \"1\",\r\n\t\t\t\"uploaded_by\": \"USER-20190913-0000006\"\r\n\t\t},\r\n\t\t{\r\n\t\t\t\"attachment_type\": \"Hello\",\r\n\t\t\t\"attachment_name\": \"heyu\",\r\n\t\t\t\"file_name\": \"Sample\",\r\n\t\t\t\"description\": \"Sameple Desc\",\r\n\t\t\t\"file_upload\": \"2\",\r\n\t\t\t\"uploaded_by\": \"USER-20190913-0000006\"\r\n\t\t}\r\n\t],\r\n\t\r\n\t\"tmp_details\": [{\r\n\t\t\t\"field_idx\": \"Hello\",\r\n\t\t\t\"field_ref\": \"heyu\",\r\n\t\t\t\"field_val\": \"Sample\",\r\n\t\t\t\"field_props\": \"Sameple Desc\"\r\n\t\t},\r\n\t\t{\r\n\t\t\t\"field_idx\": \"Hello\",\r\n\t\t\t\"field_ref\": \"heyu\",\r\n\t\t\t\"field_val\": \"Sample\",\r\n\t\t\t\"field_props\": \"Sameple Desc\"\r\n\t\t}\r\n\t]\r\n}"
}, },
"url": { "url": {
"raw": "{{baseurl}}/change-request/template-post/", "raw": "{{baseurl}}/change-request/template-post/",
...@@ -2597,7 +2597,7 @@ ...@@ -2597,7 +2597,7 @@
"bearer": [ "bearer": [
{ {
"key": "token", "key": "token",
"value": "84b7b325abedd50a537f78504ab2ff93dfe2d61b", "value": "ba9a275c67036d872f5cfd6862488fc115569fd3",
"type": "string" "type": "string"
} }
] ]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment