summaryrefslogtreecommitdiff
path: root/indoteknik_api/controllers/api_v1/user.py
diff options
context:
space:
mode:
Diffstat (limited to 'indoteknik_api/controllers/api_v1/user.py')
-rw-r--r--indoteknik_api/controllers/api_v1/user.py87
1 files changed, 81 insertions, 6 deletions
diff --git a/indoteknik_api/controllers/api_v1/user.py b/indoteknik_api/controllers/api_v1/user.py
index f4fffc0e..f6dbb92c 100644
--- a/indoteknik_api/controllers/api_v1/user.py
+++ b/indoteknik_api/controllers/api_v1/user.py
@@ -415,8 +415,8 @@ class User(controller.Controller):
@http.route(prefix + 'user/<id>/switch', auth='public', methods=['PUT', 'OPTIONS'], csrf=False)
@controller.Controller.must_authorized()
def switch_account(self, **kw):
- id = kw.get('id')
- user = request.env['res.users'].search([('id', '=', id)], limit=1)
+ id = int(kw.get('id'))
+ user = request.env['res.partner'].search([('id', '=', id)], limit=1)
response = {
'switch': False,
@@ -488,7 +488,7 @@ class User(controller.Controller):
}
new_company = request.env['res.partner'].create(new_company_data)
request.env['user.company.request'].create({
- 'user_id': user.partner_id.id,
+ 'user_id': user.id,
'user_company_id': new_company.id,
'user_input': business_name
})
@@ -526,6 +526,9 @@ class User(controller.Controller):
'mimetype': sppkp_mimetype
})
new_company.message_post(body="SPPKP Uploaded", attachment_ids=[sppkp_attachment.id])
+ request_company = self.get_user_by_email(user.email)
+ request_company.parent_name = business_name
+ request_company.send_company_request_mail()
response['switch'] = 'Pending'
return self.response(response)
@@ -534,7 +537,7 @@ class User(controller.Controller):
# @controller.Controller.must_authorized()
def switch_account_progres(self, **kw):
id = int(kw.get('id'))
- user = request.env['res.users'].search([('id', '=', id)], limit=1)
+ # user = request.env['res.partner'].search([('id', '=', id)], limit=1)
response = {
'status': ''
}
@@ -550,5 +553,77 @@ class User(controller.Controller):
else:
response['status'] = new_company_request.is_approve
else:
- response['status'] = 'unknown'
- return self.response(response) \ No newline at end of file
+ response['status'] = False
+ return self.response(response)
+
+ def get_user_by_email(self, email):
+ return request.env['res.users'].search([
+ ('login', '=', email),
+ ('active', 'in', [True, False])
+ ])
+
+ @http.route(prefix + 'user/download/npwp/<id>', auth='public', methods=['GET'])
+ def download_npwp(self, **kw):
+ id = int(kw.get('id'))
+ """Download NPWP file for the given company"""
+ # Search for the NPWP attachment associated with the company
+ attachment = request.env['ir.attachment'].search([
+ ('res_model', '=', 'res.partner'),
+ ('res_id', '=', id),
+ ('name', '=', 'NPWP Document')
+ ], limit=1)
+
+ if not attachment:
+ return request.not_found()
+
+ # Get the file data and content type
+ npwp_mimetype = attachment.mimetype # This should be directly from the attachment
+ npwp_mimetype = npwp_mimetype or 'application/octet-stream'
+
+ # Create a filename with the correct extension
+ filename = f"{attachment.name}"
+
+ # Manually set the Content-Disposition header to inline
+ content_disposition = f'inline; filename="{filename}"'
+
+ # Send the file as a response
+ return request.make_response(
+ base64.b64decode(attachment.datas),
+ headers=[
+ ('Content-Type', npwp_mimetype),
+ ('Content-Disposition', content_disposition)
+ ]
+ )
+
+ @http.route(prefix + 'user/download/sppkp/<id>', auth='public', methods=['GET'])
+ def download_sppkp(self, **kw):
+ id = int(kw.get('id'))
+ """Download SPPKP file for the given company"""
+ # Search for the SPPKP attachment associated with the company
+ attachment = request.env['ir.attachment'].search([
+ ('res_model', '=', 'res.partner'),
+ ('res_id', '=', id),
+ ('name', '=', 'SPPKP Document')
+ ], limit=1)
+
+ if not attachment:
+ return request.not_found()
+
+ # Get the file data and content type
+ sppkp_mimetype = attachment.mimetype # Use the MIME type directly from the attachment
+ sppkp_mimetype = sppkp_mimetype or 'application/octet-stream'
+
+ # Create a filename with the correct extension
+ filename = attachment.name # No need to append extension since attachment should already have it
+
+ # Manually set the Content-Disposition header to inline
+ content_disposition = f'inline; filename="{filename}"'
+
+ # Send the file as a response
+ return request.make_response(
+ base64.b64decode(attachment.datas),
+ headers=[
+ ('Content-Type', sppkp_mimetype),
+ ('Content-Disposition', content_disposition) # Ensure inline display
+ ]
+ )