summaryrefslogtreecommitdiff
path: root/indoteknik_api/controllers/api_v1/user.py
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2024-10-25 08:47:36 +0700
committerit-fixcomart <it@fixcomart.co.id>2024-10-25 08:47:36 +0700
commit9fa80c62cdffec5b91aaf2a2899d70d0f507c2e4 (patch)
tree93ae8d82f774345f650bc8d072dea759c6e33363 /indoteknik_api/controllers/api_v1/user.py
parenta21c5fe37529b2d2259d3b86d8e98730b2bc8513 (diff)
parenta7be93f4825967807f12e6bfbebcf090af8500fa (diff)
Merge branch 'production' into iman/switch-account
# Conflicts: # indoteknik_api/controllers/api_v1/user.py # indoteknik_custom/models/user_company_request.py
Diffstat (limited to 'indoteknik_api/controllers/api_v1/user.py')
-rw-r--r--indoteknik_api/controllers/api_v1/user.py43
1 files changed, 28 insertions, 15 deletions
diff --git a/indoteknik_api/controllers/api_v1/user.py b/indoteknik_api/controllers/api_v1/user.py
index c490500c..e06a099f 100644
--- a/indoteknik_api/controllers/api_v1/user.py
+++ b/indoteknik_api/controllers/api_v1/user.py
@@ -94,7 +94,13 @@ class User(controller.Controller):
user = request.env['res.users'].create(user_data)
user.partner_id.email = email
-
+ user.partner_id.customer_type = 'nonpkp'
+ user.partner_id.npwp = '00.000.000.0-000.000'
+ user.partner_id.sppkp = '-'
+ user.partner_id.nama_wajib_pajak = user.name
+ user.partner_id.user_id = 3222
+ user.partner_id.property_account_receivable_id = 395
+ user.partner_id.property_account_payable_id = 438
data = {
'is_auth': True,
'user': self.response_with_token(user)
@@ -149,6 +155,7 @@ class User(controller.Controller):
'name': name,
'login': email,
'mobile': phone,
+ 'phone': phone,
'password': password,
'active': False,
'sel_groups_1_9_10': 9
@@ -158,20 +165,26 @@ class User(controller.Controller):
user.partner_id.email = email
user.partner_id.mobile = phone
- 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:
+ 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]
+
# 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:
@@ -235,7 +248,7 @@ class User(controller.Controller):
if type_acc == 'individu':
user.partner_id.customer_type = 'nonpkp'
- user.partner_id.npwp = '0.000.000.0-000.000'
+ user.partner_id.npwp = '00.000.000.0-000.000'
user.partner_id.sppkp = '-'
user.partner_id.nama_wajib_pajak = name
user.partner_id.user_id = 3222
@@ -255,7 +268,7 @@ class User(controller.Controller):
'activation_request': False,
'reason': None
}
-
+
user = self.get_user_by_email(email)
if not user:
response['reason'] = 'NOT_FOUND'
@@ -769,4 +782,4 @@ class User(controller.Controller):
response['status'] = False
# If no attachment is found, return status False
- return self.response(response)
+ return self.response(response) \ No newline at end of file