from odoo import models, fields, api, _ from odoo.exceptions import UserError from odoo.http import request class RejectReasonWizard(models.TransientModel): _name = 'reject.reason.wizard' _description = 'Wizard for Reject Reason' request_id = fields.Many2one('user.pengajuan.tempo.request', string='Request') reason_reject = fields.Text(string='Reason for Rejection', required=True, tracking=True) def confirm_reject(self): tempo = self.request_id if tempo: tempo.write({'reason_reject': self.reason_reject}) tempo.state_tempo = 'reject' template = self.env.ref('indoteknik_custom.mail_template_res_user_company_tempo_reject') template.send_mail(tempo.id, force_send=True) return {'type': 'ir.actions.act_window_close'} class ConfirmApprovalWizard(models.TransientModel): _name = 'confirm.approval.wizard' _description = 'Wizard Konfirmasi Approval' tempo_id = fields.Many2one('user.pengajuan.tempo.request', string='Tempo', required=True) def confirm_approval(self): tempo = self.tempo_id if tempo.state_tempo == 'draft': tempo.state_tempo = 'approval_sales' template = self.env.ref('indoteknik_custom.mail_template_res_user_company_tempo_approved_by_sales') template.send_mail(tempo.id, force_send=True) elif tempo.state_tempo == 'approval_sales': tempo.state_tempo = 'approval_finance' template = self.env.ref('indoteknik_custom.mail_template_res_user_company_tempo_to_aprove_director') template.send_mail(tempo.id, force_send=True) elif tempo.state_tempo == 'approval_finance': tempo.state_tempo = 'approval_director' class UserPengajuanTempoRequest(models.Model): _name = 'user.pengajuan.tempo.request' _inherit = ['mail.thread', 'mail.activity.mixin'] _rec_name = 'user_id' user_id = fields.Many2one('res.partner', string='User') user_company_id = fields.Many2one('res.partner', string='Company') pengajuan_tempo_id = fields.Many2one('user.pengajuan.tempo', string='Form Tempo') tempo_duration = fields.Many2one('account.payment.term', string='Durasi Tempo', tracking=3) tempo_limit = fields.Integer(string='Limit Tempo', tracking=3) state_tempo = fields.Selection([ ('draft', 'Pengajuan Tempo'), ('approval_sales', 'Approved by Sales Manager'), ('approval_finance', 'Approved by Finance'), ('approval_director', 'Approved by Director'), ('reject', 'Rejected'), ], string='Status', readonly=True, copy=False, index=True, track_visibility='onchange', default='draft') last_state_tempo = fields.Selection([ ('draft', 'Pengajuan Tempo'), ('approval_sales', 'Approved by Sales Manager'), ('approval_finance', 'Approved by Finance'), ('approval_director', 'Approved by Director'), ('reject', 'Rejected'), ], string='Status',) reason_reject = fields.Char(string='Reason Reaject', tracking=True, track_visibility='onchange') state_tempo_text = fields.Char(string="Status", compute="_compute_state_tempo_text") @api.depends('state_tempo') def _compute_state_tempo_text(self): for record in self: status_mapping = { 'draft': "Menunggu Approve Manager", 'approval_sales': "Menunggu Approve Finance", 'approval_finance': "Menunggu Approve Direktur", 'approval_director': "Approved", 'reject': "Rejected", } record.state_tempo_text = status_mapping.get(record.state_tempo, "Unknown") # informasi perusahaan name_tempo = fields.Many2one('res.partner', string='Nama Perusahaan', related='pengajuan_tempo_id.name_tempo', store=True, tracking=True, readonly=False) industry_id_tempo = fields.Many2one('res.partner.industry', 'Customer Industry', related='pengajuan_tempo_id.industry_id_tempo',store=True, tracking=True, readonly=False) street_tempo = fields.Char(string="Alamat Perusahaan", related='pengajuan_tempo_id.street_tempo', store=True, tracking=True, readonly=False) state_id_tempo = fields.Many2one('res.country.state', string='State', related='pengajuan_tempo_id.state_id_tempo', store=True, tracking=True, readonly=False) city_id_tempo = fields.Many2one('vit.kota', string='City', related='pengajuan_tempo_id.city_id_tempo', store=True, tracking=True, readonly=False) zip_tempo = fields.Char(string="Zip", related='pengajuan_tempo_id.zip_tempo', store=True, tracking=True, readonly=False) mobile_tempo = fields.Char(string="No. Telfon Perusahaan", related='pengajuan_tempo_id.mobile_tempo', store=True, tracking=True, readonly=False) bank_name_tempo = fields.Char(string="Nama Bank", related='pengajuan_tempo_id.bank_name_tempo', store=True, tracking=True, readonly=False) account_name_tempo = fields.Char(string="Nama Rekening", related='pengajuan_tempo_id.account_name_tempo', store=True, tracking=True, readonly=False) account_number_tempo = fields.Char(string="Nomor Rekening Bank", related='pengajuan_tempo_id.account_number_tempo', store=True, tracking=True, readonly=False) website_tempo = fields.Char(string='Website', related='pengajuan_tempo_id.website_tempo', store=True, tracking=True, readonly=False) portal = fields.Boolean(string='Portal Website', related='pengajuan_tempo_id.portal', store=True, tracking=True, readonly=False) estimasi_tempo = fields.Char(string='Estimasi Pembelian Pertahun', related='pengajuan_tempo_id.estimasi_tempo', store=True, tracking=True, readonly=False) tempo_duration_origin = fields.Many2one('account.payment.term', string='Durasi Tempo', related='tempo_duration', store=True, tracking=True, readonly=False) tempo_limit_origin = fields.Char(string='Limit Tempo', related='pengajuan_tempo_id.tempo_limit' , store=True, tracking=True, readonly=False) category_produk_ids = fields.Many2many('product.public.category', string='Kategori Produk yang Digunakan', related='pengajuan_tempo_id.category_produk_ids', readonly=False) # Kontak Perusahaan direktur_name = fields.Char(string='Nama Lengkap Direktur', related='pengajuan_tempo_id.direktur_name', store=True, readonly=False) direktur_mobile = fields.Char(string='No. Telpon Direktur', related='pengajuan_tempo_id.direktur_mobile', store=True, readonly=False) direktur_email = fields.Char(string='Email Direktur', related='pengajuan_tempo_id.direktur_email', store=True, readonly=False) purchasing_name = fields.Char(string='Nama Purchasing', related='pengajuan_tempo_id.purchasing_name', store=True, readonly=False) purchasing_mobile = fields.Char(string='No. Telpon Purchasing', related='pengajuan_tempo_id.purchasing_mobile', store=True, readonly=False) purchasing_email = fields.Char(string='Email Purchasing', related='pengajuan_tempo_id.purchasing_email', store=True, readonly=False) finance_name = fields.Char(string='Nama Finance', related='pengajuan_tempo_id.finance_name', store=True, readonly=False) finance_mobile = fields.Char(string='No. Telpon Finance', related='pengajuan_tempo_id.finance_mobile', store=True, readonly=False) finance_email = fields.Char(string='Email Finance', related='pengajuan_tempo_id.finance_email', store=True, readonly=False) # Pengiriman pic_tittle = fields.Char(string='Tittle PIC Penerimaan Barang', related='pengajuan_tempo_id.pic_tittle', store=True, readonly=False) pic_mobile = fields.Char(string='Nomor HP PIC Penerimaan Barang', related='pengajuan_tempo_id.pic_mobile', store=True, readonly=False) pic_name = fields.Char(string='Nama PIC Penerimaan Barang', related='pengajuan_tempo_id.pic_name', store=True, readonly=False) street_pengiriman = fields.Char(string="Alamat Pengiriman Barang", related='pengajuan_tempo_id.street_pengiriman', store=True, readonly=False) state_id_pengiriman = fields.Many2one('res.country.state', string='State', related='pengajuan_tempo_id.state_id_pengiriman', store=True, readonly=False) city_id_pengiriman = fields.Many2one('vit.kota', string='City', related='pengajuan_tempo_id.city_id_pengiriman', store=True, readonly=False) district_id_pengiriman = fields.Many2one('vit.kecamatan', string='Kecamatan',related='pengajuan_tempo_id.district_id_pengiriman', store=True, readonly=False) subDistrict_id_pengiriman = fields.Many2one('vit.kelurahan', string='Kelurahan', related='pengajuan_tempo_id.subDistrict_id_pengiriman', store=True, readonly=False) zip_pengiriman = fields.Char(string="Zip", related='pengajuan_tempo_id.zip_pengiriman', store=True, readonly=False) invoice_pic_tittle = fields.Char(string='Tittle PIC Penerimaan Invoice', related='pengajuan_tempo_id.invoice_pic_tittle', store=True, readonly=False) invoice_pic_mobile = fields.Char(string='Nomor HP PIC Penerimaan Invoice', related='pengajuan_tempo_id.invoice_pic_mobile', store=True, readonly=False) invoice_pic = fields.Char(string='Nama PIC Penerimaan Invoice', related='pengajuan_tempo_id.invoice_pic', store=True, readonly=False) street_invoice = fields.Char(string="Alamat Pengiriman Invoice", related='pengajuan_tempo_id.street_invoice', store=True, readonly=False) state_id_invoice = fields.Many2one('res.country.state', string='State', related='pengajuan_tempo_id.state_id_invoice', store=True, readonly=False) city_id_invoice = fields.Many2one('vit.kota', string='City', related='pengajuan_tempo_id.city_id_invoice', store=True, readonly=False) district_id_invoice = fields.Many2one('vit.kecamatan', string='Kecamatan', related='pengajuan_tempo_id.district_id_invoice', store=True, readonly=False) subDistrict_id_invoice = fields.Many2one('vit.kelurahan', string='Kelurahan', related='pengajuan_tempo_id.subDistrict_id_invoice', store=True, readonly=False) zip_invoice = fields.Char(string="Zip", related='pengajuan_tempo_id.zip_invoice', store=True, readonly=False) tukar_invoice = fields.Char(string='Jadwal Penukaran Invoice', related='pengajuan_tempo_id.tukar_invoice', store=True, readonly=False) jadwal_bayar = fields.Char(string='Jadwal Pembayaran', related='pengajuan_tempo_id.jadwal_bayar', store=True, readonly=False) dokumen_pengiriman = fields.Char(string='Dokumen Tanda Terima yang Diberikan Pada Saat Pengiriman Barang', related='pengajuan_tempo_id.dokumen_pengiriman', store=True, readonly=False) dokumen_pengiriman_input = fields.Char(string='Dokumen yang dibawa saat pengiriman barang', related='pengajuan_tempo_id.dokumen_pengiriman_input', store=True, readonly=False) dokumen_invoice = fields.Char(string='Dokumen yang dilampirkan saat Pengiriman Invoice', related='pengajuan_tempo_id.dokumen_invoice', store=True, readonly=False) is_same_address = fields.Boolean(string="Same Address pengiriman invoicr dan alamat pengiriman barang", related='pengajuan_tempo_id.is_same_address', store=True, readonly=False) is_same_address_street = fields.Boolean(string="Same Address pengiriman barang dan alamat bisnis", related='pengajuan_tempo_id.is_same_address_street', store=True, readonly=False) dokumen_prosedur = fields.Many2many( 'ir.attachment', 'dokumen_prosedur_rel', string="Dokumen Prosedur", related='pengajuan_tempo_id.dokumen_prosedur', readonly=False, tracking=3 ) #Referensi supplier_ids = fields.Many2many('user.pengajuan.tempo.line',related='pengajuan_tempo_id.supplier_ids', string="Suppliers", readonly=False) # Dokumen dokumen_npwp = fields.Many2many( 'ir.attachment', 'pengajuan_dokumen_npwp_rel', string="NPWP Perusahaan", related='pengajuan_tempo_id.dokumen_npwp', readonly=False, tracking=3 ) dokumen_sppkp = fields.Many2many( 'ir.attachment', 'pengajuan_dokumen_sppkp_rel', string="SPPKP Perusahaan", related='pengajuan_tempo_id.dokumen_sppkp', readonly=False, tracking=3 ) dokumen_nib = fields.Many2many( 'ir.attachment', 'pengajuan_dokumen_nib_rel', string="NIB", related='pengajuan_tempo_id.dokumen_nib', readonly=False, tracking=3, track_visibility="onchange" ) dokumen_siup = fields.Many2many( 'ir.attachment', 'pengajuan_dokumen_siup_rel', string="SIUP", related='pengajuan_tempo_id.dokumen_siup', readonly=False, tracking=3, track_visibility="onchange" ) dokumen_tdp = fields.Many2many( 'ir.attachment', 'pengajuan_dokumen_tdp_rel', string="TDP", related='pengajuan_tempo_id.dokumen_tdp', readonly=False, tracking=3, track_visibility="onchange" ) dokumen_skdp = fields.Many2many( 'ir.attachment', 'pengajuan_dokumen_skdp_rel', string="SKDP", related='pengajuan_tempo_id.dokumen_skdp', readonly=False, tracking=3, track_visibility="onchange" ) dokumen_skt = fields.Many2many( 'ir.attachment', 'pengajuan_dokumen_skt_rel', string="SKT", related='pengajuan_tempo_id.dokumen_skt', readonly=False, tracking=3, track_visibility="onchange" ) dokumen_akta_perubahan = fields.Many2many( 'ir.attachment', 'pengajuan_dokumen_akta_perubahan_rel', string="Akta Perubahan", related='pengajuan_tempo_id.dokumen_akta_perubahan', readonly=False, tracking=3 ) dokumen_ktp_dirut = fields.Many2many( 'ir.attachment', 'pengajuan_dokumen_ktp_dirut_rel', string="KTP Dirut/Direktur", related='pengajuan_tempo_id.dokumen_ktp_dirut', readonly=False, tracking=3 ) dokumen_akta_pendirian = fields.Many2many( 'ir.attachment', 'pengajuan_dokumen_angkta_pendirian_rel', string="Akta Pendirian", related='pengajuan_tempo_id.dokumen_akta_pendirian', readonly=False, tracking=3 ) dokumen_laporan_keuangan = fields.Many2many( 'ir.attachment', 'pengajuan_dokumen_laporan_keuangan_rel', string="Laporan Keuangan", related='pengajuan_tempo_id.dokumen_laporan_keuangan', readonly=False, tracking=3 ) dokumen_foto_kantor = fields.Many2many( 'ir.attachment', 'pengajuan_dokumen_foto_kantor_rel', string="Foto Kantor (Tampak Depan)", related='pengajuan_tempo_id.dokumen_foto_kantor', readonly=False, tracking=3 ) dokumen_tempat_bekerja = fields.Many2many( 'ir.attachment', 'pengajuan_dokumen_tempat_bekerja_rel', string="Tempat Bekerja", related='pengajuan_tempo_id.dokumen_tempat_bekerja', readonly=False, tracking=3 ) @api.onchange('name_tempo', 'industry_id_tempo', 'street_tempo', 'state_id_tempo', 'city_id_tempo', 'zip_tempo', 'mobile_tempo', 'bank_name_tempo', 'account_name_tempo', 'account_number_tempo', 'website_tempo', 'estimasi_tempo', 'tempo_duration_origin', 'tempo_limit_origin', 'category_produk_ids') def _onchange_related_fields(self): if self.pengajuan_tempo_id: # Perbarui nilai di pengajuan_tempo_id self.pengajuan_tempo_id.name_tempo = self.name_tempo self.pengajuan_tempo_id.industry_id_tempo = self.industry_id_tempo self.pengajuan_tempo_id.street_tempo = self.street_tempo self.pengajuan_tempo_id.state_id_tempo = self.state_id_tempo self.pengajuan_tempo_id.city_id_tempo = self.city_id_tempo self.pengajuan_tempo_id.zip_tempo = self.zip_tempo self.pengajuan_tempo_id.mobile_tempo = self.mobile_tempo self.pengajuan_tempo_id.bank_name_tempo = self.bank_name_tempo self.pengajuan_tempo_id.account_name_tempo = self.account_name_tempo self.pengajuan_tempo_id.account_number_tempo = self.account_number_tempo self.pengajuan_tempo_id.website_tempo = self.website_tempo self.pengajuan_tempo_id.portal = self.portal self.pengajuan_tempo_id.estimasi_tempo = self.estimasi_tempo self.pengajuan_tempo_id.tempo_duration = self.tempo_duration_origin self.pengajuan_tempo_id.tempo_limit = self.tempo_limit_origin self.pengajuan_tempo_id.category_produk_ids = self.category_produk_ids @api.onchange('direktur_name', 'direktur_mobile', 'direktur_email', 'purchasing_name', 'purchasing_mobile', 'purchasing_email', 'finance_name', 'finance_mobile', 'finance_email') def _onchange_related_fields_kontak(self): if self.pengajuan_tempo_id: # Perbarui nilai di pengajuan_tempo_id self.pengajuan_tempo_id.direktur_name = self.direktur_name self.pengajuan_tempo_id.direktur_mobile = self.direktur_mobile self.pengajuan_tempo_id.direktur_email = self.direktur_email self.pengajuan_tempo_id.purchasing_name = self.purchasing_name self.pengajuan_tempo_id.purchasing_mobile = self.purchasing_mobile self.pengajuan_tempo_id.purchasing_email = self.purchasing_email self.pengajuan_tempo_id.finance_name = self.finance_name self.pengajuan_tempo_id.finance_mobile = self.finance_mobile self.pengajuan_tempo_id.finance_email = self.finance_email @api.onchange('pic_tittle','pic_mobile', 'pic_name', 'street_pengiriman', 'state_id_pengiriman', 'city_id_pengiriman', 'zip_pengiriman', 'district_id_pengiriman', 'subDistrict_id_pengiriman' 'invoice_pic_tittle','invoice_pic_mobile', 'invoice_pic', 'street_invoice', 'state_id_invoice', 'city_id_invoice', 'district_id_invoice', 'subDistrict_id_invoice', 'zip_invoice', 'tukar_invoice', 'jadwal_bayar', 'dokumen_pengiriman', 'dokumen_pengiriman_input', 'dokumen_invoice', 'is_same_address', 'is_same_address_street','dokumen_prosedur') def _onchange_related_fields_pengiriman(self): if self.pengajuan_tempo_id: # Perbarui nilai di pengajuan_tempo_id self.pengajuan_tempo_id.pic_tittle = self.pic_tittle self.pengajuan_tempo_id.pic_mobile = self.pic_mobile self.pengajuan_tempo_id.pic_name = self.pic_name self.pengajuan_tempo_id.street_pengiriman = self.street_pengiriman self.pengajuan_tempo_id.state_id_pengiriman = self.state_id_pengiriman self.pengajuan_tempo_id.city_id_pengiriman = self.city_id_pengiriman self.pengajuan_tempo_id.district_id_pengiriman = self.district_id_pengiriman self.pengajuan_tempo_id.subDistrict_id_pengiriman = self.subDistrict_id_pengiriman self.pengajuan_tempo_id.zip_pengiriman = self.zip_pengiriman self.pengajuan_tempo_id.invoice_pic_tittle = self.invoice_pic_tittle self.pengajuan_tempo_id.invoice_pic_mobile = self.invoice_pic_mobile self.pengajuan_tempo_id.invoice_pic = self.invoice_pic self.pengajuan_tempo_id.street_invoice = self.street_invoice self.pengajuan_tempo_id.state_id_invoice = self.state_id_invoice self.pengajuan_tempo_id.city_id_invoice = self.city_id_invoice self.pengajuan_tempo_id.district_id_invoice = self.district_id_invoice self.pengajuan_tempo_id.subDistrict_id_invoice = self.subDistrict_id_invoice self.pengajuan_tempo_id.zip_invoice = self.zip_invoice self.pengajuan_tempo_id.tukar_invoice = self.tukar_invoice self.pengajuan_tempo_id.jadwal_bayar = self.jadwal_bayar self.pengajuan_tempo_id.dokumen_pengiriman = self.dokumen_pengiriman self.pengajuan_tempo_id.dokumen_pengiriman_input = self.dokumen_pengiriman_input self.pengajuan_tempo_id.dokumen_invoice = self.dokumen_invoice self.pengajuan_tempo_id.is_same_address = self.is_same_address self.pengajuan_tempo_id.is_same_address_street = self.is_same_address_street self.pengajuan_tempo_id.dokumen_prosedur = self.dokumen_prosedur @api.onchange('supplier_ids') def _onchange_supplier_ids(self): if self.pengajuan_tempo_id: self.pengajuan_tempo_id.supplier_ids = self.supplier_ids @api.onchange('dokumen_nib', 'dokumen_npwp', 'dokumen_sppkp', 'dokumen_akta_perubahan', 'dokumen_ktp_dirut', 'dokumen_akta_pendirian', 'dokumen_laporan_keuangan', 'dokumen_foto_kantor', 'dokumen_tempat_bekerja', 'dokumen_skdp', 'dokumen_skt', 'dokumen_siup', 'dokumen_tdp') def _onchange_related_fields_dokumen(self): if self.pengajuan_tempo_id: # Perbarui nilai di pengajuan_tempo_id self.pengajuan_tempo_id.dokumen_siup = self.dokumen_siup self.pengajuan_tempo_id.dokumen_tdp = self.dokumen_tdp self.pengajuan_tempo_id.dokumen_skdp = self.dokumen_skdp self.pengajuan_tempo_id.dokumen_skt = self.dokumen_skt self.pengajuan_tempo_id.dokumen_npwp = self.dokumen_npwp self.pengajuan_tempo_id.dokumen_sppkp = self.dokumen_sppkp self.pengajuan_tempo_id.dokumen_akta_perubahan = self.dokumen_akta_perubahan self.pengajuan_tempo_id.dokumen_ktp_dirut = self.dokumen_ktp_dirut self.pengajuan_tempo_id.dokumen_akta_pendirian = self.dokumen_akta_pendirian self.pengajuan_tempo_id.dokumen_laporan_keuangan = self.dokumen_laporan_keuangan self.pengajuan_tempo_id.dokumen_foto_kantor = self.dokumen_foto_kantor self.pengajuan_tempo_id.dokumen_tempat_bekerja = self.dokumen_tempat_bekerja @api.onchange('tempo_duration') def _tempo_duration_change(self): for tempo in self: if tempo.env.user.id not in (7, 688, 28, 377, 12182, 375, 19): raise UserError("Durasi tempo hanya bisa di ubah oleh Sales Manager atau Direktur") @api.onchange('tempo_limit') def _onchange_tempo_limit(self): for tempo in self: if tempo.env.user.id not in (7, 688, 28, 19, 375): raise UserError("Limit tempo hanya bisa diubah oleh Sales Manager atau Direktur") def button_approve(self): for tempo in self: if not self.tempo_limit: raise UserError("Limit Tempo harus di isi terlebih dahulu") if tempo.state_tempo == 'draft': if tempo.env.user.id in (688, 28, 7): raise UserError("Pengajuan tempo harus di approve oleh sales manager terlebih dahulu") else: # if tempo.env.user.id not in (375, 19): if tempo.env.user.id != 19: # if tempo.env.user.id != 12182: raise UserError("Pengajuan tempo hanya bisa di approve oleh sales manager") else: return { 'type': 'ir.actions.act_window', 'name': 'Konfirmasi Approve', 'res_model': 'confirm.approval.wizard', 'view_mode': 'form', 'target': 'new', 'context': { 'default_tempo_id': tempo.id, }, } elif tempo.state_tempo == 'approval_sales': if tempo.env.user.id == 7: raise UserError("Pengajuan tempo harus di approve oleh Finence terlebih dahulu") else: if tempo.env.user.id not in (688, 28): # if tempo.env.user.id not in (288,28,12182): raise UserError("Pengajuan tempo hanya bisa di approve oleh Finence") else: return { 'type': 'ir.actions.act_window', 'name': 'Konfirmasi Approve', 'res_model': 'confirm.approval.wizard', 'view_mode': 'form', 'target': 'new', 'context': { 'default_tempo_id': tempo.id, }, } elif tempo.state_tempo == 'approval_finance': if tempo.env.user.id != 7: # if tempo.env.user.id != 12182: raise UserError("Pengajuan tempo hanya bisa di approve oleh Direktur") else: return { 'type': 'ir.actions.act_window', 'name': 'Konfirmasi Approve', 'res_model': 'confirm.approval.wizard', 'view_mode': 'form', 'target': 'new', 'context': { 'default_tempo_id': tempo.id, }, } def button_reject(self): return { 'type': 'ir.actions.act_window', 'name': _('Reject Reason'), 'res_model': 'reject.reason.wizard', 'view_mode': 'form', 'target': 'new', 'context': {'default_request_id': self.id}, } def button_draft(self): for tempo in self: tempo.state_tempo = tempo.last_state_tempo if tempo.last_state_tempo else 'draft' def write(self, vals): is_approve = True if self.state_tempo == 'approval_director' or vals.get('state_tempo') == 'approval_director' else False # if self.is_approve and is_approve: # raise UserError('Tidak dapat mengubah approval yang sudah diisi') limit_tempo = '' if vals.get('tempo_limit'): limit_tempo = vals.get('tempo_limit') elif self.tempo_limit: limit_tempo = self.tempo_limit else: limit_tempo = self.pengajuan_tempo_id.tempo_limit tempo_duration = '' if vals.get('tempo_duration'): tempo_duration = vals.get('tempo_duration') elif self.tempo_duration: tempo_duration = self.tempo_duration else: tempo_duration = self.pengajuan_tempo_id.tempo_duration if is_approve: self.pengajuan_tempo_id.partner_id = self.user_id.id # informasi perusahaan self.user_company_id.name_tempo = self.pengajuan_tempo_id.name_tempo self.user_company_id.industry_id_tempo = self.pengajuan_tempo_id.industry_id_tempo self.user_company_id.street_tempo = self.pengajuan_tempo_id.street_tempo self.user_company_id.state_id_tempo = self.pengajuan_tempo_id.state_id_tempo self.user_company_id.city_id_tempo = self.pengajuan_tempo_id.city_id_tempo self.user_company_id.zip_tempo = self.pengajuan_tempo_id.zip_tempo self.user_company_id.mobile_tempo = self.pengajuan_tempo_id.mobile_tempo self.user_company_id.bank_name_tempo = self.pengajuan_tempo_id.bank_name_tempo self.user_company_id.account_name_tempo = self.pengajuan_tempo_id.account_name_tempo self.user_company_id.account_number_tempo = self.pengajuan_tempo_id.account_number_tempo self.user_company_id.website_tempo = self.pengajuan_tempo_id.website_tempo self.user_company_id.portal = self.pengajuan_tempo_id.portal self.user_company_id.estimasi_tempo = self.pengajuan_tempo_id.estimasi_tempo self.user_company_id.tempo_duration = tempo_duration.id self.user_company_id.tempo_limit = limit_tempo self.user_company_id.category_produk_ids = self.pengajuan_tempo_id.category_produk_ids # Kontak Perusahaan self.user_company_id.direktur_name = self.pengajuan_tempo_id.direktur_name self.user_company_id.direktur_mobile = self.pengajuan_tempo_id.direktur_mobile self.user_company_id.direktur_email = self.pengajuan_tempo_id.direktur_email self.user_company_id.purchasing_name = self.pengajuan_tempo_id.purchasing_name self.user_company_id.purchasing_mobile = self.pengajuan_tempo_id.purchasing_mobile self.user_company_id.purchasing_email = self.pengajuan_tempo_id.purchasing_email self.user_company_id.finance_name = self.pengajuan_tempo_id.finance_name self.user_company_id.finance_mobile = self.pengajuan_tempo_id.finance_mobile self.user_company_id.finance_email = self.pengajuan_tempo_id.finance_email # Data untuk kontak baru contacts_data = [ { "type": "contact", 'title': 6 if self.pengajuan_tempo_id.direktur_tittle == 'Bpk' else 7, "name": self.pengajuan_tempo_id.direktur_name, "email": self.pengajuan_tempo_id.direktur_email, "phone": self.pengajuan_tempo_id.direktur_mobile, }, { "type": "contact", 'title': 6 if self.pengajuan_tempo_id.purchasing_tittle == 'Bpk' else 7, "name": self.pengajuan_tempo_id.purchasing_name, "email": self.pengajuan_tempo_id.purchasing_email, "phone": self.pengajuan_tempo_id.purchasing_mobile, }, { "type": "contact", 'title': 6 if self.pengajuan_tempo_id.finance_tittle == 'Bpk' else 7, "name": self.pengajuan_tempo_id.finance_name, "email": self.pengajuan_tempo_id.finance_email, "phone": self.pengajuan_tempo_id.finance_mobile, }, { "type": "delivery", "name": self.pengajuan_tempo_id.pic_name, "phone": self.pengajuan_tempo_id.pic_mobile, "street": self.pengajuan_tempo_id.street_pengiriman, "state_id": self.pengajuan_tempo_id.state_id_pengiriman.id, "kota_id": self.pengajuan_tempo_id.city_id_pengiriman.id, "kecamatan_id": self.pengajuan_tempo_id.district_id_pengiriman.id, "kelurahan_id": self.pengajuan_tempo_id.subDistrict_id_pengiriman.id, "zip": self.pengajuan_tempo_id.zip_pengiriman, }, { "type": "invoice", "name": self.pengajuan_tempo_id.invoice_pic, "phone": self.pengajuan_tempo_id.invoice_pic_mobile, "street": self.pengajuan_tempo_id.street_invoice, "state_id": self.pengajuan_tempo_id.state_id_invoice.id, "kota_id": self.pengajuan_tempo_id.city_id_invoice.id, "kecamatan_id": self.pengajuan_tempo_id.district_id_invoice.id, "kelurahan_id": self.pengajuan_tempo_id.subDistrict_id_invoice.id, "zip": self.pengajuan_tempo_id.zip_invoice, }, ] # Buat kontak baru untuk company_id for contact_data in contacts_data: existing_contact = self.env['res.partner'].search([ ('parent_id', '=', self.user_company_id.id), ('name', '=', contact_data['name']) ], limit=1) if not existing_contact: # Pastikan tidak ada partner lain dengan nama yang sama sebelum membuat baru duplicate_check = self.env['res.partner'].search([ ('name', '=', contact_data['name']) ], limit=1) if duplicate_check: # Jika nama sudah ada tetapi di perusahaan lain, tambahkan nama perusahaan contact_data['name'] = f"{contact_data['name']} ({self.user_company_id.name})" self.env['res.partner'].create({ "parent_id": self.user_company_id.id, # Hubungkan ke perusahaan **contact_data, # Tambahkan data kontak }) # Pengiriman self.user_company_id.pic_name = self.pengajuan_tempo_id.pic_name self.user_company_id.street_pengiriman = self.pengajuan_tempo_id.street_pengiriman self.user_company_id.state_id_pengiriman = self.pengajuan_tempo_id.state_id_pengiriman self.user_company_id.city_id_pengiriman = self.pengajuan_tempo_id.city_id_pengiriman self.user_company_id.district_id_pengiriman = self.pengajuan_tempo_id.district_id_pengiriman self.user_company_id.subDistrict_id_pengiriman = self.pengajuan_tempo_id.subDistrict_id_pengiriman self.user_company_id.zip_pengiriman = self.pengajuan_tempo_id.zip_pengiriman self.user_company_id.invoice_pic = self.pengajuan_tempo_id.invoice_pic self.user_company_id.street_invoice = self.pengajuan_tempo_id.street_invoice self.user_company_id.state_id_invoice = self.pengajuan_tempo_id.state_id_invoice self.user_company_id.city_id_invoice = self.pengajuan_tempo_id.city_id_invoice self.user_company_id.district_id_invoice = self.pengajuan_tempo_id.district_id_invoice self.user_company_id.subDistrict_id_invoice = self.pengajuan_tempo_id.subDistrict_id_invoice self.user_company_id.zip_invoice = self.pengajuan_tempo_id.zip_invoice self.user_company_id.tukar_invoice = self.pengajuan_tempo_id.tukar_invoice self.user_company_id.jadwal_bayar = self.pengajuan_tempo_id.jadwal_bayar self.user_company_id.dokumen_pengiriman = self.pengajuan_tempo_id.dokumen_pengiriman self.user_company_id.dokumen_pengiriman_input = self.pengajuan_tempo_id.dokumen_pengiriman_input self.user_company_id.dokumen_invoice = self.pengajuan_tempo_id.dokumen_invoice self.user_company_id.dokumen_prosedur = self.pengajuan_tempo_id.dokumen_prosedur[0] if self.pengajuan_tempo_id.dokumen_prosedur else [] if self.user_company_id.dokumen_prosedur: self.user_company_id.message_post(body='Dokumen Prosedur', attachment_ids=[self.user_company_id.dokumen_prosedur.id]) # Referensi self.user_company_id.supplier_ids = self.pengajuan_tempo_id.supplier_ids # Dokumen self.user_company_id.dokumen_npwp = self.pengajuan_tempo_id.dokumen_npwp[0] if self.pengajuan_tempo_id.dokumen_npwp else [] if self.user_company_id.dokumen_npwp: self.user_company_id.message_post(body='Dokumen NPWP', attachment_ids=[self.user_company_id.dokumen_npwp.id]) self.user_company_id.dokumen_sppkp = self.pengajuan_tempo_id.dokumen_sppkp[0] if self.pengajuan_tempo_id.dokumen_sppkp else [] if self.user_company_id.dokumen_sppkp: self.user_company_id.message_post(body='Dokumen SPPKP', attachment_ids=[self.user_company_id.dokumen_sppkp.id]) self.user_company_id.dokumen_nib = self.pengajuan_tempo_id.dokumen_nib[0] if self.pengajuan_tempo_id.dokumen_nib else [] if self.user_company_id.dokumen_nib: self.user_company_id.message_post(body='Dokumen NIB', attachment_ids=[self.user_company_id.dokumen_nib.id]) self.user_company_id.dokumen_siup = self.pengajuan_tempo_id.dokumen_siup[0] if self.pengajuan_tempo_id.dokumen_siup else [] if self.user_company_id.dokumen_siup: self.user_company_id.message_post(body='dokumen SIUP', attachment_ids=[self.user_company_id.dokumen_siup.id]) self.user_company_id.dokumen_tdp = self.pengajuan_tempo_id.dokumen_tdp[0] if self.pengajuan_tempo_id.dokumen_tdp else [] if self.user_company_id.dokumen_tdp: self.user_company_id.message_post(body='dokumen TDP', attachment_ids=[self.user_company_id.dokumen_tdp.id]) self.user_company_id.dokumen_skdp = self.pengajuan_tempo_id.dokumen_skdp[0] if self.pengajuan_tempo_id.dokumen_skdp else [] if self.user_company_id.dokumen_skdp: self.user_company_id.message_post(body='dokumen SKDP', attachment_ids=[self.user_company_id.dokumen_skdp.id]) self.user_company_id.dokumen_skt = self.pengajuan_tempo_id.dokumen_skt[0] if self.pengajuan_tempo_id.dokumen_skt else [] if self.user_company_id.dokumen_skt: self.user_company_id.message_post(body='dokumen SKT', attachment_ids=[self.user_company_id.dokumen_skt.id]) self.user_company_id.dokumen_akta_perubahan = self.pengajuan_tempo_id.dokumen_akta_perubahan[0] if self.pengajuan_tempo_id.dokumen_akta_perubahan else [] if self.user_company_id.dokumen_akta_perubahan: self.user_company_id.message_post(body='Dokumen Akta Perubahan', attachment_ids=[self.user_company_id.dokumen_akta_perubahan.id]) self.user_company_id.dokumen_ktp_dirut = self.pengajuan_tempo_id.dokumen_ktp_dirut[0] if self.pengajuan_tempo_id.dokumen_ktp_dirut else [] if self.user_company_id.dokumen_ktp_dirut: self.user_company_id.message_post(body='Dokumen Ktp Dirut', attachment_ids=[self.user_company_id.dokumen_ktp_dirut.id]) self.user_company_id.dokumen_akta_pendirian = self.pengajuan_tempo_id.dokumen_akta_pendirian[0] if self.pengajuan_tempo_id.dokumen_akta_pendirian else [] if self.user_company_id.dokumen_akta_pendirian: self.user_company_id.message_post(body='Dokumen Akta Pendirian', attachment_ids=[self.user_company_id.dokumen_akta_pendirian.id]) self.user_company_id.dokumen_laporan_keuangan = self.pengajuan_tempo_id.dokumen_laporan_keuangan[0] if self.pengajuan_tempo_id.dokumen_laporan_keuangan else [] if self.user_company_id.dokumen_laporan_keuangan: self.user_company_id.message_post(body='Dokumen Laporan Keuangan', attachment_ids=[self.user_company_id.dokumen_laporan_keuangan.id]) self.user_company_id.dokumen_foto_kantor = self.pengajuan_tempo_id.dokumen_foto_kantor[0] if self.pengajuan_tempo_id.dokumen_foto_kantor else [] if self.user_company_id.dokumen_foto_kantor: self.user_company_id.message_post(body='Dokumen Foto Kantor', attachment_ids=[self.user_company_id.dokumen_foto_kantor.id]) self.user_company_id.dokumen_tempat_bekerja = self.pengajuan_tempo_id.dokumen_tempat_bekerja[0] if self.pengajuan_tempo_id.dokumen_tempat_bekerja else [] if self.user_company_id.dokumen_tempat_bekerja: self.user_company_id.message_post(body='Dokumen Tempat Bekerja', attachment_ids=[self.user_company_id.dokumen_tempat_bekerja.id]) # self.user_company_id.active = True # user.send_company_request_approve_mail() self.user_company_id.property_payment_term_id = self.tempo_duration.id self.user_company_id.active_limit = True self.user_company_id.blocking_stage = limit_tempo self.user_company_id.warning_stage = float(limit_tempo) - (float(limit_tempo)/2) # Internal Notes comment = [] if self.pengajuan_tempo_id.tukar_invoice: comment.append(f"Jadwal Tukar Invoice: {self.pengajuan_tempo_id.tukar_invoice}") if self.pengajuan_tempo_id.jadwal_bayar: comment.append(f"Jadwal Pembayaran: {self.pengajuan_tempo_id.jadwal_bayar}") self.user_company_id.comment = "\n".join(comment) # template = self.env.ref('indoteknik_custom.mail_template_res_user_company_tempo_approved') # tempo = self.pengajuan_tempo_id # template.send_mail(tempo.id, force_send=True) template = self.env.ref('indoteknik_custom.mail_template_res_user_company_tempo_approved') template.send_mail(self.id, force_send=True) # self.user_id.parent_id = new_company.id # user.send_company_request_reject_mail() return super(UserPengajuanTempoRequest, self).write(vals) def get_user_by_email(self, email): return request.env['res.users'].search([ ('login', '=', email), ('active', 'in', [True, False]) ]) def _message_get_suggested_recipients(self): return {} def format_currency(self, number): number = int(number) return "{:,}".format(number).replace(',', '.')