diff options
| author | IT Fixcomart <it@fixcomart.co.id> | 2025-08-15 10:23:56 +0000 |
|---|---|---|
| committer | IT Fixcomart <it@fixcomart.co.id> | 2025-08-15 10:23:56 +0000 |
| commit | e67ef9896699133a6d65dca9c8c3ed3ce27c9f0c (patch) | |
| tree | 6dc62a192d8456bb7608bcca16836f3cc0dded95 | |
| parent | 8dd70f877c68abb3f0331e18f4652acb11e1bf84 (diff) | |
| parent | c9111bcf2c71a5dac6f13dc5aceb55956127a055 (diff) | |
Merged in fix-switch-account (pull request #386)
Fix switch account
| -rw-r--r-- | indoteknik_api/controllers/api_v1/user.py | 27 | ||||
| -rw-r--r-- | indoteknik_custom/models/user_company_request.py | 10 |
2 files changed, 28 insertions, 9 deletions
diff --git a/indoteknik_api/controllers/api_v1/user.py b/indoteknik_api/controllers/api_v1/user.py index b5b7e055..d134fc5a 100644 --- a/indoteknik_api/controllers/api_v1/user.py +++ b/indoteknik_api/controllers/api_v1/user.py @@ -396,7 +396,7 @@ class User(controller.Controller): 'user': request.env['res.users'].api_single_response(user) }) - @http.route(prefix + 'user/<id>', auth='public', methods=['PUT', 'OPTIONS'], csrf=False) + @http.route(prefix + 'user/<id>', auth='public', methods=['POST', 'OPTIONS'], csrf=False) @controller.Controller.must_authorized() def update_user(self, **kw): id = kw.get('id') @@ -446,7 +446,7 @@ class User(controller.Controller): return self.response(address) - @http.route(prefix + 'user/<id>/switch', auth='public', methods=['PUT', 'OPTIONS'], csrf=False) + @http.route(prefix + 'user/<id>/switch', auth='public', methods=['POST', 'OPTIONS'], csrf=False) @controller.Controller.must_authorized() def switch_account(self, **kw): id = int(kw.get('id')) @@ -489,7 +489,7 @@ class User(controller.Controller): if type_acc == 'business': parameter = [ - ('company_type', '=', 'company'), + ('is_company', '=', True), ('name', 'ilike', business_name) ] if parent_id: @@ -674,7 +674,7 @@ class User(controller.Controller): # request_company.send_company_request_mail_switch() request_company.send_company_request_mail_switch() - response['switch'] = 'Pending' + response['switch'] = 'pending' return self.response(response) @http.route(prefix + 'user/<id>/switch_progres', auth='public', methods=['GET', 'OPTIONS'], csrf=False) @@ -691,15 +691,28 @@ class User(controller.Controller): new_company_request = request.env['user.company.request'].search(parameter, limit=1) is_approve = '' if new_company_request: - # Mengambil nilai is_approve - if new_company_request.is_approve == False: + if not new_company_request.is_approve: # None atau '' response['status'] = 'pending' else: - response['status'] = new_company_request.is_approve + response['status'] = new_company_request.is_approve # 'approved' atau 'rejected' else: response['status'] = False return self.response(response) + # @http.route(prefix + 'user/<id>/parent_status', auth='public', methods=['GET', 'OPTIONS'], csrf=False) + # # @controller.Controller.must_authorized() + # def parent_status(self, **kw): + # id = int(kw.get('id')) + # response = { + # 'parentId': None, + # 'parentName': None + # } + # partner = request.env['res.partner'].sudo().search([('id', '=', id)], limit=1) + # if partner and partner.parent_id: + # response['parentId'] = partner.parent_id.id + # response['parentName'] = partner.parent_id.name + # return self.response(response) + def get_user_by_email(self, email): return request.env['res.users'].search([ ('login', '=', email), diff --git a/indoteknik_custom/models/user_company_request.py b/indoteknik_custom/models/user_company_request.py index 9216e8eb..284575aa 100644 --- a/indoteknik_custom/models/user_company_request.py +++ b/indoteknik_custom/models/user_company_request.py @@ -1,6 +1,9 @@ from odoo import models, fields, api from odoo.exceptions import UserError from odoo.http import request +import logging + +_logger = logging.getLogger(__name__) class UserCompanyRequest(models.Model): _name = 'user.company.request' @@ -65,8 +68,8 @@ class UserCompanyRequest(models.Model): is_approve = vals.get('is_approve') is_internal_input = vals.get('internal_input') is_company_id = vals.get('user_company_id') - if self.is_approve and is_approve: - raise UserError('Tidak dapat mengubah approval yang sudah diisi') + # if self.is_approve and is_approve: + # raise UserError('Tidak dapat mengubah approval yang sudah diisi') if is_internal_input: if self.user_company_id.nama_wajib_pajak == self.user_company_id.name: @@ -75,6 +78,7 @@ class UserCompanyRequest(models.Model): user_company_id = [] if is_company_id: user_company_id = request.env['res.partner'].search([('id', '=', is_company_id)], limit=1) + _logger.info('User Company ID: %s', user_company_id) # self.user_company_id.customer_type = self.similar_company_ids.customer_type # self.user_company_id.npwp = self.similar_company_ids.npwp # self.user_company_id.sppkp = self.similar_company_ids.sppkp @@ -101,6 +105,8 @@ class UserCompanyRequest(models.Model): self.user_id.property_account_payable_id = user_company_id.property_account_payable_id if user_company_id else self.user_company_id.property_account_payable_id self.user_id.property_payment_term_id = user_company_id.property_payment_term_id if user_company_id else self.user_company_id.property_payment_term_id self.user_id.property_supplier_payment_term_id = user_company_id.property_supplier_payment_term_id if user_company_id else self.user_company_id.property_supplier_payment_term_id + # self.user_id.is_company = True + # self.user_id.active = True self.user_company_id.active = True user.send_company_switch_approve_mail() if vals.get('is_switch_account') == True else user.send_company_request_approve_mail() else: |
