summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--indoteknik_api/controllers/api_v1/user.py68
-rw-r--r--indoteknik_api/models/res_users.py2
2 files changed, 68 insertions, 2 deletions
diff --git a/indoteknik_api/controllers/api_v1/user.py b/indoteknik_api/controllers/api_v1/user.py
index 4b29c820..b897cfff 100644
--- a/indoteknik_api/controllers/api_v1/user.py
+++ b/indoteknik_api/controllers/api_v1/user.py
@@ -554,4 +554,70 @@ class User(controller.Controller):
return request.env['res.users'].search([
('login', '=', email),
('active', 'in', [True, False])
- ]) \ No newline at end of file
+ ])
+
+ @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
+ ]
+ )
diff --git a/indoteknik_api/models/res_users.py b/indoteknik_api/models/res_users.py
index 170a8061..0a302be9 100644
--- a/indoteknik_api/models/res_users.py
+++ b/indoteknik_api/models/res_users.py
@@ -58,7 +58,7 @@ class ResUsers(models.Model):
'rajaongkir_city_id': user.kecamatan_id.rajaongkir_id or 0,
'alamat_wajib_pajak': user.alamat_lengkap_text or '',
'alamat_bisnis': user.street or '',
- 'company_type': user.customer_type or 'nonpkp',
+ 'companyType': user.customer_type or 'nonpkp',
}
if user.kota_id: