From 5fdade43dd264f834a52194b22a9d687c4dc6aab Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Wed, 22 Feb 2023 17:08:53 +0700 Subject: user company request and register logic --- indoteknik_api/controllers/api_v1/user.py | 32 ++++++++++++++-- indoteknik_custom/__manifest__.py | 1 + indoteknik_custom/models/__init__.py | 1 + indoteknik_custom/models/user_company_request.py | 15 ++++++++ indoteknik_custom/security/ir.model.access.csv | 3 +- indoteknik_custom/views/user_company_request.xml | 49 ++++++++++++++++++++++++ 6 files changed, 96 insertions(+), 5 deletions(-) create mode 100644 indoteknik_custom/models/user_company_request.py create mode 100644 indoteknik_custom/views/user_company_request.xml diff --git a/indoteknik_api/controllers/api_v1/user.py b/indoteknik_api/controllers/api_v1/user.py index 17bc931e..800f6bf1 100644 --- a/indoteknik_api/controllers/api_v1/user.py +++ b/indoteknik_api/controllers/api_v1/user.py @@ -3,6 +3,7 @@ from odoo import http from odoo.http import request from odoo.tools.config import config import random, string +from difflib import SequenceMatcher class User(controller.Controller): @@ -62,20 +63,43 @@ class User(controller.Controller): return self.response(code=400, description='email, name and password is required') user = self.get_user_by_email(email) - if user: return self.response({ 'register': False, 'reason': 'EMAIL_USED' }) - - user = request.env['res.users'].create({ + + user_data = { 'name': name, 'login': email, 'password': password, 'active': False, 'sel_groups_1_9_10': 9 - }) + } + + user = request.env['res.users'].create(user_data) + + company = kw.get('company', False) + if company: + parameter = [ + ('company_type', '=', 'company'), + ('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, company).ratio() + if match_ratio > 0.7: + request.env['user.company.request'].create({ + 'user_id': user.partner_id.id, + 'user_company_id': match_company.id, + 'user_input': company + }) + else: + new_company = request.env['res.partner'].create({ + 'name': company + }) + user.parent_id = new_company.id return self.response({'register': True}) diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py index 243b3028..5a3ffe0a 100755 --- a/indoteknik_custom/__manifest__.py +++ b/indoteknik_custom/__manifest__.py @@ -25,6 +25,7 @@ 'views/sale_monitoring.xml', 'views/sale_monitoring_detail.xml', 'views/user_activity_log.xml', + 'views/user_company_request.xml', 'views/vit_kelurahan.xml', 'views/vit_kecamatan.xml', 'views/vit_kota.xml', diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py index 62a024e3..4cb8bdda 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -32,6 +32,7 @@ from . import stock_picking_type from . import stock_picking from . import stock_vendor from . import user_activity_log +from . import user_company_request from . import users from . import website_brand_homepage from . import website_categories_homepage diff --git a/indoteknik_custom/models/user_company_request.py b/indoteknik_custom/models/user_company_request.py new file mode 100644 index 00000000..c69b789c --- /dev/null +++ b/indoteknik_custom/models/user_company_request.py @@ -0,0 +1,15 @@ +from odoo import models, fields + + +class UserCompanyRequest(models.Model): + _name = 'user.company.request' + _rec_name = 'user_id' + + user_id = fields.Many2one('res.partner', string='User') + user_company_id = fields.Many2one('res.partner', string='Company') + user_input = fields.Char(string='User Input') + is_approve = fields.Selection([ + ('approved', 'Approve'), + ('rejected', 'Reject'), + ], string='Approval') + \ No newline at end of file diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv index 977f3a1b..26c1bd73 100755 --- a/indoteknik_custom/security/ir.model.access.csv +++ b/indoteknik_custom/security/ir.model.access.csv @@ -33,4 +33,5 @@ access_midtrans_recurring,access.midtrans.recurring,model_midtrans_recurring,,1, access_midtrans_account,access.midtrans.account,model_midtrans_account,,1,1,1,1 access_ip_lookup,access.ip.lookup,model_ip_lookup,,1,1,1,1 access_ip_lookup_line,access.ip.lookup.line,model_ip_lookup_line,,1,1,1,1 -access_wati_notification,access.wati.notification,model_wati_notification,,1,1,1,1 \ No newline at end of file +access_wati_notification,access.wati.notification,model_wati_notification,,1,1,1,1 +access_user_company_request,access.user.company.request,model_user_company_request,,1,1,1,1 \ No newline at end of file diff --git a/indoteknik_custom/views/user_company_request.xml b/indoteknik_custom/views/user_company_request.xml new file mode 100644 index 00000000..a44a48e0 --- /dev/null +++ b/indoteknik_custom/views/user_company_request.xml @@ -0,0 +1,49 @@ + + + + user.company.request.tree + user.company.request + + + + + + + + + + + + user.company.request.form + user.company.request + +
+ + + + + + + + + + +
+
+
+ + + User Company Request + ir.actions.act_window + user.company.request + tree,form + + + +
\ No newline at end of file -- cgit v1.2.3