1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
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="<br/>".join(messages))
#
# return res
|