summaryrefslogtreecommitdiff
path: root/indoteknik_api/controllers/api_v1/user.py
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2024-09-12 12:18:59 +0700
committerit-fixcomart <it@fixcomart.co.id>2024-09-12 12:18:59 +0700
commit33d2a0583d74182709588313ad0eae70c8569f02 (patch)
treefa216402b61eb7845ece0bc2ae9cde5b2c7df41d /indoteknik_api/controllers/api_v1/user.py
parent84cb69b4ce0a793768fbeca4367d37f21e896615 (diff)
<iman> update new register
Diffstat (limited to 'indoteknik_api/controllers/api_v1/user.py')
-rw-r--r--indoteknik_api/controllers/api_v1/user.py143
1 files changed, 142 insertions, 1 deletions
diff --git a/indoteknik_api/controllers/api_v1/user.py b/indoteknik_api/controllers/api_v1/user.py
index ea74d297..9a15f404 100644
--- a/indoteknik_api/controllers/api_v1/user.py
+++ b/indoteknik_api/controllers/api_v1/user.py
@@ -149,7 +149,7 @@ class User(controller.Controller):
'login': email,
'mobile': phone,
'password': password,
- 'active': False,
+ 'active': True,
'sel_groups_1_9_10': 9
}
@@ -403,3 +403,144 @@ class User(controller.Controller):
x) for x in partners]
return self.response(address)
+
+ @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)
+
+ response = {
+ 'switch': False,
+ 'reason': None
+ }
+
+ # Form Data
+ npwp = kw.get('npwp')
+ npwp_document = kw.get('npwp_document', False)
+ npwp_filename = kw.get('npwp_filename', 'npwp_document')
+ sppkp = kw.get('sppkp', False)
+ sppkp_document = kw.get('sppkp_document', False)
+ sppkp_filename = kw.get('sppkp_filename', 'sppkp_document')
+ email_partner = kw.get('email_partner')
+ business_name = kw.get('business_name', False)
+ industry_id = int(kw.get('industry_id', '0') or 0)
+ company_type_id = int(kw.get('company_type_id', '0') or 0)
+ alamat_wajib_pajak = kw.get('alamat_wajib_pajak', False)
+ alamat_bisnis = kw.get('alamat_bisnis', False)
+ nama_wajib_pajak = kw.get('nama_wajib_pajak', False)
+ is_pkp = kw.get('is_pkp')
+ type_acc = kw.get('type_acc', False)
+
+
+ response = {
+ 'switch': False,
+ 'reason': None
+ }
+
+ 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_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.partner_id.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
+ })
+ 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
+ })
+ new_company.message_post(body="SPPKP Uploaded", attachment_ids=[sppkp_attachment.id])
+
+ response['switch'] = 'Pending'
+ return self.response(response)
+
+ @http.route(prefix + 'user/<id>/switch_progres', auth='public', methods=['GET', 'OPTIONS'], csrf=False)
+ # @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)
+ response = {
+ 'status': ''
+ }
+ parameter = [
+ ('user_id', '=', id)
+ ]
+ new_company_request = request.env['user.company.request'].search(parameter, limit=1)
+ is_approve = ''
+ if new_company_request:
+ # Mengambil nilai is_approve
+ if new_company_request.is_approve == False:
+ response['status'] = 'pending'
+ else:
+ response['status'] = new_company_request.is_approve
+ else:
+ response['status'] = 'unknown'
+ return self.response(response) \ No newline at end of file