summaryrefslogtreecommitdiff
path: root/indoteknik_api/controllers/api_v1
diff options
context:
space:
mode:
authorit-fixcomart <it@fixcomart.co.id>2025-01-21 13:53:28 +0700
committerit-fixcomart <it@fixcomart.co.id>2025-01-21 13:53:28 +0700
commit63433ff471ba98e6fc63bca16abd9a585471498b (patch)
tree7fe83758b1c40888bab68f5498e4a1c7da4d7891 /indoteknik_api/controllers/api_v1
parentff20b62d6932c6be4ffb56f63f3c05be3aa72c06 (diff)
parente3521c2153c36cee6629cee9146e1b4b0201da9f (diff)
Merge branch 'odoo-production' into CR/form-merchant
# Conflicts: # indoteknik_api/models/res_partner.py # indoteknik_api/models/res_users.py # indoteknik_custom/__manifest__.py # indoteknik_custom/models/__init__.py # indoteknik_custom/models/res_partner.py # indoteknik_custom/security/ir.model.access.csv # indoteknik_custom/views/res_partner.xml # indoteknik_custom/views/user_company_request.xml
Diffstat (limited to 'indoteknik_api/controllers/api_v1')
-rw-r--r--indoteknik_api/controllers/api_v1/invoice.py25
-rw-r--r--indoteknik_api/controllers/api_v1/lead.py2
-rw-r--r--indoteknik_api/controllers/api_v1/partner.py360
-rw-r--r--indoteknik_api/controllers/api_v1/state.py6
-rw-r--r--indoteknik_api/controllers/api_v1/user.py353
5 files changed, 676 insertions, 70 deletions
diff --git a/indoteknik_api/controllers/api_v1/invoice.py b/indoteknik_api/controllers/api_v1/invoice.py
index 4937e8dd..4bd3746c 100644
--- a/indoteknik_api/controllers/api_v1/invoice.py
+++ b/indoteknik_api/controllers/api_v1/invoice.py
@@ -1,7 +1,7 @@
from .. import controller
from odoo import http
from odoo.http import request
-
+from odoo import fields
class Invoice(controller.Controller):
PREFIX = '/api/v1/'
@@ -15,6 +15,7 @@ class Invoice(controller.Controller):
'name': [],
'limit': ['default:0', 'number'],
'offset': ['default:0', 'number'],
+ 'status': [],
})
limit = params['value']['limit']
offset = params['value']['offset']
@@ -27,6 +28,11 @@ class Invoice(controller.Controller):
('state', '=', 'posted'),
('partner_id', 'in', partner_child_ids)
]
+ domain_orders = [
+ ('invoice_status', '!=', 'invoiced'),
+ ('state', '=', 'sale'),
+ ('partner_id', 'in', partner_child_ids)
+ ]
if params['value']['name']:
name = params['value']['name'].replace(' ', '%')
domain += [
@@ -34,10 +40,25 @@ class Invoice(controller.Controller):
('name', 'ilike', '%'+ name +'%'),
('ref', 'ilike', '%'+ name +'%')
]
+ if params['value']['status']:
+ if params['value']['status'] == '1':
+ domain += [('payment_state', '=', 'not_paid'), ('invoice_date_due', '<', fields.Date.today())]
+ elif params['value']['status'] == '2':
+ domain += [('payment_state', '=', 'not_paid'), ('invoice_date_due', '>', fields.Date.today())]
+ elif params['value']['status'] == '3':
+ domain += [('payment_state', '=', 'paid')]
+ elif params['value']['status'] == '0':
+ domain = domain
+ elif params['value']['status'] == '4':
+ domain += [('payment_state', '=', 'not_paid')]
+
invoices = request.env['account.move'].search(domain, offset=offset, limit=limit)
+ sale_orders = request.env['sale.order'].search(domain_orders, offset=offset, limit=limit)
data = {
'invoice_total': request.env['account.move'].search_count(domain),
- 'invoices': [request.env['account.move'].api_v1_single_response(x) for x in invoices]
+ 'invoices': [request.env['account.move'].api_v1_single_response(x) for x in invoices],
+ 'sale_order_total': request.env['sale.order'].search_count(domain_orders),
+ 'sale_orders': [request.env['sale.order'].api_v1_single_response(x) for x in sale_orders]
}
return self.response(data)
diff --git a/indoteknik_api/controllers/api_v1/lead.py b/indoteknik_api/controllers/api_v1/lead.py
index 7ff8a8e9..f2793838 100644
--- a/indoteknik_api/controllers/api_v1/lead.py
+++ b/indoteknik_api/controllers/api_v1/lead.py
@@ -216,5 +216,5 @@ class Lead(controller.Controller):
form_merchant = request.env['user.form.merchant'].search([('partner_id', '=', main_partner.id)],limit=1)
if not form_merchant:
return self.response(code=404, description='form merchant not found')
- form_merchant = request.env['res.partner'].api_single_response(form_merchant)
+ form_merchant = request.env['res.partner'].api_single_response_merchant(form_merchant)
return self.response(form_merchant)
diff --git a/indoteknik_api/controllers/api_v1/partner.py b/indoteknik_api/controllers/api_v1/partner.py
index bbca471b..307165b3 100644
--- a/indoteknik_api/controllers/api_v1/partner.py
+++ b/indoteknik_api/controllers/api_v1/partner.py
@@ -1,7 +1,10 @@
from .. import controller
from odoo import http
from odoo.http import request
-
+from odoo import fields
+import json
+import base64
+import mimetypes
class Partner(controller.Controller):
_name = 'res.partner'
@@ -135,14 +138,12 @@ class Partner(controller.Controller):
'npwp': [],
'alamat_lengkap_text': [],
'street': [],
+ 'email': [],
+ 'mobile': []
})
-
- # Mengambil id_user dari request
id_user = self.get_request_params(kw, {
'id_user': ['number']
})
-
- # Mengambil parameter user dari request
params_user = self.get_request_params(kw, {
'company_type_id': ['number'],
'industry_id': ['number'],
@@ -151,17 +152,26 @@ class Partner(controller.Controller):
'alamat_lengkap_text': [],
})
- # Cek validitas parameter
if not params['valid']:
return self.response(code=400, description=params)
- # Mencari partner dan user berdasarkan ID
partner = request.env[self._name].search([('id', '=', params['value']['id'])], limit=1)
user = request.env[self._name].search([('id', '=', id_user['value']['id_user'])], limit=1)
-
if not partner:
return self.response(code=404, description='Partner not found')
+ if not params['value'].get('tax_name'):
+ params['value']['nama_wajib_pajak'] = params['value'].get('name')
+ params_user['value']['nama_wajib_pajak'] = params_user['value'].get('name')
+
+ if not params['value'].get('alamat_lengkap_text'):
+ params['value']['alamat_lengkap_text'] = params['value'].get('street')
+ params_user['value']['alamat_lengkap_text'] = params_user['value'].get('street')
+
+ if not params['value'].get('npwp'):
+ params['value']['npwp'] = "00.000.000.0-000.000"
+ params_user['value']['npwp'] = "00.000.000.0-000.000"
+
# Filter parameter yang memiliki nilai saja untuk partner
params_filtered = {k: v for k, v in params['value'].items() if v}
@@ -208,6 +218,32 @@ class Partner(controller.Controller):
})
return self.response(data)
+
+ @http.route(prefix + 'partner/payment_term', auth='public', methods=['GET', 'OPTIONS'])
+ @controller.Controller.must_authorized()
+ def get_partner_payment_term(self):
+ partner_industry = request.env['account.payment.term'].search([])
+ data = []
+ for industry in partner_industry:
+ if 'tempo' in industry.name.lower():
+ data.append({
+ 'id': industry.id,
+ 'name': industry.name
+ })
+
+ return self.response(data)
+
+ @http.route(prefix + 'partner/detail-tempo/<id>', auth='public', methods=['GET', 'OPTIONS'])
+ @controller.Controller.must_authorized()
+ def get_partner_detail_tempo(self, **kw):
+ params = self.get_request_params(kw, {
+ 'id': ['required', 'number']
+ })
+ pengajuan_tempo = request.env['user.pengajuan.tempo'].search([('name_tempo', '=', params['value']['id'])], limit=1)
+ if not pengajuan_tempo:
+ return self.response(code=404, description='pengajuan tempo not found')
+ pengajuan_tempo = request.env['res.partner'].api_single_response(pengajuan_tempo)
+ return self.response(pengajuan_tempo)
@http.route(prefix + 'check/<partner_id>/tempo', auth='public', methods=['GET', 'OPTIONS'])
@controller.Controller.must_authorized()
@@ -222,18 +258,318 @@ class Partner(controller.Controller):
if any(line.days == 0 for line in partner.property_payment_term_id.line_ids):
return self.response(code=402, description='Partner not tempo')
-
- result_tempo = sum(m.amount_total_signed for m in request.env['account.move'].search([('partner_id', '=', partner.id), ('payment_state', '=', 'not_paid'), ('state', '=', 'posted')]))
-
+
+ domain_result_tempo = [('partner_id', '=', partner.id), ('payment_state', '=', 'not_paid'), ('state', '=', 'posted')]
+ domain_result_jatuh_tempo = [('partner_id', '=', partner.id), ('payment_state', '=', 'not_paid'), ('state', '=', 'posted'), ('invoice_date_due', '<', fields.Date.today())]
+ domain_orders = [('partner_id', '=', partner.id), ('invoice_status', '!=', 'invoiced'), ('state', '=', 'sale')]
+
+ result_tempo = sum(m.amount_total_signed for m in request.env['account.move'].search(domain_result_tempo))
+ result_tempo_total = request.env['account.move'].search_count(domain_result_tempo)
+ result_jatuh_tempo = sum(m.amount_total_signed for m in request.env['account.move'].search(domain_result_jatuh_tempo))
+ result_jatuh_tempo_total = request.env['account.move'].search_count(domain_result_jatuh_tempo)
+ orders = request.env['sale.order'].search(domain_orders)
+ orders_total = request.env['sale.order'].search_count(domain_orders)
+
+ total_amount = sum(order.amount_total for order in orders)
+
remaining_limit = partner.blocking_stage - result_tempo if partner.active_limit else None
data = {
'name': partner.name,
+ 'payment_term': partner.property_payment_term_id.name,
'amount_due': result_tempo,
+ 'amount_due_total': result_tempo_total,
+ 'amount_jatuh_tempo_total': result_jatuh_tempo_total,
+ 'amount_jatuh_tempo': result_jatuh_tempo,
+ 'amount_due_sale': total_amount,
+ 'amount_due_sale_total': orders_total,
'remaining_limit': remaining_limit
}
-
+
return self.response(data)
+ @http.route(prefix + 'check/<partner_id>/tempo_progress', auth='public', methods=['GET', 'OPTIONS'])
+ @controller.Controller.must_authorized()
+ def get_check_tempo_partner_progres(self, **kw):
+ partner_id = int(kw.get('partner_id'))
+ partner = request.env['res.partner'].search([('id', '=', partner_id)], limit=1)
+ pengajuan_tempo = request.env['user.pengajuan.tempo'].search([('name_tempo', '=', partner.id)], limit=1)
+ if not pengajuan_tempo:
+ return self.response(code=404, description='Partner not found')
+
+ data = True if pengajuan_tempo.id else False
+ return self.response(data)
+ @http.route(prefix + 'partner/pengajuan_tempo', auth='public', methods=['POST'], csrf=False)
+ @controller.Controller.must_authorized()
+ def write_pengajuan_tempo(self, **kw):
+ id = int(kw.get('partner_id'))
+ user_id = int(kw.get('user_id'))
+ tempo_request = True if kw.get('tempo_request') == 'true' else False
+ pengajuan_tempo = request.env['user.pengajuan.tempo'].search([('name_tempo', '=', user_id)], limit=1)
+ user = request.env['res.partner'].search([('id', '=', user_id)], limit=1)
+ company_name = kw.get('name', pengajuan_tempo.name_tempo.name)
+ partner_id = request.env['res.partner'].search([('name', 'like', company_name)], limit=1)
+ user_account = self.get_user_by_email(user.email)
+
+ params = self.get_request_params(kw, {
+
+ # informasi perusahaan
+ # 'name': ['required', 'alias:name_tempo'],
+ 'industryId': ['alias:industry_id_tempo'],
+ 'street': ['alias:street_tempo'],
+ 'state': ['alias:state_id_tempo'],
+ 'city': ['alias:city_id_tempo'],
+ 'district': ['alias:district_id_tempo'],
+ 'subDistrict': ['alias:subDistrict_id_tempo'],
+ 'zip': ['alias:zip_tempo'],
+ 'mobile': ['alias:mobile_tempo'],
+ 'bankName': ['alias:bank_name_tempo'],
+ 'accountName': ['alias:account_name_tempo'],
+ 'accountNumber': ['alias:account_number_tempo'],
+ 'website': ['alias:website_tempo'],
+ 'estimasi': ['alias:estimasi_tempo'],
+ 'portal': ['alias:portal'],
+ 'bersedia': ['alias:bersedia'],
+ 'tempoDuration': ['alias:tempo_duration'],
+ 'tempoLimit': ['alias:tempo_limit'],
+
+ # informasi perusahaan
+ 'direkturTittle': ['alias:direktur_tittle'],
+ 'direkturName': ['alias:direktur_name'],
+ 'direkturMobile': ['alias:direktur_mobile'],
+ 'direkturEmail': ['alias:direktur_email'],
+ 'purchasingTittle': ['alias:purchasing_tittle'],
+ 'purchasingName': ['alias:purchasing_name'],
+ 'purchasingMobile': ['alias:purchasing_mobile'],
+ 'purchasingEmail': ['alias:purchasing_email'],
+ 'financeTittle': ['alias:finance_tittle'],
+ 'financeName': ['alias:finance_name'],
+ 'financeMobile': ['alias:finance_mobile'],
+ 'financeEmail': ['alias:finance_email'],
+
+ # Pengiriman
+ 'PICTittle': ['alias:pic_tittle'],
+ 'PICName': ['alias:pic_name'],
+ 'streetPengiriman': ['alias:street_pengiriman'],
+ 'statePengiriman': ['alias:state_id_pengiriman'],
+ 'cityPengiriman': ['alias:city_id_pengiriman'],
+ 'districtPengiriman': ['alias:district_id_pengiriman'],
+ 'subDistrictPengiriman': ['alias:subDistrict_id_pengiriman'],
+ 'zipPengiriman': ['alias:zip_pengiriman'],
+ 'invoicePicTittle': ['alias:invoice_pic_tittle'],
+ 'invoicePic': ['alias:invoice_pic'],
+ 'streetInvoice': ['alias:street_invoice'],
+ 'stateInvoice': ['alias:state_id_invoice'],
+ 'cityInvoice': ['alias:city_id_invoice'],
+ 'districtInvoice': ['alias:district_id_invoice'],
+ 'subDistrictInvoice': ['alias:subDistrict_id_invoice'],
+ 'zipInvoice': ['alias:zip_invoice'],
+ 'isSameAddrees':['alias:is_same_address'],
+ 'isSameAddreesStreet':['alias:is_same_address_street'],
+ })
+
+ # # Konversi nilai 'true' ke boolean True
+ # is_same_address = kw.get('isSameAddrees', 'false').lower() == 'true'
+ # is_same_address_street = kw.get('isSameAddreesStreet', 'false').lower() == 'true'
+ #
+ # # Tambahkan nilai yang dikonversi ke params
+ # if 'isSameAddress' in kw:
+ # params['value']['is_same_address'] = is_same_address
+ # if 'is_same_address_street' in kw:
+ # params['value']['is_same_address_street'] = is_same_address_street
+
+ if not params['valid']:
+ return self.response(code=400, description=params)
+ if params['value']['portal']:
+ if params['value']['portal'] == 'ada':
+ params['value']['portal'] = True
+ else:
+ params['value']['portal'] = False
+ # Filter data baru yang dikirim (non-kosong, boolean False tetap masuk)
+ new_data = {key: value for key, value in params['value'].items() if value != ''}
+
+ if pengajuan_tempo:
+ # Jika pengajuan_tempo sudah ada, hanya write data baru yang non-kosong
+ pengajuan_tempo.write(new_data)
+ else:
+ # Jika belum ada, buat record baru
+ pengajuan_tempo = request.env['user.pengajuan.tempo'].create(new_data)
+ pengajuan_tempo.partner_id = user_id
+
+ if partner_id:
+ pengajuan_tempo.name_tempo = partner_id
+
+ form_supplier_data = kw.get('formSupplier', False)
+
+ if form_supplier_data:
+ try:
+ form_supplier_data = json.loads(form_supplier_data)
+
+ supplier_ids_to_add = []
+ for item in form_supplier_data:
+ supplier_name = item.get("supplier")
+ pic_name = item.get("pic")
+ phone = item.get("telepon")
+ tempo_duration = item.get("durasiTempo")
+ credit_limit = item.get("creditLimit")
+
+ new_data = {
+ 'name_supplier': supplier_name,
+ 'pic_name': pic_name,
+ 'phone': phone,
+ 'tempo_duration': tempo_duration,
+ 'credit_limit': credit_limit,
+ }
+ new_supplier_data = request.env['user.pengajuan.tempo.line'].create(new_data)
+
+ supplier_ids_to_add.append(new_supplier_data.id)
+
+ pengajuan_tempo.write({'supplier_ids': [(6, 0, supplier_ids_to_add)]})
+
+ except json.JSONDecodeError:
+ return http.Response(status=400, json_body={'error': 'Invalid JSON format for formSupplier'})
+ category_produk_ids = kw.get('categoryProduk', False)
+ category_ids = ''
+ if category_produk_ids:
+ category_ids = list(map(int, category_produk_ids.split(',')))
+ pengajuan_tempo.category_produk_ids = [(6, 0, category_ids)]
+
+ tukar_invoice_input = kw.get('tukarInvoiceInput')
+ if tukar_invoice_input:
+ pengajuan_tempo.tukar_invoice = tukar_invoice_input
+
+ tukar_invoice_input_pembayaran = kw.get('tukarInvoiceInputPembayaran')
+ if tukar_invoice_input_pembayaran:
+ pengajuan_tempo.jadwal_bayar = tukar_invoice_input_pembayaran
+
+ dokumen_kirim = [
+ 'Surat Tanda Terima Barang (STTB)',
+ 'Good Receipt (GR)',
+ 'Surat Terima Barang (STB)',
+ 'Lembar Penerimaan Barang (LPB)'
+ ]
+
+ dokumen_kirim_barang_ids = kw.get('dokumenPengiriman')
+ dokumen_kirim_input = kw.get('dokumenKirimInput', '')
+ dokumen_kirim_barang_input = kw.get('dokumenPengirimanInput', '')
+ dokumen_kirim_barang = []
+
+ if dokumen_kirim_barang_ids:
+ dokumen_kirim_ids = list(map(int, dokumen_kirim_barang_ids.split(',')))
+ dokumen_kirim_barang = [dokumen_kirim[i] for i in dokumen_kirim_ids if 0 <= i < len(dokumen_kirim)]
+ if dokumen_kirim_input:
+ input_items = [item.strip() for item in dokumen_kirim_input.split(',')]
+ dokumen_kirim_barang.extend(item for item in input_items if item and item not in dokumen_kirim_barang)
+ pengajuan_tempo.dokumen_kirim_input = dokumen_kirim_input
+ if dokumen_kirim_barang:
+ pengajuan_tempo.dokumen_pengiriman = ', '.join(dokumen_kirim_barang)
+ if dokumen_kirim_barang_input:
+ pengajuan_tempo.dokumen_pengiriman_input = dokumen_kirim_barang_input
+
+ dokumen = [
+ 'Invoice Pembelian',
+ 'Surat Jalan',
+ 'Berita Acara Serah Terima (BAST)',
+ 'Faktur Pajak',
+ 'Good Receipt (GR)'
+ ]
+
+ dokumen_invoice = kw.get('dokumenPengirimanInvoice', '')
+ if dokumen_invoice:
+ pengajuan_tempo.dokumen_invoice = dokumen_invoice
+ user_tempo_request = []
+ if tempo_request:
+ user_tempo_request = request.env['user.pengajuan.tempo.request'].create({
+ 'user_id': id,
+ 'pengajuan_tempo_id': pengajuan_tempo.id,
+ 'user_company_id': partner_id.id,
+ 'tempo_duration': pengajuan_tempo.tempo_duration.id,
+ 'tempo_limit': pengajuan_tempo.tempo_limit,
+ })
+
+ form_dokumen_data = kw.get('formDocs', False)
+ if form_dokumen_data:
+ try:
+ form_dokumen = json.loads(form_dokumen_data)
+
+ for dokumen in form_dokumen:
+ if dokumen['details']['base64'] != '':
+ mimetype, _ = mimetypes.guess_type(dokumen['details']['name'])
+ mimetype = mimetype or 'application/octet-stream'
+ data = base64.b64decode(dokumen['details']['base64'])
+ sppkp_attachment = request.env['ir.attachment'].create({
+ 'name': dokumen['details']['name'],
+ 'type': 'binary',
+ 'datas': base64.b64encode(data),
+ 'res_model': 'user.pengajuan.tempo',
+ 'res_id': pengajuan_tempo.id,
+ 'mimetype': mimetype
+ })
+
+ if dokumen['documentName'] == 'dokumenNib':
+ pengajuan_tempo.dokumen_nib = [(6, 0, [sppkp_attachment.id])]
+
+ elif dokumen['documentName'] == 'dokumenSiup':
+ pengajuan_tempo.dokumen_siup = [(6, 0, [sppkp_attachment.id])]
+
+ elif dokumen['documentName'] == 'dokumenTdp':
+ pengajuan_tempo.dokumen_tdp = [(6, 0, [sppkp_attachment.id])]
+
+ elif dokumen['documentName'] == 'dokumenSkdp':
+ pengajuan_tempo.dokumen_skdp = [(6, 0, [sppkp_attachment.id])]
+
+ elif dokumen['documentName'] == 'dokumenSkt':
+ pengajuan_tempo.dokumen_skt = [(6, 0, [sppkp_attachment.id])]
+
+ elif dokumen['documentName'] == 'dokumenNpwp':
+ pengajuan_tempo.dokumen_npwp = [(6, 0, [sppkp_attachment.id])]
+
+ elif dokumen['documentName'] == 'dokumenSppkp':
+ pengajuan_tempo.dokumen_sppkp = [(6, 0, [sppkp_attachment.id])]
+
+ elif dokumen['documentName'] == 'dokumenAktaPerubahan':
+ pengajuan_tempo.dokumen_akta_perubahan = [(6, 0, [sppkp_attachment.id])]
+
+ elif dokumen['documentName'] == 'dokumenKtpDirut':
+ pengajuan_tempo.dokumen_ktp_dirut = [(6, 0, [sppkp_attachment.id])]
+
+ elif dokumen['documentName'] == 'dokumenAktaPendirian':
+ pengajuan_tempo.dokumen_akta_pendirian = [(6, 0, [sppkp_attachment.id])]
+
+ elif dokumen['documentName'] == 'dokumenLaporanKeuangan':
+ pengajuan_tempo.dokumen_laporan_keuangan = [(6, 0, [sppkp_attachment.id])]
+
+ elif dokumen['documentName'] == 'dokumenFotoKantor':
+ pengajuan_tempo.dokumen_foto_kantor = [(6, 0, [sppkp_attachment.id])]
+
+ elif dokumen['documentName'] == 'dokumenTempatBekerja':
+ pengajuan_tempo.dokumen_tempat_bekerja = [(6, 0, [sppkp_attachment.id])]
+
+ formatted_text = ''.join([' ' + char if char.isupper() and i != 0 else char for i, char in
+ enumerate(dokumen['documentName'])])
+ teks = formatted_text.strip().title()
+ pengajuan_tempo.message_post(body=teks, attachment_ids=[sppkp_attachment.id])
+ if tempo_request:
+ user_tempo_request.message_post(body=teks, attachment_ids=[sppkp_attachment.id])
+
+
+ except json.JSONDecodeError:
+ return http.Response(status=400, json_body={'error': 'Invalid JSON format for formDokumen'})
+
+ if tempo_request:
+ # pengajuan_tempo.user_id = id
+ template = pengajuan_tempo.env.ref('indoteknik_custom.mail_template_res_user_company_request_tempo_review')
+ template.send_mail(pengajuan_tempo.id, force_send=True)
+ template2 = pengajuan_tempo.env.ref('indoteknik_custom.mail_template_res_user_company_new_tempo_to_sales')
+ template2.send_mail(pengajuan_tempo.id, force_send=True)
+ return self.response({
+ 'id': pengajuan_tempo.id,
+ 'user_id': user_id,
+ })
+ def get_user_by_email(self, email):
+ return request.env['res.users'].search([
+ ('login', '=', email),
+ ('active', 'in', [True, False])
+ ]) \ No newline at end of file
diff --git a/indoteknik_api/controllers/api_v1/state.py b/indoteknik_api/controllers/api_v1/state.py
index 598ef70b..958359a7 100644
--- a/indoteknik_api/controllers/api_v1/state.py
+++ b/indoteknik_api/controllers/api_v1/state.py
@@ -8,7 +8,11 @@ class District(controller.Controller):
@http.route(prefix + 'state', auth='public', methods=['GET', 'OPTIONS'])
@controller.Controller.must_authorized()
def get_state(self, **kw):
+ tempo = kw.get('tempo')
parameters = []
+ if tempo == 'true':
+ parameters.append(('country_id', '=', 100))
+
name = kw.get('name')
if name:
@@ -18,7 +22,7 @@ class District(controller.Controller):
states = request.env['res.country.state'].search(parameters)
data = []
for state in states:
- data.append({ 'id': state.id, 'name': state.name })
+ data.append({ 'id': state.id, 'name': state.name})
return self.response(data)
diff --git a/indoteknik_api/controllers/api_v1/user.py b/indoteknik_api/controllers/api_v1/user.py
index 3be874fa..f71af89f 100644
--- a/indoteknik_api/controllers/api_v1/user.py
+++ b/indoteknik_api/controllers/api_v1/user.py
@@ -130,6 +130,7 @@ class User(controller.Controller):
alamat_bisnis = kw.get('alamat_bisnis', False)
nama_wajib_pajak = kw.get('nama_wajib_pajak', False)
is_pkp = kw.get('is_pkp')
+ is_terdaftar = kw.get('is_terdaftar', False)
type_acc = kw.get('type_acc', 'individu') or 'individu'
if not name or not email or not password:
@@ -168,7 +169,7 @@ class User(controller.Controller):
if type_acc == 'business' and business_name:
# Eksekusi query SQL menggunakan Levenshtein distance
query = """
- SELECT name, levenshtein(name::text, %s) AS distance
+ SELECT id, name, levenshtein(name::text, %s) AS distance
FROM res_partner
WHERE levenshtein(name::text, %s) < 3
ORDER BY distance ASC
@@ -177,9 +178,9 @@ class User(controller.Controller):
request.env.cr.execute(query, params)
result = request.env.cr.fetchone()
- if result:
- match_company_name = result[0]
- match_company_id = result[2]
+ if result and is_terdaftar:
+ match_company_name = result[2]
+ match_company_id = result[0]
# Create a user company request
request.env['user.company.request'].create({
@@ -403,6 +404,20 @@ class User(controller.Controller):
'user': self.response_with_token(user)
})
+ @http.route(prefix + 'user/<id>/after_request_tempo', auth='public', methods=['PUT', 'OPTIONS'], csrf=False)
+ @controller.Controller.must_authorized()
+ def update_user_tempo_after_request(self, **kw):
+ id = kw.get('id')
+
+ user = request.env['res.users'].search([('id', '=', id)], limit=1)
+ if not user:
+ return self.response(code=404, description='User not found')
+
+
+ return self.response({
+ 'user': self.response_with_token(user)
+ })
+
@http.route(prefix + 'user/<id>/address', auth='public', methods=['GET', 'OPTIONS'])
@controller.Controller.must_authorized()
def get_user_address_by_id(self, **kw):
@@ -423,8 +438,8 @@ class User(controller.Controller):
@http.route(prefix + 'user/<id>/switch', auth='public', methods=['PUT', 'OPTIONS'], csrf=False)
@controller.Controller.must_authorized()
def switch_account(self, **kw):
- id = kw.get('id')
- user = request.env['res.users'].search([('id', '=', id)], limit=1)
+ id = int(kw.get('id'))
+ user = request.env['res.partner'].search([('id', '=', id)], limit=1)
response = {
'switch': False,
@@ -447,7 +462,14 @@ class User(controller.Controller):
nama_wajib_pajak = kw.get('nama_wajib_pajak', False)
is_pkp = kw.get('is_pkp')
type_acc = kw.get('type_acc', False)
-
+ parent_id = kw.get('parent_id', False)
+ if parent_id:
+ try:
+ parent_id = int(parent_id)
+ except ValueError:
+ parent_id = False
+ else:
+ parent_id = False
response = {
'switch': False,
@@ -459,55 +481,23 @@ class User(controller.Controller):
('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:
- # Create a user company request
- request.env['user.company.request'].create({
- 'user_id': user.partner_id.id,
- 'user_company_id': match_company.id,
- 'user_input': business_name
- })
- else:
- if not nama_wajib_pajak and is_pkp == 'false':
- nama_wajib_pajak = business_name
-
- if not alamat_wajib_pajak and is_pkp == 'false':
- alamat_wajib_pajak = alamat_bisnis
-
- new_company_data = {
+ if parent_id:
+ match_company = request.env['res.partner'].search([('id', '=', parent_id)], limit=1)
+ new_data = {
+ 'email': email_partner,
+ 'customer_type': 'pkp' if is_pkp == 'true' else 'nonpkp',
'name': business_name if business_name else business_name,
'company_type_id': company_type_id if company_type_id else False,
'industry_id': industry_id,
- 'customer_type': 'pkp' if is_pkp == 'true' else 'nonpkp',
'npwp': npwp if is_pkp == 'true' else (npwp if npwp else '00.000.000.0-000.000'),
'sppkp': sppkp if is_pkp == 'true' else (sppkp if sppkp else '-'),
'nama_wajib_pajak': nama_wajib_pajak,
'alamat_lengkap_text': alamat_wajib_pajak,
- 'email': email_partner,
'street': alamat_bisnis,
- 'company_type': 'company',
- 'user_id': 3222,
- 'property_account_receivable_id': 395,
- 'property_account_payable_id': 438,
- 'active': False,
}
- new_company = request.env['res.partner'].create(new_company_data)
- request.env['user.company.request'].create({
- 'user_id': user.partner_id.id,
- 'user_company_id': new_company.id,
- 'user_input': business_name
- })
- # user.partner_id.parent_id = new_company.id
- # user.partner_id.customer_type = new_company.customer_type
- # user.partner_id.npwp = new_company.npwp
- # user.partner_id.sppkp = new_company.sppkp
- # user.partner_id.nama_wajib_pajak = new_company.nama_wajib_pajak
- # user.partner_id.alamat_lengkap_text = new_company.alamat_lengkap_text
+ match_company.write(new_data)
- if npwp_document:
+ if npwp_document != ' ':
npwp_mimetype, _ = mimetypes.guess_type(npwp_filename)
npwp_mimetype = npwp_mimetype or 'application/octet-stream'
pdf_data = base64.b64decode(npwp_document)
@@ -516,12 +506,12 @@ class User(controller.Controller):
'type': 'binary',
'datas': base64.b64encode(pdf_data),
'res_model': 'res.partner',
- 'res_id': new_company.id,
+ 'res_id': match_company.id,
'mimetype': npwp_mimetype
})
- new_company.message_post(body="NPWP Uploaded", attachment_ids=[npwp_attachment.id])
+ match_company.message_post(body="NPWP Uploaded", attachment_ids=[npwp_attachment.id])
- if sppkp_document:
+ if sppkp_document != ' ':
sppkp_mimetype, _ = mimetypes.guess_type(sppkp_filename)
sppkp_mimetype = sppkp_mimetype or 'application/octet-stream'
pdf_data = base64.b64decode(sppkp_document)
@@ -530,11 +520,149 @@ class User(controller.Controller):
'type': 'binary',
'datas': base64.b64encode(pdf_data),
'res_model': 'res.partner',
- 'res_id': new_company.id,
+ 'res_id': match_company.id,
'mimetype': sppkp_mimetype
})
- new_company.message_post(body="SPPKP Uploaded", attachment_ids=[sppkp_attachment.id])
-
+ match_company.message_post(body="SPPKP Uploaded", attachment_ids=[sppkp_attachment.id])
+ request.env['user.company.request'].create({
+ 'user_id': user.id,
+ 'user_company_id': match_company.id,
+ 'user_input': business_name,
+ 'is_switch_account': True
+ })
+ else:
+ 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 user.parent_id :
+ new_data = {
+ 'email': email_partner,
+ 'customer_type': 'pkp' if is_pkp == 'true' else 'nonpkp',
+ 'name': business_name if business_name else business_name,
+ 'company_type_id': company_type_id if company_type_id else False,
+ 'industry_id': industry_id,
+ 'npwp': npwp if is_pkp == 'true' else (npwp if npwp else '00.000.000.0-000.000'),
+ 'sppkp': sppkp if is_pkp == 'true' else (sppkp if sppkp else '-'),
+ 'nama_wajib_pajak': nama_wajib_pajak,
+ 'alamat_lengkap_text': alamat_wajib_pajak,
+ 'street': alamat_bisnis,
+ }
+ match_company.write(new_data)
+
+ if npwp_document != ' ':
+ npwp_mimetype, _ = mimetypes.guess_type(npwp_filename)
+ npwp_mimetype = npwp_mimetype or 'application/octet-stream'
+ pdf_data = base64.b64decode(npwp_document)
+ npwp_attachment = request.env['ir.attachment'].create({
+ 'name': 'NPWP Document',
+ 'type': 'binary',
+ 'datas': base64.b64encode(pdf_data),
+ 'res_model': 'res.partner',
+ 'res_id': match_company.id,
+ 'mimetype': npwp_mimetype
+ })
+ match_company.message_post(body="NPWP Uploaded", attachment_ids=[npwp_attachment.id])
+
+ if sppkp_document != ' ':
+ sppkp_mimetype, _ = mimetypes.guess_type(sppkp_filename)
+ sppkp_mimetype = sppkp_mimetype or 'application/octet-stream'
+ pdf_data = base64.b64decode(sppkp_document)
+ sppkp_attachment = request.env['ir.attachment'].create({
+ 'name': 'SPPKP Document',
+ 'type': 'binary',
+ 'datas': base64.b64encode(pdf_data),
+ 'res_model': 'res.partner',
+ 'res_id': match_company.id,
+ 'mimetype': sppkp_mimetype
+ })
+ match_company.message_post(body="SPPKP Uploaded", attachment_ids=[sppkp_attachment.id])
+ else:
+ # Create a user company request
+ request.env['user.company.request'].create({
+ 'user_id': user.id,
+ 'user_company_id': match_company.id,
+ 'user_input': business_name
+ })
+ else:
+ if not nama_wajib_pajak and is_pkp == 'false':
+ nama_wajib_pajak = business_name
+
+ if not alamat_wajib_pajak and is_pkp == 'false':
+ alamat_wajib_pajak = alamat_bisnis
+
+ new_company_data = {
+ 'name': business_name if business_name else business_name,
+ 'company_type_id': company_type_id if company_type_id else False,
+ 'industry_id': industry_id,
+ 'customer_type': 'pkp' if is_pkp == 'true' else 'nonpkp',
+ 'npwp': npwp if is_pkp == 'true' else (npwp if npwp else '00.000.000.0-000.000'),
+ 'sppkp': sppkp if is_pkp == 'true' else (sppkp if sppkp else '-'),
+ 'nama_wajib_pajak': nama_wajib_pajak,
+ 'alamat_lengkap_text': alamat_wajib_pajak,
+ 'email': email_partner,
+ 'street': alamat_bisnis,
+ 'company_type': 'company',
+ 'user_id': 3222,
+ 'property_account_receivable_id': 395,
+ 'property_account_payable_id': 438,
+ 'active': False,
+ }
+ new_company = request.env['res.partner'].create(new_company_data)
+ request.env['user.company.request'].create({
+ 'user_id': user.id,
+ 'user_company_id': new_company.id,
+ 'user_input': business_name
+ })
+ # user.partner_id.parent_id = new_company.id
+ # user.partner_id.customer_type = new_company.customer_type
+ # user.partner_id.npwp = new_company.npwp
+ # user.partner_id.sppkp = new_company.sppkp
+ # user.partner_id.nama_wajib_pajak = new_company.nama_wajib_pajak
+ # user.partner_id.alamat_lengkap_text = new_company.alamat_lengkap_text
+
+ if npwp_document:
+ npwp_mimetype, _ = mimetypes.guess_type(npwp_filename)
+ npwp_mimetype = npwp_mimetype or 'application/octet-stream'
+ pdf_data = base64.b64decode(npwp_document)
+ npwp_attachment = request.env['ir.attachment'].create({
+ 'name': 'NPWP Document',
+ 'type': 'binary',
+ 'datas': base64.b64encode(pdf_data),
+ 'res_model': 'res.partner',
+ 'res_id': new_company.id,
+ 'mimetype': npwp_mimetype
+ })
+ if user.parent_id:
+ match_company.message_post(body="NPWP Uploaded", attachment_ids=[npwp_attachment.id])
+ else:
+ new_company.message_post(body="NPWP Uploaded", attachment_ids=[npwp_attachment.id])
+
+ if sppkp_document:
+ sppkp_mimetype, _ = mimetypes.guess_type(sppkp_filename)
+ sppkp_mimetype = sppkp_mimetype or 'application/octet-stream'
+ pdf_data = base64.b64decode(sppkp_document)
+ sppkp_attachment = request.env['ir.attachment'].create({
+ 'name': 'SPPKP Document',
+ 'type': 'binary',
+ 'datas': base64.b64encode(pdf_data),
+ 'res_model': 'res.partner',
+ 'res_id': new_company.id,
+ 'mimetype': sppkp_mimetype
+ })
+ if user.parent_id:
+ match_company.message_post(body="SPPKP Uploaded", attachment_ids=[sppkp_attachment.id])
+ else:
+ new_company.message_post(body="SPPKP Uploaded", attachment_ids=[sppkp_attachment.id])
+ request_company = self.get_user_by_email(user.email)
+ request_company.parent_name = business_name
+ # if user.parent_id:
+ # request_company.send_company_switch_approve_mail()
+ # else:
+ # request_company.send_company_request_mail_switch()
+
+ request_company.send_company_request_mail_switch()
response['switch'] = 'Pending'
return self.response(response)
@@ -542,7 +670,7 @@ class User(controller.Controller):
# @controller.Controller.must_authorized()
def switch_account_progres(self, **kw):
id = int(kw.get('id'))
- user = request.env['res.users'].search([('id', '=', id)], limit=1)
+ # user = request.env['res.partner'].search([('id', '=', id)], limit=1)
response = {
'status': ''
}
@@ -558,5 +686,122 @@ class User(controller.Controller):
else:
response['status'] = new_company_request.is_approve
else:
- response['status'] = 'unknown'
+ response['status'] = False
+ return self.response(response)
+
+ def get_user_by_email(self, email):
+ return request.env['res.users'].search([
+ ('login', '=', email),
+ ('active', 'in', [True, False])
+ ])
+
+ @http.route(prefix + 'user/download/npwp/<id>', auth='public', methods=['GET'])
+ def download_npwp(self, **kw):
+ id = int(kw.get('id'))
+ """Download NPWP file for the given company"""
+ # Search for the NPWP attachment associated with the company
+ attachment = request.env['ir.attachment'].search([
+ ('res_model', '=', 'res.partner'),
+ ('res_id', '=', id),
+ ('name', '=', 'NPWP Document')
+ ], limit=1)
+
+ if not attachment:
+ return request.not_found()
+
+ # Get the file data and content type
+ npwp_mimetype = attachment.mimetype # This should be directly from the attachment
+ npwp_mimetype = npwp_mimetype or 'application/octet-stream'
+
+ # Create a filename with the correct extension
+ filename = f"{attachment.name}"
+
+ # Manually set the Content-Disposition header to inline
+ content_disposition = f'inline; filename="{filename}"'
+
+ # Send the file as a response
+ return request.make_response(
+ base64.b64decode(attachment.datas),
+ headers=[
+ ('Content-Type', npwp_mimetype),
+ ('Content-Disposition', content_disposition)
+ ]
+ )
+
+ @http.route(prefix + 'user/chek/npwp/<id>', auth='public', methods=['GET', 'OPTIONS'])
+ @controller.Controller.must_authorized()
+ def chek_npwp(self, **kw):
+ id = int(kw.get('id'))
+ """Download NPWP file for the given company"""
+ # Search for the NPWP attachment associated with the company
+ attachment = request.env['ir.attachment'].search([
+ ('res_model', '=', 'res.partner'),
+ ('res_id', '=', id),
+ ('name', '=', 'NPWP Document')
+ ], limit=1)
+ response = {
+ 'status': ''
+ }
+ if attachment:
+ response['status'] = True
+ else:
+ response['status'] = False
+
+ # If no attachment is found, return status False
+ return self.response(response)
+
+ @http.route(prefix + 'user/download/sppkp/<id>', auth='public', methods=['GET'])
+ def download_sppkp(self, **kw):
+ id = int(kw.get('id'))
+ """Download SPPKP file for the given company"""
+ # Search for the SPPKP attachment associated with the company
+ attachment = request.env['ir.attachment'].search([
+ ('res_model', '=', 'res.partner'),
+ ('res_id', '=', id),
+ ('name', '=', 'SPPKP Document')
+ ], limit=1)
+
+ if not attachment:
+ return request.not_found()
+
+ # Get the file data and content type
+ sppkp_mimetype = attachment.mimetype # Use the MIME type directly from the attachment
+ sppkp_mimetype = sppkp_mimetype or 'application/octet-stream'
+
+ # Create a filename with the correct extension
+ filename = attachment.name # No need to append extension since attachment should already have it
+
+ # Manually set the Content-Disposition header to inline
+ content_disposition = f'inline; filename="{filename}"'
+
+ # Send the file as a response
+ return request.make_response(
+ base64.b64decode(attachment.datas),
+ headers=[
+ ('Content-Type', sppkp_mimetype),
+ ('Content-Disposition', content_disposition) # Ensure inline display
+ ]
+ )
+
+ @http.route(prefix + 'user/chek/sppkp/<id>', auth='public', methods=['GET', 'OPTIONS'])
+ @controller.Controller.must_authorized()
+ def chek_sppkp(self, **kw):
+ id = int(kw.get('id'))
+ """Download SPPKP file for the given company"""
+ # Search for the SPPKP attachment associated with the company
+ attachment = request.env['ir.attachment'].search([
+ ('res_model', '=', 'res.partner'),
+ ('res_id', '=', id),
+ ('name', '=', 'SPPKP Document')
+ ], limit=1)
+
+ response = {
+ 'status': ''
+ }
+ if attachment:
+ response['status'] = True
+ else:
+ response['status'] = False
+
+ # If no attachment is found, return status False
return self.response(response) \ No newline at end of file