summaryrefslogtreecommitdiff
path: root/indoteknik_api/controllers/api_v1/user.py
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2024-08-26 13:10:08 +0700
committerit-fixcomart <it@fixcomart.co.id>2024-08-26 13:10:08 +0700
commit31f97fbae9f9f933e1e0aa215b27c82289ba297a (patch)
treeeeba09e4d5a0d92bc5c2c5814ed1858c7428f0fb /indoteknik_api/controllers/api_v1/user.py
parent50872250614240947df2257c9db872e2a2820082 (diff)
<iman> back to code
Diffstat (limited to 'indoteknik_api/controllers/api_v1/user.py')
-rw-r--r--indoteknik_api/controllers/api_v1/user.py80
1 files changed, 13 insertions, 67 deletions
diff --git a/indoteknik_api/controllers/api_v1/user.py b/indoteknik_api/controllers/api_v1/user.py
index cc97d004..b9fd9f56 100644
--- a/indoteknik_api/controllers/api_v1/user.py
+++ b/indoteknik_api/controllers/api_v1/user.py
@@ -104,23 +104,11 @@ class User(controller.Controller):
name = kw.get('name')
email = kw.get('email')
password = kw.get('password')
- 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')
+ return self.response(code=400, description='email, name and password is required')
+
+ company = kw.get('company', False)
+ phone = kw.get('phone')
response = {
'register': False,
@@ -137,80 +125,38 @@ class User(controller.Controller):
return self.response(response)
- # Create user data
user_data = {
'name': name,
'login': email,
'phone': phone,
'password': password,
- 'active': True,
+ 'active': False,
'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 type_acc == 'business':
+ if company:
parameter = [
('company_type', '=', 'company'),
- ('name', 'ilike', business_name)
+ ('name', 'ilike', company)
]
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()
+ match_ratio = SequenceMatcher(None, match_company.name, company).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': business_name
+ 'user_input': company
})
else:
- 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])
+ new_company = request.env['res.partner'].create({
+ 'name': company
+ })
+ user.parent_id = new_company.id
user.send_activation_mail()