From 4815f90304fa9298da521c3ce8df2730f79a00cd Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Mon, 23 Sep 2024 14:18:47 +0700 Subject: update new switch account api --- indoteknik_api/controllers/api_v1/user.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'indoteknik_api/controllers/api_v1/user.py') diff --git a/indoteknik_api/controllers/api_v1/user.py b/indoteknik_api/controllers/api_v1/user.py index 7166bd79..4b29c820 100644 --- a/indoteknik_api/controllers/api_v1/user.py +++ b/indoteknik_api/controllers/api_v1/user.py @@ -409,8 +409,8 @@ class User(controller.Controller): @http.route(prefix + 'user//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, @@ -482,7 +482,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 }) @@ -520,6 +520,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) @@ -528,7 +531,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': '' } @@ -545,4 +548,10 @@ class User(controller.Controller): response['status'] = new_company_request.is_approve else: response['status'] = 'unknown' - return self.response(response) \ No newline at end of file + return self.response(response) + + def get_user_by_email(self, email): + return request.env['res.users'].search([ + ('login', '=', email), + ('active', 'in', [True, False]) + ]) \ No newline at end of file -- cgit v1.2.3 From 55e1e5dfc58b8b1d53dd34835cb000c656758656 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Fri, 27 Sep 2024 17:24:26 +0700 Subject: add api untuk lihat sppkp atau npwp --- indoteknik_api/controllers/api_v1/user.py | 68 ++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) (limited to 'indoteknik_api/controllers/api_v1/user.py') 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/', 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/', 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 + ] + ) -- cgit v1.2.3 From 4d8dee6da82637f406373a8cd3258a47529bb59f Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Sat, 28 Sep 2024 10:00:49 +0700 Subject: update switch account --- indoteknik_api/controllers/api_v1/user.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_api/controllers/api_v1/user.py') diff --git a/indoteknik_api/controllers/api_v1/user.py b/indoteknik_api/controllers/api_v1/user.py index b897cfff..e62aad90 100644 --- a/indoteknik_api/controllers/api_v1/user.py +++ b/indoteknik_api/controllers/api_v1/user.py @@ -547,7 +547,7 @@ class User(controller.Controller): else: response['status'] = new_company_request.is_approve else: - response['status'] = 'unknown' + response['status'] = False return self.response(response) def get_user_by_email(self, email): -- cgit v1.2.3 From c2c2ef9cadd3e6cca40a9b2825cdb29c5c77d466 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Mon, 30 Sep 2024 13:26:35 +0700 Subject: update switch account get file --- indoteknik_api/controllers/api_v1/user.py | 77 +++++++++++++++++++++++-------- 1 file changed, 57 insertions(+), 20 deletions(-) (limited to 'indoteknik_api/controllers/api_v1/user.py') 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/', 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/', 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/', 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) -- cgit v1.2.3 From 90a29846ae6008b3152d495f2e83a5d00cfdd438 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Mon, 30 Sep 2024 13:56:43 +0700 Subject: update switch account --- indoteknik_api/controllers/api_v1/user.py | 34 +++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) (limited to 'indoteknik_api/controllers/api_v1/user.py') diff --git a/indoteknik_api/controllers/api_v1/user.py b/indoteknik_api/controllers/api_v1/user.py index 4a01f88b..a4655417 100644 --- a/indoteknik_api/controllers/api_v1/user.py +++ b/indoteknik_api/controllers/api_v1/user.py @@ -450,12 +450,24 @@ class User(controller.Controller): 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_input': business_name - }) + if user.parent_id : + match_company.email = email_partner, + match_company.customer_type = 'pkp' if is_pkp == 'true' else 'nonpkp', + match_company.name = business_name if business_name else business_name, + match_company.company_type_id.id = company_type_id if company_type_id else False, + match_company.industry_id.id = industry_id, + match_company.npwp = npwp if is_pkp == 'true' else (npwp if npwp else '00.000.000.0-000.000'), + match_company.sppkp = sppkp if is_pkp == 'true' else (sppkp if sppkp else '-'), + match_company.nama_wajib_pajak = nama_wajib_pajak, + match_company.alamat_lengkap_text = alamat_wajib_pajak, + match_company.street = alamat_bisnis, + else: + # Create a user company request + request.env['user.company.request'].create({ + 'user_id': user.partner_id.id, + 'user_company_id': match_company.id, + 'user_input': business_name + }) else: if not nama_wajib_pajak and is_pkp == 'false': nama_wajib_pajak = business_name @@ -505,7 +517,10 @@ class User(controller.Controller): 'res_id': new_company.id, 'mimetype': npwp_mimetype }) - new_company.message_post(body="NPWP Uploaded", attachment_ids=[npwp_attachment.id]) + if user.parent_id: + match_company.message_post(body="NPWP Uploaded", attachment_ids=[npwp_attachment.id]) + else: + new_company.message_post(body="NPWP Uploaded", attachment_ids=[npwp_attachment.id]) if sppkp_document != ' ': sppkp_mimetype, _ = mimetypes.guess_type(sppkp_filename) @@ -519,7 +534,10 @@ class User(controller.Controller): 'res_id': new_company.id, 'mimetype': sppkp_mimetype }) - new_company.message_post(body="SPPKP Uploaded", attachment_ids=[sppkp_attachment.id]) + if user.parent_id: + match_company.message_post(body="SPPKP Uploaded", attachment_ids=[sppkp_attachment.id]) + else: + 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() -- cgit v1.2.3 From 48322cab6c0b10bf85dec9beffffd2c1064aa8a5 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Tue, 1 Oct 2024 10:19:47 +0700 Subject: update switch account --- indoteknik_api/controllers/api_v1/user.py | 58 ++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 12 deletions(-) (limited to 'indoteknik_api/controllers/api_v1/user.py') diff --git a/indoteknik_api/controllers/api_v1/user.py b/indoteknik_api/controllers/api_v1/user.py index b66e0f3c..77dc60d0 100644 --- a/indoteknik_api/controllers/api_v1/user.py +++ b/indoteknik_api/controllers/api_v1/user.py @@ -451,16 +451,48 @@ class User(controller.Controller): match_ratio = SequenceMatcher(None, match_company.name, business_name).ratio() if match_ratio > 0.8: if user.parent_id : - match_company.email = email_partner, - match_company.customer_type = 'pkp' if is_pkp == 'true' else 'nonpkp', - match_company.name = business_name if business_name else business_name, - match_company.company_type_id.id = company_type_id if company_type_id else False, - match_company.industry_id.id = industry_id, - match_company.npwp = npwp if is_pkp == 'true' else (npwp if npwp else '00.000.000.0-000.000'), - match_company.sppkp = sppkp if is_pkp == 'true' else (sppkp if sppkp else '-'), - match_company.nama_wajib_pajak = nama_wajib_pajak, - match_company.alamat_lengkap_text = alamat_wajib_pajak, - match_company.street = alamat_bisnis, + new_data = { + 'email': email_partner, + 'customer_type': 'pkp' if is_pkp == 'true' else 'nonpkp', + 'name': business_name if business_name else business_name, + 'company_type_id': company_type_id if company_type_id else False, + 'industry_id': industry_id, + 'npwp': npwp if is_pkp == 'true' else (npwp if npwp else '00.000.000.0-000.000'), + 'sppkp': sppkp if is_pkp == 'true' else (sppkp if sppkp else '-'), + 'nama_wajib_pajak': nama_wajib_pajak, + 'alamat_lengkap_text': alamat_wajib_pajak, + 'street': alamat_bisnis, + 'active': False, + } + match_company.write(new_data) + + if npwp_document != ' ': + npwp_mimetype, _ = mimetypes.guess_type(npwp_filename) + npwp_mimetype = npwp_mimetype or 'application/octet-stream' + pdf_data = base64.b64decode(npwp_document) + npwp_attachment = request.env['ir.attachment'].create({ + 'name': 'NPWP Document', + 'type': 'binary', + 'datas': base64.b64encode(pdf_data), + 'res_model': 'res.partner', + 'res_id': match_company.id, + 'mimetype': npwp_mimetype + }) + match_company.message_post(body="NPWP Uploaded", attachment_ids=[npwp_attachment.id]) + + if sppkp_document != ' ': + sppkp_mimetype, _ = mimetypes.guess_type(sppkp_filename) + sppkp_mimetype = sppkp_mimetype or 'application/octet-stream' + pdf_data = base64.b64decode(sppkp_document) + sppkp_attachment = request.env['ir.attachment'].create({ + 'name': 'SPPKP Document', + 'type': 'binary', + 'datas': base64.b64encode(pdf_data), + 'res_model': 'res.partner', + 'res_id': match_company.id, + 'mimetype': sppkp_mimetype + }) + match_company.message_post(body="SPPKP Uploaded", attachment_ids=[sppkp_attachment.id]) else: # Create a user company request request.env['user.company.request'].create({ @@ -607,7 +639,8 @@ class User(controller.Controller): ] ) - @http.route(prefix + 'user/chek/npwp/', auth='public', methods=['GET']) + @http.route(prefix + 'user/chek/npwp/', auth='public', methods=['GET', 'OPTIONS']) + @controller.Controller.must_authorized() def chek_npwp(self, **kw): id = int(kw.get('id')) """Download NPWP file for the given company""" @@ -661,7 +694,8 @@ class User(controller.Controller): ] ) - @http.route(prefix + 'user/chek/sppkp/', auth='public', methods=['GET']) + @http.route(prefix + 'user/chek/sppkp/', auth='public', methods=['GET', 'OPTIONS']) + @controller.Controller.must_authorized() def chek_sppkp(self, **kw): id = int(kw.get('id')) """Download SPPKP file for the given company""" -- cgit v1.2.3 From 471bfb3cff31dac389fd9b8cba5ec8b7e465c82f Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Tue, 1 Oct 2024 13:31:27 +0700 Subject: update switch account --- indoteknik_api/controllers/api_v1/user.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'indoteknik_api/controllers/api_v1/user.py') diff --git a/indoteknik_api/controllers/api_v1/user.py b/indoteknik_api/controllers/api_v1/user.py index 77dc60d0..6f71174c 100644 --- a/indoteknik_api/controllers/api_v1/user.py +++ b/indoteknik_api/controllers/api_v1/user.py @@ -462,7 +462,6 @@ class User(controller.Controller): 'nama_wajib_pajak': nama_wajib_pajak, 'alamat_lengkap_text': alamat_wajib_pajak, 'street': alamat_bisnis, - 'active': False, } match_company.write(new_data) @@ -496,7 +495,7 @@ class User(controller.Controller): else: # Create a user company request request.env['user.company.request'].create({ - 'user_id': user.partner_id.id, + 'user_id': user.id, 'user_company_id': match_company.id, 'user_input': business_name }) @@ -572,7 +571,10 @@ class User(controller.Controller): 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() + if user.parent_id: + request_company.send_company_request_approve_mail() + else: + request_company.send_company_request_mail() response['switch'] = 'Pending' return self.response(response) -- cgit v1.2.3 From fba08fba49c8c885d2f087516892f0747922839a Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Tue, 1 Oct 2024 14:33:40 +0700 Subject: update switch account --- indoteknik_api/controllers/api_v1/user.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'indoteknik_api/controllers/api_v1/user.py') diff --git a/indoteknik_api/controllers/api_v1/user.py b/indoteknik_api/controllers/api_v1/user.py index 6f71174c..1528306f 100644 --- a/indoteknik_api/controllers/api_v1/user.py +++ b/indoteknik_api/controllers/api_v1/user.py @@ -433,6 +433,7 @@ class User(controller.Controller): nama_wajib_pajak = kw.get('nama_wajib_pajak', False) is_pkp = kw.get('is_pkp') type_acc = kw.get('type_acc', False) + parent_id = int(kw.get('parent_id',False)) response = { @@ -445,6 +446,8 @@ class User(controller.Controller): ('company_type', '=', 'company'), ('name', 'ilike', business_name) ] + if parent_id: + parameter = ['id', '=', parent_id] match_company = request.env['res.partner'].search(parameter, limit=1) match_ratio = 0 if match_company: -- cgit v1.2.3 From 37ee561ff633776ef984d4d9e441981aecbca762 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Tue, 1 Oct 2024 14:56:06 +0700 Subject: update add parameter --- indoteknik_api/controllers/api_v1/user.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_api/controllers/api_v1/user.py') diff --git a/indoteknik_api/controllers/api_v1/user.py b/indoteknik_api/controllers/api_v1/user.py index 1528306f..8a9d8f68 100644 --- a/indoteknik_api/controllers/api_v1/user.py +++ b/indoteknik_api/controllers/api_v1/user.py @@ -447,7 +447,7 @@ class User(controller.Controller): ('name', 'ilike', business_name) ] if parent_id: - parameter = ['id', '=', parent_id] + parameter = (('id', '=', parent_id)) match_company = request.env['res.partner'].search(parameter, limit=1) match_ratio = 0 if match_company: -- cgit v1.2.3 From 795af0a07c28d5d407070734ef94b4838d05f793 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Wed, 2 Oct 2024 11:48:15 +0700 Subject: update switch account --- indoteknik_api/controllers/api_v1/user.py | 226 ++++++++++++++++++------------ 1 file changed, 134 insertions(+), 92 deletions(-) (limited to 'indoteknik_api/controllers/api_v1/user.py') diff --git a/indoteknik_api/controllers/api_v1/user.py b/indoteknik_api/controllers/api_v1/user.py index bcced998..26c0b4fe 100644 --- a/indoteknik_api/controllers/api_v1/user.py +++ b/indoteknik_api/controllers/api_v1/user.py @@ -448,97 +448,20 @@ class User(controller.Controller): ('name', 'ilike', business_name) ] if parent_id: - parameter = (('id', '=', parent_id)) - 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: - if user.parent_id : - new_data = { - 'email': email_partner, - 'customer_type': 'pkp' if is_pkp == 'true' else 'nonpkp', - 'name': business_name if business_name else business_name, - 'company_type_id': company_type_id if company_type_id else False, - 'industry_id': industry_id, - 'npwp': npwp if is_pkp == 'true' else (npwp if npwp else '00.000.000.0-000.000'), - 'sppkp': sppkp if is_pkp == 'true' else (sppkp if sppkp else '-'), - 'nama_wajib_pajak': nama_wajib_pajak, - 'alamat_lengkap_text': alamat_wajib_pajak, - 'street': alamat_bisnis, - } - match_company.write(new_data) - - if npwp_document != ' ': - npwp_mimetype, _ = mimetypes.guess_type(npwp_filename) - npwp_mimetype = npwp_mimetype or 'application/octet-stream' - pdf_data = base64.b64decode(npwp_document) - npwp_attachment = request.env['ir.attachment'].create({ - 'name': 'NPWP Document', - 'type': 'binary', - 'datas': base64.b64encode(pdf_data), - 'res_model': 'res.partner', - 'res_id': match_company.id, - 'mimetype': npwp_mimetype - }) - match_company.message_post(body="NPWP Uploaded", attachment_ids=[npwp_attachment.id]) - - if sppkp_document != ' ': - sppkp_mimetype, _ = mimetypes.guess_type(sppkp_filename) - sppkp_mimetype = sppkp_mimetype or 'application/octet-stream' - pdf_data = base64.b64decode(sppkp_document) - sppkp_attachment = request.env['ir.attachment'].create({ - 'name': 'SPPKP Document', - 'type': 'binary', - 'datas': base64.b64encode(pdf_data), - 'res_model': 'res.partner', - 'res_id': match_company.id, - 'mimetype': sppkp_mimetype - }) - match_company.message_post(body="SPPKP Uploaded", attachment_ids=[sppkp_attachment.id]) - else: - # Create a user company request - request.env['user.company.request'].create({ - 'user_id': user.id, - 'user_company_id': match_company.id, - 'user_input': business_name - }) - else: - if not nama_wajib_pajak and is_pkp == 'false': - nama_wajib_pajak = business_name - - if not alamat_wajib_pajak and is_pkp == 'false': - alamat_wajib_pajak = alamat_bisnis - - new_company_data = { + match_company = request.env['res.partner'].search([('id', '=', parent_id)], limit=1) + new_data = { + 'email': email_partner, + 'customer_type': 'pkp' if is_pkp == 'true' else 'nonpkp', 'name': business_name if business_name else business_name, 'company_type_id': company_type_id if company_type_id else False, 'industry_id': industry_id, - 'customer_type': 'pkp' if is_pkp == 'true' else 'nonpkp', 'npwp': npwp if is_pkp == 'true' else (npwp if npwp else '00.000.000.0-000.000'), 'sppkp': sppkp if is_pkp == 'true' else (sppkp if sppkp else '-'), 'nama_wajib_pajak': nama_wajib_pajak, 'alamat_lengkap_text': alamat_wajib_pajak, - 'email': email_partner, 'street': alamat_bisnis, - 'company_type': 'company', - 'user_id': 3222, - 'property_account_receivable_id': 395, - 'property_account_payable_id': 438, - 'active': False, } - new_company = request.env['res.partner'].create(new_company_data) - request.env['user.company.request'].create({ - 'user_id': user.id, - 'user_company_id': new_company.id, - 'user_input': business_name - }) - # user.partner_id.parent_id = new_company.id - # user.partner_id.customer_type = new_company.customer_type - # user.partner_id.npwp = new_company.npwp - # user.partner_id.sppkp = new_company.sppkp - # user.partner_id.nama_wajib_pajak = new_company.nama_wajib_pajak - # user.partner_id.alamat_lengkap_text = new_company.alamat_lengkap_text + match_company.write(new_data) if npwp_document != ' ': npwp_mimetype, _ = mimetypes.guess_type(npwp_filename) @@ -549,13 +472,10 @@ class User(controller.Controller): 'type': 'binary', 'datas': base64.b64encode(pdf_data), 'res_model': 'res.partner', - 'res_id': new_company.id, + 'res_id': match_company.id, 'mimetype': npwp_mimetype }) - if user.parent_id: - match_company.message_post(body="NPWP Uploaded", attachment_ids=[npwp_attachment.id]) - else: - new_company.message_post(body="NPWP Uploaded", attachment_ids=[npwp_attachment.id]) + match_company.message_post(body="NPWP Uploaded", attachment_ids=[npwp_attachment.id]) if sppkp_document != ' ': sppkp_mimetype, _ = mimetypes.guess_type(sppkp_filename) @@ -566,17 +486,139 @@ class User(controller.Controller): 'type': 'binary', 'datas': base64.b64encode(pdf_data), 'res_model': 'res.partner', - 'res_id': new_company.id, + 'res_id': match_company.id, 'mimetype': sppkp_mimetype }) - if user.parent_id: - match_company.message_post(body="SPPKP Uploaded", attachment_ids=[sppkp_attachment.id]) + match_company.message_post(body="SPPKP Uploaded", attachment_ids=[sppkp_attachment.id]) + else: + 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: + if user.parent_id : + new_data = { + 'email': email_partner, + 'customer_type': 'pkp' if is_pkp == 'true' else 'nonpkp', + 'name': business_name if business_name else business_name, + 'company_type_id': company_type_id if company_type_id else False, + 'industry_id': industry_id, + 'npwp': npwp if is_pkp == 'true' else (npwp if npwp else '00.000.000.0-000.000'), + 'sppkp': sppkp if is_pkp == 'true' else (sppkp if sppkp else '-'), + 'nama_wajib_pajak': nama_wajib_pajak, + 'alamat_lengkap_text': alamat_wajib_pajak, + 'street': alamat_bisnis, + } + match_company.write(new_data) + + if npwp_document != ' ': + npwp_mimetype, _ = mimetypes.guess_type(npwp_filename) + npwp_mimetype = npwp_mimetype or 'application/octet-stream' + pdf_data = base64.b64decode(npwp_document) + npwp_attachment = request.env['ir.attachment'].create({ + 'name': 'NPWP Document', + 'type': 'binary', + 'datas': base64.b64encode(pdf_data), + 'res_model': 'res.partner', + 'res_id': match_company.id, + 'mimetype': npwp_mimetype + }) + match_company.message_post(body="NPWP Uploaded", attachment_ids=[npwp_attachment.id]) + + if sppkp_document != ' ': + sppkp_mimetype, _ = mimetypes.guess_type(sppkp_filename) + sppkp_mimetype = sppkp_mimetype or 'application/octet-stream' + pdf_data = base64.b64decode(sppkp_document) + sppkp_attachment = request.env['ir.attachment'].create({ + 'name': 'SPPKP Document', + 'type': 'binary', + 'datas': base64.b64encode(pdf_data), + 'res_model': 'res.partner', + 'res_id': match_company.id, + 'mimetype': sppkp_mimetype + }) + match_company.message_post(body="SPPKP Uploaded", attachment_ids=[sppkp_attachment.id]) else: - new_company.message_post(body="SPPKP Uploaded", attachment_ids=[sppkp_attachment.id]) + # Create a user company request + request.env['user.company.request'].create({ + 'user_id': user.id, + 'user_company_id': match_company.id, + 'user_input': business_name + }) + else: + if not nama_wajib_pajak and is_pkp == 'false': + nama_wajib_pajak = business_name + + if not alamat_wajib_pajak and is_pkp == 'false': + alamat_wajib_pajak = alamat_bisnis + + new_company_data = { + 'name': business_name if business_name else business_name, + 'company_type_id': company_type_id if company_type_id else False, + 'industry_id': industry_id, + 'customer_type': 'pkp' if is_pkp == 'true' else 'nonpkp', + 'npwp': npwp if is_pkp == 'true' else (npwp if npwp else '00.000.000.0-000.000'), + 'sppkp': sppkp if is_pkp == 'true' else (sppkp if sppkp else '-'), + 'nama_wajib_pajak': nama_wajib_pajak, + 'alamat_lengkap_text': alamat_wajib_pajak, + 'email': email_partner, + 'street': alamat_bisnis, + 'company_type': 'company', + 'user_id': 3222, + 'property_account_receivable_id': 395, + 'property_account_payable_id': 438, + 'active': False, + } + new_company = request.env['res.partner'].create(new_company_data) + request.env['user.company.request'].create({ + 'user_id': user.id, + 'user_company_id': new_company.id, + 'user_input': business_name + }) + # user.partner_id.parent_id = new_company.id + # user.partner_id.customer_type = new_company.customer_type + # user.partner_id.npwp = new_company.npwp + # user.partner_id.sppkp = new_company.sppkp + # 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 != ' ': + npwp_mimetype, _ = mimetypes.guess_type(npwp_filename) + npwp_mimetype = npwp_mimetype or 'application/octet-stream' + pdf_data = base64.b64decode(npwp_document) + npwp_attachment = request.env['ir.attachment'].create({ + 'name': 'NPWP Document', + 'type': 'binary', + 'datas': base64.b64encode(pdf_data), + 'res_model': 'res.partner', + 'res_id': new_company.id, + 'mimetype': npwp_mimetype + }) + if user.parent_id: + match_company.message_post(body="NPWP Uploaded", attachment_ids=[npwp_attachment.id]) + else: + new_company.message_post(body="NPWP Uploaded", attachment_ids=[npwp_attachment.id]) + + if sppkp_document != ' ': + sppkp_mimetype, _ = mimetypes.guess_type(sppkp_filename) + sppkp_mimetype = sppkp_mimetype or 'application/octet-stream' + pdf_data = base64.b64decode(sppkp_document) + sppkp_attachment = request.env['ir.attachment'].create({ + 'name': 'SPPKP Document', + 'type': 'binary', + 'datas': base64.b64encode(pdf_data), + 'res_model': 'res.partner', + 'res_id': new_company.id, + 'mimetype': sppkp_mimetype + }) + if user.parent_id: + match_company.message_post(body="SPPKP Uploaded", attachment_ids=[sppkp_attachment.id]) + else: + 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 if user.parent_id: - request_company.send_company_request_approve_mail() + request_company.send_company_switch_approve_mail() else: request_company.send_company_request_mail() -- cgit v1.2.3 From a21c5fe37529b2d2259d3b86d8e98730b2bc8513 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Wed, 2 Oct 2024 13:20:44 +0700 Subject: update jika user parent false --- indoteknik_api/controllers/api_v1/user.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'indoteknik_api/controllers/api_v1/user.py') diff --git a/indoteknik_api/controllers/api_v1/user.py b/indoteknik_api/controllers/api_v1/user.py index 26c0b4fe..c490500c 100644 --- a/indoteknik_api/controllers/api_v1/user.py +++ b/indoteknik_api/controllers/api_v1/user.py @@ -434,8 +434,14 @@ class User(controller.Controller): nama_wajib_pajak = kw.get('nama_wajib_pajak', False) is_pkp = kw.get('is_pkp') type_acc = kw.get('type_acc', False) - parent_id = int(kw.get('parent_id',False)) - + parent_id = kw.get('parent_id', False) + if parent_id: + try: + parent_id = int(parent_id) + except ValueError: + parent_id = False + else: + parent_id = False response = { 'switch': False, -- cgit v1.2.3 From b8ff264742f9415ceb4d919948b40800700fd9bd Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Fri, 25 Oct 2024 10:19:18 +0700 Subject: update error code individu ke non pkp --- indoteknik_api/controllers/api_v1/user.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indoteknik_api/controllers/api_v1/user.py') diff --git a/indoteknik_api/controllers/api_v1/user.py b/indoteknik_api/controllers/api_v1/user.py index e06a099f..b293c6b5 100644 --- a/indoteknik_api/controllers/api_v1/user.py +++ b/indoteknik_api/controllers/api_v1/user.py @@ -601,7 +601,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) @@ -618,7 +618,7 @@ class User(controller.Controller): else: 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) -- cgit v1.2.3 From 56f2deda9cdf2a51d5a53aade7758a0ac9313e05 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Fri, 25 Oct 2024 15:50:41 +0700 Subject: update send email template --- indoteknik_api/controllers/api_v1/user.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_api/controllers/api_v1/user.py') diff --git a/indoteknik_api/controllers/api_v1/user.py b/indoteknik_api/controllers/api_v1/user.py index b293c6b5..56b89b27 100644 --- a/indoteknik_api/controllers/api_v1/user.py +++ b/indoteknik_api/controllers/api_v1/user.py @@ -639,7 +639,7 @@ class User(controller.Controller): if user.parent_id: request_company.send_company_switch_approve_mail() else: - request_company.send_company_request_mail() + request_company.send_company_request_mail_switch() response['switch'] = 'Pending' return self.response(response) -- cgit v1.2.3 From af39e11dba2e6f9a57a520003888884c9f0f2571 Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Fri, 29 Nov 2024 10:02:48 +0700 Subject: update code switch account --- indoteknik_api/controllers/api_v1/user.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'indoteknik_api/controllers/api_v1/user.py') diff --git a/indoteknik_api/controllers/api_v1/user.py b/indoteknik_api/controllers/api_v1/user.py index 56b89b27..a94ba1f8 100644 --- a/indoteknik_api/controllers/api_v1/user.py +++ b/indoteknik_api/controllers/api_v1/user.py @@ -509,6 +509,12 @@ class User(controller.Controller): 'mimetype': sppkp_mimetype }) match_company.message_post(body="SPPKP Uploaded", attachment_ids=[sppkp_attachment.id]) + request.env['user.company.request'].create({ + 'user_id': user.id, + 'user_company_id': match_company.id, + 'user_input': business_name, + 'is_switch_account': True + }) else: match_company = request.env['res.partner'].search(parameter, limit=1) match_ratio = 0 @@ -636,11 +642,12 @@ class User(controller.Controller): 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 - if user.parent_id: - request_company.send_company_switch_approve_mail() - else: - request_company.send_company_request_mail_switch() + # if user.parent_id: + # request_company.send_company_switch_approve_mail() + # else: + # request_company.send_company_request_mail_switch() + request_company.send_company_request_mail_switch() response['switch'] = 'Pending' return self.response(response) -- cgit v1.2.3