diff options
| author | it-fixcomart <it@fixcomart.co.id> | 2024-09-28 10:56:08 +0700 |
|---|---|---|
| committer | it-fixcomart <it@fixcomart.co.id> | 2024-09-28 10:56:08 +0700 |
| commit | 4e5da6ed950e2129cb50087469c2b56894bafe93 (patch) | |
| tree | 6e1509ddc8bfa78c54004196284851d4e7a6049f /indoteknik_api | |
| parent | 7909b937bf9484b38f16be1f4be955094e0c25ab (diff) | |
| parent | 0d1bf664d93ff02a42b1962fcf034690b105b8a9 (diff) | |
Merge branch 'production' into iman/switch-account
Diffstat (limited to 'indoteknik_api')
| -rw-r--r-- | indoteknik_api/controllers/api_v1/user.py | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/indoteknik_api/controllers/api_v1/user.py b/indoteknik_api/controllers/api_v1/user.py index e62aad90..f6dbb92c 100644 --- a/indoteknik_api/controllers/api_v1/user.py +++ b/indoteknik_api/controllers/api_v1/user.py @@ -157,20 +157,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: |
