summaryrefslogtreecommitdiff
path: root/indoteknik_api
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2024-08-26 12:04:59 +0700
committerit-fixcomart <it@fixcomart.co.id>2024-08-26 12:04:59 +0700
commit4bcf9ae1efe1fa6063e4cb3642dbf00ca79b7e80 (patch)
treeef4d4594e36f88e52d00880c3302cf5836fc129f /indoteknik_api
parent123010cae07bde1a70db3477e6b5e2e5a7a6c44a (diff)
<iman> update new register
Diffstat (limited to 'indoteknik_api')
-rw-r--r--indoteknik_api/controllers/api_v1/user.py86
1 files changed, 71 insertions, 15 deletions
diff --git a/indoteknik_api/controllers/api_v1/user.py b/indoteknik_api/controllers/api_v1/user.py
index 9b89e82c..cc97d004 100644
--- a/indoteknik_api/controllers/api_v1/user.py
+++ b/indoteknik_api/controllers/api_v1/user.py
@@ -1,3 +1,5 @@
+import base64
+
from .. import controller
from odoo import http
from odoo.http import request
@@ -102,12 +104,24 @@ class User(controller.Controller):
name = kw.get('name')
email = kw.get('email')
password = kw.get('password')
- if not name or not email or not password:
- return self.response(code=400, description='email, name and password is required')
-
- company = kw.get('company', False)
phone = kw.get('phone')
-
+
+ # Form Data
+ npwp = kw.get('npwp') # File upload for NPWP
+ npwp_document = kw.get('npwp_document', False) # String input for NPWP document
+ sppkp = kw.get('sppkp', False) # File upload for SPPKP
+ sppkp_document = kw.get('sppkp_document', False) # String input for 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)
+ nama_wajib_pajak = kw.get('nama_wajib_pajak', False)
+ is_pkp = kw.get('is_pkp')
+ type_acc = kw.get('type_acc', False)
+
+ if not name or not email or not password:
+ return self.response(code=400, description='email, name, and password are required')
+
response = {
'register': False,
'reason': None
@@ -120,41 +134,83 @@ class User(controller.Controller):
else:
user.send_activation_mail()
response['reason'] = 'NOT_ACTIVE'
-
+
return self.response(response)
+ # Create user data
user_data = {
'name': name,
'login': email,
'phone': phone,
'password': password,
- 'active': False,
+ 'active': True,
'sel_groups_1_9_10': 9
}
user = request.env['res.users'].create(user_data)
user.partner_id.email = email
+ user.partner_id.phone = phone
- if company:
+ if type_acc == 'business':
parameter = [
('company_type', '=', 'company'),
- ('name', 'ilike', 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, company).ratio()
+ match_ratio = SequenceMatcher(None, match_company.name, business_name).ratio()
if match_ratio > 0.8:
+ # Set the user's partner's parent to the matched company
+ user.partner_id.parent_id = match_company.id
+
+ # 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': company
+ 'user_input': business_name
})
else:
- new_company = request.env['res.partner'].create({
- 'name': company
- })
- user.parent_id = new_company.id
+ if not nama_wajib_pajak and not is_pkp:
+ nama_wajib_pajak = business_name
+
+ 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 else 'nonpkp',
+ 'npwp': npwp if is_pkp else (npwp if npwp else '0000'),
+ 'sppkp': sppkp if is_pkp else (sppkp if sppkp else '0000'),
+ 'nama_wajib_pajak': nama_wajib_pajak,
+ 'email': email_partner,
+ 'company_type': 'company'
+ }
+ new_company = request.env['res.partner'].create(new_company_data)
+ user.partner_id.parent_id = new_company.id
+
+ if npwp_document:
+ pdf_data = base64.b64decode(npwp_document)
+ npwp_attachment = request.env['ir.attachment'].create({
+ 'name': 'NPWP Document',
+ 'type': 'binary',
+ 'datas': pdf_data,
+ 'res_model': 'res.partner',
+ 'res_id': new_company.id,
+ 'mimetype': 'application/pdf'
+ })
+ new_company.message_post(body="NPWP Uploaded", attachment_ids=[npwp_attachment.id])
+
+ if sppkp_document:
+ pdf_data = base64.b64decode(sppkp_document)
+ sppkp_attachment = request.env['ir.attachment'].create({
+ 'name': 'SPPKP Document',
+ 'type': 'binary',
+ 'datas': pdf_data,
+ 'res_model': 'res.partner',
+ 'res_id': new_company.id,
+ 'mimetype': 'application/pdf'
+ })
+ new_company.message_post(body="SPPKP Uploaded", attachment_ids=[sppkp_attachment.id])
user.send_activation_mail()