from odoo import models, fields, api from datetime import datetime, timedelta # class IrAttachment(models.Model): # _inherit = 'ir.attachment' # # @api.model # def create(self, vals): # attachment = super(IrAttachment, self).create(vals) # if attachment: # base_url = self.env['ir.config_parameter'].sudo().get_param('web.base.url') # attachment.url = f"/web/content/{attachment.id}" # return attachment class UserPengajuanTempo(models.Model): _name = 'user.pengajuan.tempo' _inherit = ['mail.thread', 'mail.activity.mixin'] partner_id = fields.Char() _description = 'User Pengajuan Tempo' name = fields.Char(string='Name', required=True) # informasi perusahaan # name_tempo = fields.Many2one( # 'res.partner', string='Nama Perusahaan', # readonly=True, required=True, # states={'draft': [('readonly', False)], 'sent': [('readonly', False)], 'sale': [('readonly', False)]}, # domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]", # tracking=True, # Menambahkan tracking=True # ) name_tempo = fields.Many2one( 'res.partner', string='Nama Perusahaan', tracking=True, # Menambahkan tracking=True ) user_id = fields.Many2one('res.users', string='User') industry_id_tempo = fields.Many2one('res.partner.industry', 'Customer Industry', readonly=True) street_tempo = fields.Char(string="Alamat Perusahaan") state_id_tempo = fields.Many2one('res.country.state', string='State') city_id_tempo = fields.Many2one('vit.kota', string='City') zip_tempo = fields.Char(string="Zip") mobile_tempo = fields.Char(string="No. Telfon Perusahaan") bank_name_tempo = fields.Char(string="Nama Bank") account_name_tempo = fields.Char(string="Nama Rekening") account_number_tempo = fields.Char(string="Nomor Rekening Bank") website_tempo = fields.Char(string='Website') estimasi_tempo = fields.Char(string='Estimasi Pembelian Pertahun') tempo_duration = fields.Many2one('account.payment.term', string='Durasi Tempo') tempo_limit = fields.Char(string='Limit Tempo') category_produk_ids = fields.Many2many('product.public.category', string='Kategori Produk yang Digunakan', domain=lambda self: self._get_default_category_domain()) @api.model def _get_default_category_domain(self): return [('parent_id', '=', False)] # Kontak Perusahaan direktur_name = fields.Char(string='Nama Lengkap Direktur') direktur_mobile = fields.Char(string='No. Telpon Direktur') direktur_email = fields.Char(string='Email Direktur') purchasing_name = fields.Char(string='Nama Purchasing') purchasing_mobile = fields.Char(string='No. Telpon Purchasing') purchasing_email = fields.Char(string='Email Purchasing') finance_name = fields.Char(string='Nama Finance') finance_mobile = fields.Char(string='No. Telpon Finance') finance_email = fields.Char(string='Email Finance') # Pengiriman pic_name = fields.Char(string='Nama PIC Penerimaan Barang') street_pengiriman = fields.Char(string="Alamat Perusahaan") state_id_pengiriman = fields.Many2one('res.country.state', string='State') city_id_pengiriman = fields.Many2one('vit.kota', string='City') zip_pengiriman = fields.Char(string="Zip") invoice_pic = fields.Char(string='Nama PIC Penerimaan Invoice') street_invoice = fields.Char(string="Alamat Perusahaan") state_id_invoice = fields.Many2one('res.country.state', string='State') city_id_invoice = fields.Many2one('vit.kota', string='City') tukar_invoice = fields.Char(string='Jadwal Penukaran Invoice') jadwal_bayar = fields.Char(string='Jadwal Pembayaran') dokumen_pengiriman = fields.Char(string='Dokumen saat Pengiriman Barang') dokumen_invoice = fields.Char(string='Dokumen yang dilampirkan saat Pengiriman Invoice') is_same_address = fields.Boolean(string="Same Address pengiriman invoicr dan alamat pengiriman barang") is_same_address_street = fields.Boolean(string="Same Address pengiriman barang dan alamat bisnis") # Referensi supplier_ids = fields.Many2many('user.pengajuan.tempo.line', string="Suppliers") #Dokumen dokumen_nib = fields.Many2many('ir.attachment', 'pengajuan_dokumen_nib_rel', string="NIB (SIUP/TDP/SKDP)", tracking=3, track_visibility="onchange") dokumen_npwp = fields.Many2many('ir.attachment', 'pengajuan_dokumen_npwp_rel', string="NPWP Perusahaan", tracking=3) dokumen_sppkp = fields.Many2many('ir.attachment', 'pengajuan_dokumen_sppkp_rel', string="SPPKP Perusahaan", tracking=3) dokumen_akta_perubahan = fields.Many2many('ir.attachment', 'pengajuan_dokumen_akta_perubahan_rel', string="Akta Perubahan", tracking=3) dokumen_ktp_dirut = fields.Many2many('ir.attachment', 'pengajuan_dokumen_ktp_dirut_rel', string="KTP Dirut/Direktur", tracking=3) dokumen_akta_pendirian = fields.Many2many('ir.attachment', 'pengajuan_dokumen_angkta_pendirian_rel', string="Akta Pendirian", tracking=3) dokumen_laporan_keuangan = fields.Many2many('ir.attachment', 'pengajuan_dokumen_laporan_keuangan_rel', string="Laporan Keuangan", tracking=3) dokumen_foto_kantor = fields.Many2many('ir.attachment', 'pengajuan_dokumen_foto_kantor_rel', string=" Foto Kantor (Tampak Depan)", tracking=3) dokumen_tempat_bekerja = fields.Many2many('ir.attachment', 'pengajuan_dokumen_tempat_bekerja_rel', string="Tempat Bekerja", tracking=3) @api.depends('name', 'name_tempo') def name_get(self): result = [] for record in self: if record.name_tempo: display_name = f"DETAIL FORM TEMPO - {record.name_tempo.name}" else: display_name = "DETAIL FORM TEMPO" result.append((record.id, display_name)) return result # # def _compute_attachment_url(self): # if self.id: # return { # 'type': 'ir.actions.act_url', # 'url': 'http://localhost:8069/web/content/' % (self.id), # 'target': 'user', # } # base_url = self.env['ir.config_parameter'].sudo().get_param('web.base.url') # for record in self: # # Buat URL list untuk attachment yang ada di dokumen_nib # record.attachment_urls = [(attachment.id, f"{base_url}/web/content/{attachment.id}") for attachment in # record.dokumen_nib] # # @api.model # def create(self, vals): # # Tangani pembuatan baru # record = super(userPengajuanTempo, self).create(vals) # if vals.get('dokumen_nib'): # attachment_names = ', '.join(self.env['ir.attachment'].browse(vals['dokumen_nib'][0][2]).mapped('name')) # record.message_post(body=f"Files added to NIB: {attachment_names}") # return record # # def write(self, vals): # # Ambil attachment sebelumnya # for record in self: # previous_files = record.dokumen_nib # res = super(userPengajuanTempo, record).write(vals) # # if 'dokumen_nib' in vals: # new_files = record.dokumen_nib # # # Periksa perbedaan antara file lama dan file baru # added_files = new_files - previous_files # removed_files = previous_files - new_files # # # Buat pesan log berdasarkan perubahan # messages = [] # if added_files: # added_names = ', '.join(added_files.mapped('name')) # messages.append(f"Files added to NIB: {added_names}") # if removed_files: # removed_names = ', '.join(removed_files.mapped('name')) # messages.append(f"Files removed from NIB: {removed_names}") # # # Post pesan ke log note jika ada perubahan # if messages: # record.message_post(body="
".join(messages)) # # return res