summaryrefslogtreecommitdiff
path: root/indoteknik_api/controllers/api_v1/user.py
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2024-09-30 13:26:35 +0700
committerit-fixcomart <it@fixcomart.co.id>2024-09-30 13:26:35 +0700
commitc2c2ef9cadd3e6cca40a9b2825cdb29c5c77d466 (patch)
tree80fac7716321481828172f930127495fa09025bb /indoteknik_api/controllers/api_v1/user.py
parent600d990fd866d8b729267c10f7e73a78d8b60f2d (diff)
<iman> update switch account get file
Diffstat (limited to 'indoteknik_api/controllers/api_v1/user.py')
-rw-r--r--indoteknik_api/controllers/api_v1/user.py77
1 files changed, 57 insertions, 20 deletions
diff --git a/indoteknik_api/controllers/api_v1/user.py b/indoteknik_api/controllers/api_v1/user.py
index f6dbb92c..4a01f88b 100644
--- a/indoteknik_api/controllers/api_v1/user.py
+++ b/indoteknik_api/controllers/api_v1/user.py
@@ -157,26 +157,20 @@ class User(controller.Controller):
user.partner_id.email = email
user.partner_id.mobile = phone
- if type_acc == 'business' and business_name:
- # Eksekusi query SQL menggunakan Levenshtein distance
- query = """
- SELECT name, levenshtein(name::text, %s) AS distance
- FROM res_partner
- WHERE levenshtein(name::text, %s) < 3
- ORDER BY distance ASC
- """
- params = (business_name, business_name)
- request.env.cr.execute(query, params)
- result = request.env.cr.fetchone()
-
- if result:
- match_company_name = result[0]
- match_company_id = result[2]
-
+ if type_acc == 'business':
+ parameter = [
+ ('company_type', '=', 'company'),
+ ('name', 'ilike', business_name)
+ ]
+ match_company = request.env['res.partner'].search(parameter, limit=1)
+ match_ratio = 0
+ if match_company:
+ match_ratio = SequenceMatcher(None, match_company.name, business_name).ratio()
+ if match_ratio > 0.8:
# Create a user company request
request.env['user.company.request'].create({
'user_id': user.partner_id.id,
- 'user_company_id': match_company_id,
+ 'user_company_id': match_company.id,
'user_input': business_name
})
else:
@@ -260,7 +254,7 @@ class User(controller.Controller):
'activation_request': False,
'reason': None
}
-
+
user = self.get_user_by_email(email)
if not user:
response['reason'] = 'NOT_FOUND'
@@ -499,7 +493,7 @@ class User(controller.Controller):
# user.partner_id.nama_wajib_pajak = new_company.nama_wajib_pajak
# user.partner_id.alamat_lengkap_text = new_company.alamat_lengkap_text
- if npwp_document:
+ if npwp_document != ' ':
npwp_mimetype, _ = mimetypes.guess_type(npwp_filename)
npwp_mimetype = npwp_mimetype or 'application/octet-stream'
pdf_data = base64.b64decode(npwp_document)
@@ -513,7 +507,7 @@ class User(controller.Controller):
})
new_company.message_post(body="NPWP Uploaded", attachment_ids=[npwp_attachment.id])
- if sppkp_document:
+ if sppkp_document != ' ':
sppkp_mimetype, _ = mimetypes.guess_type(sppkp_filename)
sppkp_mimetype = sppkp_mimetype or 'application/octet-stream'
pdf_data = base64.b64decode(sppkp_document)
@@ -595,6 +589,27 @@ class User(controller.Controller):
]
)
+ @http.route(prefix + 'user/chek/npwp/<id>', auth='public', methods=['GET'])
+ def chek_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)
+ response = {
+ 'status': ''
+ }
+ if attachment:
+ response['status'] = True
+ else:
+ response['status'] = False
+
+ # If no attachment is found, return status False
+ return self.response(response)
+
@http.route(prefix + 'user/download/sppkp/<id>', auth='public', methods=['GET'])
def download_sppkp(self, **kw):
id = int(kw.get('id'))
@@ -627,3 +642,25 @@ class User(controller.Controller):
('Content-Disposition', content_disposition) # Ensure inline display
]
)
+
+ @http.route(prefix + 'user/chek/sppkp/<id>', auth='public', methods=['GET'])
+ def chek_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)
+
+ response = {
+ 'status': ''
+ }
+ if attachment:
+ response['status'] = True
+ else:
+ response['status'] = False
+
+ # If no attachment is found, return status False
+ return self.response(response)