summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/user_company_request.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_custom/models/user_company_request.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_custom/models/user_company_request.py')
-rw-r--r--indoteknik_custom/models/user_company_request.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/indoteknik_custom/models/user_company_request.py b/indoteknik_custom/models/user_company_request.py
index f86f3872..86e66934 100644
--- a/indoteknik_custom/models/user_company_request.py
+++ b/indoteknik_custom/models/user_company_request.py
@@ -13,6 +13,39 @@ class UserCompanyRequest(models.Model):
('approved', 'Approve'),
('rejected', 'Reject'),
], string='Approval')
+ similar_company_ids = fields.Many2many('res.partner', compute="_compute_similar_companies", string="Similar Companies")
+
+ @api.depends('user_input')
+ def _compute_similar_companies(self):
+ for record in self:
+ if record.user_input:
+ record.similar_company_ids = [(6, 0, self.get_similar_companies(record.user_input))]
+ else:
+ record.similar_company_ids = [(6, 0, [])]
+
+ # def get_similar_companies(self, user_input):
+ # query = """
+ # SELECT id
+ # FROM res_partner
+ # WHERE levenshtein(name::text, %s) < 3
+ # ORDER BY levenshtein(name::text, %s) ASC
+ # """
+ # self.env.cr.execute(query, (user_input, user_input))
+ # return [row[0] for row in self.env.cr.fetchall()]
+
+ def get_similar_companies(self, user_input):
+ query = """
+ SELECT id
+ FROM res_partner
+ WHERE (name ILIKE %s OR levenshtein(name::text, %s) < 3)
+ AND active = TRUE AND is_company = TRUE
+ ORDER BY levenshtein(name::text, %s) ASC
+ """
+ # Menggunakan '%' untuk mencocokkan nama perusahaan sebagian
+ self.env.cr.execute(query, ('%' + user_input + '%', user_input, user_input))
+ company_ids = [row[0] for row in self.env.cr.fetchall()]
+ return company_ids
+
internal_input = fields.Char(string='Internal Input')
company_type = fields.Char(string='Company Type', compute='_compute_company_type')