diff options
| -rw-r--r-- | indoteknik_api/controllers/api_v1/partner.py | 19 | ||||
| -rw-r--r-- | indoteknik_api/controllers/api_v1/user.py | 198 | ||||
| -rw-r--r-- | indoteknik_api/models/res_users.py | 9 | ||||
| -rw-r--r-- | indoteknik_custom/models/user_company_request.py | 20 | ||||
| -rw-r--r-- | indoteknik_custom/views/res_users.xml | 8 | ||||
| -rw-r--r-- | indoteknik_custom/views/user_company_request.xml | 10 |
6 files changed, 211 insertions, 53 deletions
diff --git a/indoteknik_api/controllers/api_v1/partner.py b/indoteknik_api/controllers/api_v1/partner.py index 369f2125..d1a41739 100644 --- a/indoteknik_api/controllers/api_v1/partner.py +++ b/indoteknik_api/controllers/api_v1/partner.py @@ -127,13 +127,9 @@ class Partner(controller.Controller): 'alamat_lengkap_text': [], 'street': [], }) - - # Mengambil id_user dari request id_user = self.get_request_params(kw, { 'id_user': ['number'] }) - - # Mengambil parameter user dari request params_user = self.get_request_params(kw, { 'company_type_id': ['number'], 'industry_id': ['number'], @@ -142,17 +138,26 @@ class Partner(controller.Controller): 'alamat_lengkap_text': [], }) - # Cek validitas parameter if not params['valid']: return self.response(code=400, description=params) - # Mencari partner dan user berdasarkan ID partner = request.env[self._name].search([('id', '=', params['value']['id'])], limit=1) user = request.env[self._name].search([('id', '=', id_user['value']['id_user'])], limit=1) - if not partner: return self.response(code=404, description='Partner not found') + if not params['value'].get('tax_name'): + params['value']['nama_wajib_pajak'] = params['value'].get('name') + params_user['value']['nama_wajib_pajak'] = params_user['value'].get('name') + + if not params['value'].get('alamat_lengkap_text'): + params['value']['alamat_lengkap_text'] = params['value'].get('street') + params_user['value']['alamat_lengkap_text'] = params_user['value'].get('street') + + if not params['value'].get('npwp'): + params['value']['npwp'] = "00.000.000.0-000.000" + params_user['value']['npwp'] = "00.000.000.0-000.000" + # Filter parameter yang memiliki nilai saja untuk partner params_filtered = {k: v for k, v in params['value'].items() if v} diff --git a/indoteknik_api/controllers/api_v1/user.py b/indoteknik_api/controllers/api_v1/user.py index a3eb5459..b66e0f3c 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' @@ -415,8 +409,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, @@ -456,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 @@ -488,7 +494,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 }) @@ -499,7 +505,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) @@ -511,9 +517,12 @@ 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: + if sppkp_document != ' ': sppkp_mimetype, _ = mimetypes.guess_type(sppkp_filename) sppkp_mimetype = sppkp_mimetype or 'application/octet-stream' pdf_data = base64.b64decode(sppkp_document) @@ -525,7 +534,13 @@ 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() response['switch'] = 'Pending' return self.response(response) @@ -534,7 +549,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 +565,120 @@ 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/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')) + """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 + ] + ) + + @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) diff --git a/indoteknik_api/models/res_users.py b/indoteknik_api/models/res_users.py index b2e8acfe..0a302be9 100644 --- a/indoteknik_api/models/res_users.py +++ b/indoteknik_api/models/res_users.py @@ -51,13 +51,14 @@ class ResUsers(models.Model): 'district': None, 'sub_district': None, 'zip': user.zip or '', - 'company_type_id': user.company_type_id.id or None, - 'industry_id': user.industry_id.id or None, + 'company_type_id': user.company_type_id.id or '', + 'industry_id': user.industry_id.id or '', 'tax_name': user.nama_wajib_pajak or '', 'npwp': user.npwp or '', 'rajaongkir_city_id': user.kecamatan_id.rajaongkir_id or 0, - 'alamat_wajib_pajak': user.alamat_lengkap_text or None, - 'alamat_bisnis': user.street or None, + 'alamat_wajib_pajak': user.alamat_lengkap_text or '', + 'alamat_bisnis': user.street or '', + 'companyType': user.customer_type or 'nonpkp', } if user.kota_id: diff --git a/indoteknik_custom/models/user_company_request.py b/indoteknik_custom/models/user_company_request.py index d540b0f6..f86f3872 100644 --- a/indoteknik_custom/models/user_company_request.py +++ b/indoteknik_custom/models/user_company_request.py @@ -1,4 +1,4 @@ -from odoo import models, fields +from odoo import models, fields, api from odoo.exceptions import UserError from odoo.http import request @@ -13,14 +13,32 @@ class UserCompanyRequest(models.Model): ('approved', 'Approve'), ('rejected', 'Reject'), ], string='Approval') + internal_input = fields.Char(string='Internal Input') + company_type = fields.Char(string='Company Type', compute='_compute_company_type') + + @api.depends('user_company_id.customer_type') + def _compute_company_type(self): + for record in self: + if record.user_company_id.customer_type == 'nonpkp': + record.company_type = 'Non PKP' + elif record.user_company_id.customer_type == 'pkp': + record.company_type = 'PKP' + else: + record.company_type = 'company type belum di set' def write(self, vals): user = self.get_user_by_email(self.user_id.email) user.parent_name = self.user_input is_approve = vals.get('is_approve') + is_internal_input = vals.get('internal_input') if self.is_approve and is_approve: raise UserError('Tidak dapat mengubah approval yang sudah diisi') + if is_internal_input: + if self.user_company_id.nama_wajib_pajak == self.user_company_id.name: + self.user_company_id.nama_wajib_pajak = is_internal_input + self.user_company_id.name = is_internal_input + if not self.is_approve and is_approve: if is_approve == 'approved': self.user_id.parent_id = self.user_company_id.id diff --git a/indoteknik_custom/views/res_users.xml b/indoteknik_custom/views/res_users.xml index 39b9d43e..41c74d72 100644 --- a/indoteknik_custom/views/res_users.xml +++ b/indoteknik_custom/views/res_users.xml @@ -5,7 +5,7 @@ <field name="model_id" ref="base.model_res_users"/> <field name="subject">Aktivasi Akun - Indoteknik.com</field> <field name="email_from">"Indoteknik.com" <noreply@indoteknik.com></field> - <field name="reply_to">noreply@indoteknik.com</field> + <field name="reply_to">sales@indoteknik.com</field> <field name="email_to">${object.login | safe}</field> <field name="body_html" type="html"> <table border="0" cellpadding="0" cellspacing="0" style="padding-top: 16px; background-color: #F1F1F1; font-family:Inter, Helvetica, Verdana, Arial,sans-serif; line-height: 24px; color: #454748; width: 100%; border-collapse:separate;"> @@ -65,7 +65,7 @@ <field name="model_id" ref="base.model_res_users"/> <field name="subject">Email Pendaftaran Bisnis dalam Proses Review</field> <field name="email_from">"Indoteknik.com" <noreply@indoteknik.com></field> - <field name="reply_to">noreply@indoteknik.com</field> + <field name="reply_to">sales@indoteknik.com</field> <field name="email_to">${object.login | safe}</field> <field name="body_html" type="html"> <table border="0" cellpadding="0" cellspacing="0" style="padding-top: 16px; background-color: #F1F1F1; font-family:Inter, Helvetica, Verdana, Arial,sans-serif; line-height: 24px; color: #454748; width: 100%; border-collapse:separate;"> @@ -125,7 +125,7 @@ <field name="model_id" ref="base.model_res_users"/> <field name="subject">Email Pendaftaran Bisnis Berhasil</field> <field name="email_from">"Indoteknik.com" <noreply@indoteknik.com></field> - <field name="reply_to">noreply@indoteknik.com</field> + <field name="reply_to">sales@indoteknik.com</field> <field name="email_to">${object.login | safe}</field> <field name="body_html" type="html"> <table border="0" cellpadding="0" cellspacing="0" style="padding-top: 16px; background-color: #F1F1F1; font-family:Inter, Helvetica, Verdana, Arial,sans-serif; line-height: 24px; color: #454748; width: 100%; border-collapse:separate;"> @@ -186,7 +186,7 @@ <field name="model_id" ref="base.model_res_users"/> <field name="subject">Email Pendaftaran Bisnis Tidak Berhasil</field> <field name="email_from">"Indoteknik.com" <noreply@indoteknik.com></field> - <field name="reply_to">noreply@indoteknik.com</field> + <field name="reply_to">sales@indoteknik.com</field> <field name="email_to">${object.login | safe}</field> <field name="body_html" type="html"> <table border="0" cellpadding="0" cellspacing="0" style="padding-top: 16px; background-color: #F1F1F1; font-family:Inter, Helvetica, Verdana, Arial,sans-serif; line-height: 24px; color: #454748; width: 100%; border-collapse:separate;"> diff --git a/indoteknik_custom/views/user_company_request.xml b/indoteknik_custom/views/user_company_request.xml index c9edd3f8..ad121a89 100644 --- a/indoteknik_custom/views/user_company_request.xml +++ b/indoteknik_custom/views/user_company_request.xml @@ -8,12 +8,14 @@ <field name="user_id"/> <field name="user_company_id"/> <field name="user_input"/> - <field + <field name="is_approve" widget="badge" decoration-success="is_approve == 'approved'" decoration-danger="is_approve == 'rejected'" /> + <field name="internal_input"/> + <field name="company_type"/> <field name="create_date"/> </tree> </field> @@ -30,12 +32,14 @@ <field name="user_id" readonly="1"/> <field name="user_company_id" readonly="1"/> <field name="user_input" readonly="1"/> - <field - name="is_approve" + <field + name="is_approve" required="1" decoration-success="is_approve == 'approved'" decoration-danger="is_approve == 'rejected'" /> + <field name="internal_input" /> + <field name="company_type" readonly="1"/> </group> </group> </sheet> |
