from odoo import models import json import base64 class ResPartner(models.Model): _inherit = 'res.partner' def api_single_response(self, form_merchant, with_detail=''): sertifikat = [ ['TKDN', '0'], ['SNI', '1'], ['K3L', '2'], ] dokumen_sertifikat = [] if form_merchant.sertifikat_produk: form_merchant_dokumen_sertifikat = form_merchant.sertifikat_produk mapping_dokumen = {item[0]: item[1] for item in sertifikat} dokumen_pengiriman_list = [dokumen.strip() for dokumen in form_merchant_dokumen_sertifikat.split(',')] dokumen_sertifikat = [mapping_dokumen.get(dokumen, '3') for dokumen in dokumen_pengiriman_list] data = { 'name_merchant' : form_merchant.name_merchant, 'pejabat_name' : form_merchant.pejabat_name, 'pic_merchant' : form_merchant.pic_merchant, 'pic_position' : form_merchant.pic_position, 'address' : form_merchant.address, 'state' : form_merchant.state.id, 'city' : form_merchant.city.id, 'district' : form_merchant.district.id, 'subDistrict' : form_merchant.subDistrict.id, 'zip' : form_merchant.zip, 'bank_name' : form_merchant.bank_name, 'rekening_name' : form_merchant.rekening_name, 'account_number' : form_merchant.account_number, 'email_company' : form_merchant.email_company, 'email_sales' : form_merchant.email_sales, 'email_finance' : form_merchant.email_finance, 'phone' : form_merchant.phone, 'mobile' : form_merchant.mobile, 'bisnis_type' : form_merchant.bisnis_type, 'category_perusahaan': form_merchant.category_perusahaan, 'website' : form_merchant.website, # informasi Vendor 'harga_tayang' : form_merchant.harga_tayang, 'category_produk': ','.join([str(cat.id) for cat in form_merchant.category_produk_ids]) if form_merchant.category_produk_ids else '', 'merk_dagang' : form_merchant.merk_dagang, 'is_pengajuan_tempo' : 'ada' if form_merchant.is_pengajuan_tempo else 'tidak', 'tempo_duration' : form_merchant.tempo_duration.id, 'kredit_limit' : form_merchant.kredit_limit, 'waktu_pengiriman' : form_merchant.waktu_pengiriman, 'terhitung_sejak' : form_merchant.terhitung_sejak, # syarat perdagangan 'is_kembali_barang': 'tidak' if form_merchant.is_kembali_barang == 'Tidak dapat direturn' else 'ya', 'text_return': form_merchant.is_kembali_barang if form_merchant.is_kembali_barang != 'Tidak dapat direturn' else '', 'tenggat_waktu': form_merchant.tenggat_waktu, 'sertifikat_produk': ','.join(dokumen_sertifikat) if dokumen_sertifikat else '', 'custom_sertifikat_produk': '' if form_merchant.custom_sertifikat_produk == 'false' else form_merchant.custom_sertifikat_produk, 'tempo_garansi': form_merchant.tempo_garansi, 'explain_garansi': form_merchant.explain_garansi, 'is_order_quantity': 'ya' if form_merchant.is_order_quantity != 'Tidak ada minimum order quantity' else 'tidak', 'minimum_pembelian': form_merchant.is_order_quantity, #dokumen 'file_npwp': { 'name': form_merchant.file_npwp.name, } if form_merchant.file_npwp else '', 'file_sppkp': { 'name': form_merchant.file_sppkp.name, } if form_merchant.file_sppkp else '', 'file_dokumenKtpDirut': { 'name': form_merchant.file_dokumenKtpDirut.name, }if form_merchant.file_dokumenKtpDirut else '', 'file_kartuNama': { 'name': form_merchant.file_kartuNama.name, }if form_merchant.file_kartuNama else '', 'file_suratPernyataan': { 'name': form_merchant.file_suratPernyataan.name, }if form_merchant.file_suratPernyataan else '', 'file_fotoKantor': { 'name': form_merchant.file_fotoKantor.name }if form_merchant.file_fotoKantor else '', 'file_dataProduk': { 'name': form_merchant.file_dataProduk.name, }if form_merchant.file_dataProduk else '', 'file_pricelist': { 'name': form_merchant.file_pricelist.name, } if form_merchant.file_pricelist else '', } return data