diff options
Diffstat (limited to 'indoteknik_custom/models')
19 files changed, 1652 insertions, 76 deletions
diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py index 70a84bd0..43fbf146 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -34,6 +34,7 @@ from . import stock_picking_type from . import stock_picking from . import stock_vendor from . import user_company_request +from . import user_pengajuan_tempo_request from . import users from . import website_brand_homepage from . import website_categories_homepage @@ -131,7 +132,11 @@ from . import approval_unreserve from . import vendor_approval from . import partner from . import find_page +from . import user_pengajuan_tempo_line +from . import user_pengajuan_tempo from . import approval_retur_picking from . import va_multi_approve from . import va_multi_reject from . import vendor_sla +from . import stock_immediate_transfer +from . import coretax_fatur diff --git a/indoteknik_custom/models/account_move.py b/indoteknik_custom/models/account_move.py index 725b3c2d..42678847 100644 --- a/indoteknik_custom/models/account_move.py +++ b/indoteknik_custom/models/account_move.py @@ -325,3 +325,35 @@ class AccountMove(models.Model): # if rec.statement_line_id and not rec.statement_line_id.statement_id.is_edit and rec.statement_line_id.statement_id.state == 'confirm': # raise UserError('Bank Statement di Lock, Minta admin reconcile untuk unlock') # return res + + def validate_faktur_for_export(self): + invoices = self.filtered(lambda inv: not inv.is_efaktur_exported and + inv.state == 'posted' and + inv.move_type == 'out_invoice') + + invalid_invoices = self - invoices + if invalid_invoices: + invalid_ids = ", ".join(str(inv.id) for inv in invalid_invoices) + raise UserError(_( + "Faktur dengan ID berikut tidak valid untuk diekspor: {}.\n" + "Pastikan faktur dalam status 'posted', belum diekspor, dan merupakan 'out_invoice'.".format(invalid_ids) + )) + + return invoices + + def export_faktur_to_xml(self): + + valid_invoices = self.validate_faktur_for_export() + + # Panggil model coretax.faktur untuk menghasilkan XML + coretax_faktur = self.env['coretax.faktur'].create({}) + response = coretax_faktur.export_to_download(invoices=valid_invoices) + + current_time = datetime.utcnow() + # Tandai faktur sebagai sudah diekspor + valid_invoices.write({ + 'is_efaktur_exported': True, + 'date_efaktur_exported': current_time, # Set tanggal ekspor + }) + + return response diff --git a/indoteknik_custom/models/coretax_fatur.py b/indoteknik_custom/models/coretax_fatur.py new file mode 100644 index 00000000..ff8606b1 --- /dev/null +++ b/indoteknik_custom/models/coretax_fatur.py @@ -0,0 +1,119 @@ +from odoo import models, fields +import xml.etree.ElementTree as ET +from xml.dom import minidom +import base64 +import re + +class CoretaxFaktur(models.Model): + _name = 'coretax.faktur' + _description = 'Export Faktur ke XML' + + export_file = fields.Binary(string="Export File", ) + export_filename = fields.Char(string="Export File", ) + + def validate_and_format_number(slef, input_number): + # Hapus semua karakter non-digit + cleaned_number = re.sub(r'\D', '', input_number) + + total_sum = sum(int(char) for char in cleaned_number) + if total_sum == 0 : + return '0000000000000000' + + # Hitung jumlah digit + digit_count = len(cleaned_number) + + # Jika jumlah digit kurang dari 15, tambahkan nol di depan + if digit_count < 16: + cleaned_number = cleaned_number.zfill(16) + + return cleaned_number + + def generate_xml(self, invoices=None): + # Buat root XML + root = ET.Element('TaxInvoiceBulk', { + 'xmlns:xsi': "http://www.w3.org/2001/XMLSchema-instance", + 'xsi:noNamespaceSchemaLocation': "TaxInvoice.xsd" + }) + ET.SubElement(root, 'TIN').text = '0742260227086000' + + # Tambahkan elemen ListOfTaxInvoice + list_of_tax_invoice = ET.SubElement(root, 'ListOfTaxInvoice') + + # Dapatkan data faktur + # inv_obj = self.env['account.move'] + # invoices = inv_obj.search([('is_efaktur_exported','=',True), + # ('state','=','posted'), + # ('efaktur_id','!=', False), + # ('move_type','=','out_invoice')], limit = 5) + + for invoice in invoices: + tax_invoice = ET.SubElement(list_of_tax_invoice, 'TaxInvoice') + buyerTIN = self.validate_and_format_number(invoice.partner_id.npwp) + buyerIDTKU = buyerTIN.ljust(len(buyerTIN) + 6, '0') if sum(int(char) for char in buyerTIN) > 0 else '000000' + + # Tambahkan elemen faktur + ET.SubElement(tax_invoice, 'TaxInvoiceDate').text = invoice.invoice_date.strftime('%Y-%m-%d') if invoice.invoice_date else '' + ET.SubElement(tax_invoice, 'TaxInvoiceOpt').text = 'Normal' + ET.SubElement(tax_invoice, 'TrxCode').text = '04' + ET.SubElement(tax_invoice, 'AddInfo') + ET.SubElement(tax_invoice, 'CustomDoc') + ET.SubElement(tax_invoice, 'RefDesc').text = invoice.name + ET.SubElement(tax_invoice, 'FacilityStamp') + ET.SubElement(tax_invoice, 'SellerIDTKU').text = '0742260227086000000000' + ET.SubElement(tax_invoice, 'BuyerTin').text = buyerTIN + ET.SubElement(tax_invoice, 'BuyerDocument').text = 'TIN' if sum(int(char) for char in buyerTIN) > 0 else 'Other ID' + ET.SubElement(tax_invoice, 'BuyerCountry').text = 'IDN' + ET.SubElement(tax_invoice, 'BuyerDocumentNumber').text = str(invoice.partner_id.id) + ET.SubElement(tax_invoice, 'BuyerName').text = invoice.partner_id.nama_wajib_pajak or '' + ET.SubElement(tax_invoice, 'BuyerAdress').text = invoice.partner_id.alamat_lengkap_text or '' + ET.SubElement(tax_invoice, 'BuyerEmail').text = invoice.partner_id.email or '' + ET.SubElement(tax_invoice, 'BuyerIDTKU').text = buyerIDTKU + + # Tambahkan elemen ListOfGoodService + list_of_good_service = ET.SubElement(tax_invoice, 'ListOfGoodService') + for line in invoice.invoice_line_ids: + otherTaxBase = round(line.price_subtotal * (11/12)) if line.price_subtotal else 0 + good_service = ET.SubElement(list_of_good_service, 'GoodService') + ET.SubElement(good_service, 'Opt').text = 'A' + ET.SubElement(good_service, 'Code') + ET.SubElement(good_service, 'Name').text = line.name + ET.SubElement(good_service, 'Unit').text = 'UM.0018' + ET.SubElement(good_service, 'Price').text = str(round(line.price_subtotal/line.quantity, 2)) if line.price_subtotal else '0' + ET.SubElement(good_service, 'Qty').text = str(line.quantity) + ET.SubElement(good_service, 'TotalDiscount').text = '0' + ET.SubElement(good_service, 'TaxBase').text = str(round(line.price_subtotal)) if line.price_subtotal else '0' + ET.SubElement(good_service, 'OtherTaxBase').text = str(otherTaxBase) + ET.SubElement(good_service, 'VATRate').text = '12' + ET.SubElement(good_service, 'VAT').text = str(round(otherTaxBase * 0.12, 2)) + ET.SubElement(good_service, 'STLGRate').text = '0' + ET.SubElement(good_service, 'STLG').text = '0' + + # Pretty print XML + xml_str = ET.tostring(root, encoding='utf-8') + xml_pretty = minidom.parseString(xml_str).toprettyxml(indent=" ") + return xml_pretty + + def export_to_download(self, invoices): + # Generate XML content + xml_content = self.generate_xml(invoices) + + # Encode content to Base64 + xml_encoded = base64.b64encode(xml_content.encode('utf-8')) + + # Buat attachment untuk XML + attachment = self.env['ir.attachment'].create({ + 'name': 'Faktur_XML.xml', + 'type': 'binary', + 'datas': xml_encoded, + 'mimetype': 'application/xml', + 'store_fname': 'faktur_xml.xml', + }) + + # Kembalikan URL untuk download dengan header 'Content-Disposition' + response = { + 'type': 'ir.actions.act_url', + 'url': '/web/content/{}?download=true'.format(attachment.id), + 'target': 'self', + } + + return response diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index 6fb8c7a0..5bedae13 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -5,7 +5,9 @@ import logging import requests import json import re +import qrcode, base64 from bs4 import BeautifulSoup +from io import BytesIO _logger = logging.getLogger(__name__) @@ -58,10 +60,30 @@ class ProductTemplate(models.Model): ('sp', 'Spare Part'), ('acc', 'Accessories') ], string='Kind of', copy=False) - sni = fields.Boolean(string='SNI') + sni = fields.Boolean(string='SNI') tkdn = fields.Boolean(string='TKDN') short_spesification = fields.Char(string='Short Spesification') merchandise_ok = fields.Boolean(string='Product Promotion') + print_barcode = fields.Boolean(string='Print Barcode', default=True) + # qr_code = fields.Binary("QR Code", compute='_compute_qr_code') + + # def _compute_qr_code(self): + # for rec in self.product_variant_ids: + # qr = qrcode.QRCode( + # version=1, + # error_correction=qrcode.constants.ERROR_CORRECT_L, + # box_size=5, + # border=4, + # ) + # qr.add_data(rec.display_name) + # qr.make(fit=True) + # img = qr.make_image(fill_color="black", back_color="white") + + # buffer = BytesIO() + # img.save(buffer, format="PNG") + # qr_code_img = base64.b64encode(buffer.getvalue()).decode() + + # rec.qr_code = qr_code_img @api.constrains('name', 'internal_reference', 'x_manufacture') def required_public_categ_ids(self): @@ -379,6 +401,30 @@ class ProductProduct(models.Model): qty_rpo = fields.Float(string='Qty RPO', compute='_get_qty_rpo') plafon_qty = fields.Float(string='Max Plafon', compute='_get_plafon_qty_product') merchandise_ok = fields.Boolean(string='Product Promotion') + qr_code_variant = fields.Binary("QR Code Variant", compute='_compute_qr_code_variant') + + def _compute_qr_code_variant(self): + for rec in self: + # Skip inactive variants + if not rec.active: + rec.qr_code_variant = False # Clear the QR Code for archived variants + continue + + qr = qrcode.QRCode( + version=1, + error_correction=qrcode.constants.ERROR_CORRECT_L, + box_size=5, + border=4, + ) + qr.add_data(rec.default_code) + qr.make(fit=True) + img = qr.make_image(fill_color="black", back_color="white") + + buffer = BytesIO() + img.save(buffer, format="PNG") + qr_code_img = base64.b64encode(buffer.getvalue()).decode() + + rec.qr_code_variant = qr_code_img def _get_clean_website_description(self): for rec in self: diff --git a/indoteknik_custom/models/purchase_order.py b/indoteknik_custom/models/purchase_order.py index 9388ae4c..799c4db0 100755 --- a/indoteknik_custom/models/purchase_order.py +++ b/indoteknik_custom/models/purchase_order.py @@ -74,6 +74,29 @@ class PurchaseOrder(models.Model): approve_by = fields.Many2one('res.users', string='Approve By') exclude_incoming = fields.Boolean(string='Exclude Incoming', default=False, help='Centang jika tidak mau masuk perhitungan Incoming Qty') + not_update_purchasepricelist = fields.Boolean(string='Not Update Purchase Pricelist?') + # total_cost_service = fields.Float(string='Total Cost Service') + # total_delivery_amt = fields.Float(string='Total Delivery Amt') + + # @api.onchange('total_cost_service') + # def _onchange_total_cost_service(self): + # for order in self: + # lines = order.order_line + # if lines: + # # Hitung nilai rata-rata cost_service + # per_line_cost_service = order.total_cost_service / len(lines) + # for line in lines: + # line.cost_service = per_line_cost_service + + # @api.onchange('total_delivery_amt') + # def _onchange_total_delivery_amt(self): + # for order in self: + # lines = order.order_line + # if lines: + # # Hitung nilai rata-rata delivery_amt + # per_line_delivery_amt = order.total_delivery_amt / len(lines) + # for line in lines: + # line.delivery_amt = per_line_delivery_amt def _compute_total_margin_match(self): for purchase in self: @@ -114,6 +137,7 @@ class PurchaseOrder(models.Model): 'ref': self.name, 'invoice_date': current_date, 'date': current_date, + 'invoice_origin': self.name, 'move_type': 'in_invoice' } @@ -164,6 +188,11 @@ class PurchaseOrder(models.Model): self.bills_pelunasan_id = bills.id + lognote_message = ( + f"Vendor bill created from: {self.name} ({self.partner_ref})" + ) + bills.message_post(body=lognote_message) + return { 'name': _('Account Move'), 'view_mode': 'tree,form', @@ -173,12 +202,10 @@ class PurchaseOrder(models.Model): 'domain': [('id', '=', bills.id)] } - - def create_bill_dp(self): if not self.env.user.is_accounting: raise UserError('Hanya Accounting yang bisa bikin bill dp') - + current_date = datetime.utcnow() data_bills = { 'partner_id': self.partner_id.id, @@ -186,8 +213,8 @@ class PurchaseOrder(models.Model): 'ref': self.name, 'invoice_date': current_date, 'date': current_date, + 'invoice_origin': self.name, 'move_type': 'in_invoice' - } bills = self.env['account.move'].create([data_bills]) @@ -196,14 +223,13 @@ class PurchaseOrder(models.Model): data_line_bills = { 'move_id': bills.id, - 'product_id': product_dp.id, #product down payment - 'account_id': 401, #Uang Muka persediaan barang dagang + 'product_id': product_dp.id, # product down payment + 'account_id': 401, # Uang Muka persediaan barang dagang 'quantity': 1, 'product_uom_id': 1, 'tax_ids': [line[0].taxes_id.id for line in self.order_line], } - bills_line = self.env['account.move.line'].create([data_line_bills]) self.bills_dp_id = bills.id @@ -212,6 +238,11 @@ class PurchaseOrder(models.Model): move_line.name = '[IT.121456] Down Payment' move_line.partner_id = self.partner_id.id + lognote_message = ( + f"Vendor bill created from: {self.name} ({self.partner_ref})" + ) + bills.message_post(body=lognote_message) + return { 'name': _('Account Move'), 'view_mode': 'tree,form', @@ -620,7 +651,8 @@ class PurchaseOrder(models.Model): raise UserError("Tidak ada link dengan SO, harus approval Merchandise") send_email = False - self.add_product_to_pricelist() + if not self.not_update_purchasepricelist: + self.add_product_to_pricelist() for line in self.order_line: if not line.product_id.purchase_ok: raise UserError("Terdapat barang yang tidak bisa diproses") diff --git a/indoteknik_custom/models/requisition.py b/indoteknik_custom/models/requisition.py index 32a9f94f..c972b485 100644 --- a/indoteknik_custom/models/requisition.py +++ b/indoteknik_custom/models/requisition.py @@ -82,11 +82,11 @@ class Requisition(models.Model): state = ['done', 'sale'] if self.sale_order_id.state in state: raise UserError('SO sudah Confirm, akan berakibat double Purchase melalui PJ') - if self.env.user.id not in [377, 19]: + if self.env.user.id not in [377, 19, 28]: raise UserError('Hanya Vita dan Darren Yang Bisa Approve') - if self.env.user.id == 377: + if self.env.user.id == 377 or self.env.user.id == 28: self.sales_approve = True - elif self.env.user.id == 19: + elif self.env.user.id == 19 or self.env.user.id == 28: if not self.sales_approve: raise UserError('Vita Belum Approve') self.merchandise_approve = True diff --git a/indoteknik_custom/models/res_partner.py b/indoteknik_custom/models/res_partner.py index da4a6cb6..57fab403 100644 --- a/indoteknik_custom/models/res_partner.py +++ b/indoteknik_custom/models/res_partner.py @@ -20,6 +20,78 @@ class ResPartner(models.Model): domain="[('internal_type', '=', 'receivable'), ('deprecated', '=', False), ('company_id', '=', current_company_id)]", help="This account will be used instead of the default one as the receivable account for the current partner", default=395) + # Referensi + supplier_ids = fields.Many2many('user.pengajuan.tempo.line', string="Suppliers") + + # informasi perusahaan + name_tempo = fields.Many2one('res.partner', string='Nama Perusahaan',tracking=True) + 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') + portal = fields.Boolean(string='Portal 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') + district_id_pengiriman = fields.Many2one('vit.kecamatan', string='Kecamatan') + subDistrict_id_pengiriman = fields.Many2one('vit.kelurahan', string='Kelurahan') + 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') + district_id_invoice = fields.Many2one('vit.kecamatan', string='Kecamatan') + subDistrict_id_invoice = fields.Many2one('vit.kelurahan', string='Kelurahan') + zip_invoice = fields.Char(string="Zip") + tukar_invoice = fields.Char(string='Jadwal Penukaran Invoice') + jadwal_bayar = fields.Char(string='Jadwal Pembayaran') + dokumen_pengiriman = fields.Char(string='Dokumen Tanda Terima yang Diberikan Pada Saat Pengiriman Barang') + dokumen_pengiriman_input = fields.Char(string='Dokumen yang Dibawa Saat Pengiriman Barang') + dokumen_invoice = fields.Char(string='Dokumen yang dilampirkan saat Pengiriman Invoice') + + # Dokumen + dokumen_npwp = fields.Many2one('ir.attachment', string="NPWP Perusahaan", tracking=3, readonly=True) + dokumen_sppkp = fields.Many2one('ir.attachment', string="SPPKP Perusahaan", tracking=3, readonly=True) + dokumen_nib = fields.Many2one('ir.attachment', string="NIB (SIUP/TDP/SKDP)", tracking=3, readonly=True,) + dokumen_siup = fields.Many2one('ir.attachment', string="SIUP Perusahaan", tracking=3, readonly=True) + dokumen_tdp = fields.Many2one('ir.attachment', string="TDP Perusahaan", tracking=3, readonly=True) + dokumen_skdp = fields.Many2one('ir.attachment', string="SKDP Perusahaan",tracking=True, readonly=True) + dokumen_skt = fields.Many2one('ir.attachment', string="SKT Perusahaan", tracking=True, readonly=True) + dokumen_akta_perubahan = fields.Many2one('ir.attachment', string="Akta Perubahan", tracking=3, readonly=True) + dokumen_ktp_dirut = fields.Many2one('ir.attachment', string="KTP Dirut/Direktur", tracking=3, readonly=True) + dokumen_akta_pendirian = fields.Many2one('ir.attachment', string="Akta Pendirian", tracking=3, readonly=True) + dokumen_laporan_keuangan = fields.Many2one('ir.attachment', string="Laporan Keuangan", tracking=3, readonly=True) + dokumen_foto_kantor = fields.Many2one('ir.attachment', string=" Foto Kantor (Tampak Depan)", tracking=3, readonly=True) + dokumen_tempat_bekerja = fields.Many2one('ir.attachment', string="Tempat Bekerja", tracking=3, readonly=True) + reference_number = fields.Char(string="Reference Number") company_type_id = fields.Many2one('res.partner.company_type', string='Company Type') custom_pricelist_id = fields.Many2one('product.pricelist', string='Price Matrix') @@ -92,23 +164,22 @@ class ResPartner(models.Model): if partner.company_type == 'person' and not partner.parent_id: partner.alamat_lengkap_text = partner.street # if partner.company_type == 'person' and partner.parent_id: - # partner.alamat_lengkap_text = partner.parent_id.alamat_lengkap_text + # partner.alamat_lengkap_text = partner.parent_id.alamat_lengkap_text - - alamat_lengkap_text = fields.Text(string="Alamat Lengkap", required=False , tracking=3) + alamat_lengkap_text = fields.Text(string="Alamat Lengkap", required=False, tracking=3) def write(self, vals): res = super(ResPartner, self).write(vals) - # - # # if 'property_payment_term_id' in vals: - # # if not self.env.user.is_accounting and vals['property_payment_term_id'] != 26: - # # raise UserError('Hanya Finance Accounting yang dapat merubah payment term') - # - # # group_id = self.env.ref('indoteknik_custom.group_role_merchandiser').id - # # users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])]) - # # if self.env.user.id not in users_in_group.mapped('id'): - # # raise UserError('You name it') - # + # + # # if 'property_payment_term_id' in vals: + # # if not self.env.user.is_accounting and vals['property_payment_term_id'] != 26: + # # raise UserError('Hanya Finance Accounting yang dapat merubah payment term') + # + # # group_id = self.env.ref('indoteknik_custom.group_role_merchandiser').id + # # users_in_group = self.env['res.users'].search([('groups_id', 'in', [group_id])]) + # # if self.env.user.id not in users_in_group.mapped('id'): + # # raise UserError('You name it') + # return res def write(self, vals): @@ -133,8 +204,74 @@ class ResPartner(models.Model): vals['sppkp'] = vals.get('sppkp', self.sppkp) vals['alamat_lengkap_text'] = vals.get('alamat_lengkap_text', self.alamat_lengkap_text) vals['industry_id'] = vals.get('industry_id', self.industry_id.id if self.industry_id else None) - vals['company_type_id'] = vals.get('company_type_id', - self.company_type_id.id if self.company_type_id else None) + vals['company_type_id'] = vals.get('company_type_id', self.company_type_id.id if self.company_type_id else None) + + # Referensi + vals['supplier_ids'] = vals.get('supplier_ids', self.supplier_ids) + + # informasi perusahaan + vals['name_tempo'] = vals.get('name_tempo', self.name_tempo) + vals['industry_id_tempo'] = vals.get('industry_id_tempo', self.industry_id_tempo) + vals['street_tempo'] = vals.get('street_tempo', self.street_tempo) + vals['state_id_tempo'] = vals.get('state_id_tempo', self.state_id_tempo) + vals['city_id_tempo'] = vals.get('city_id_tempo', self.city_id_tempo) + vals['zip_tempo'] = vals.get('zip_tempo', self.zip_tempo) + vals['bank_name_tempo'] = vals.get('bank_name_tempo', self.bank_name_tempo) + vals['account_name_tempo'] = vals.get('account_name_tempo', self.account_name_tempo) + vals['account_number_tempo'] = vals.get('account_number_tempo', self.account_number_tempo) + vals['website_tempo'] = vals.get('website_tempo', self.website_tempo) + vals['portal'] = vals.get('portal', self.portal) + vals['estimasi_tempo'] = vals.get('estimasi_tempo', self.estimasi_tempo) + vals['tempo_duration'] = vals.get('tempo_duration', self.tempo_duration) + vals['tempo_limit'] = vals.get('tempo_limit', self.tempo_limit) + vals['category_produk_ids'] = vals.get('category_produk_ids', self.category_produk_ids) + + # Kontak Perusahaan + vals['direktur_name'] = vals.get('direktur_name', self.direktur_name) + vals['direktur_mobile'] = vals.get('direktur_mobile', self.direktur_mobile) + vals['direktur_email'] = vals.get('direktur_email', self.direktur_email) + vals['purchasing_name'] = vals.get('purchasing_name', self.purchasing_name) + vals['purchasing_mobile'] = vals.get('purchasing_mobile', self.purchasing_mobile) + vals['purchasing_email'] = vals.get('purchasing_email', self.purchasing_email) + vals['finance_name'] = vals.get('finance_name', self.finance_name) + vals['finance_mobile'] = vals.get('finance_mobile', self.finance_mobile) + vals['finance_email'] = vals.get('finance_email', self.finance_email) + + # Pengiriman + vals['pic_name'] = vals.get('pic_name', self.pic_name) + vals['street_pengiriman'] = vals.get('street_pengiriman', self.street_pengiriman) + vals['state_id_pengiriman'] = vals.get('state_id_pengiriman', self.state_id_pengiriman) + vals['city_id_pengiriman'] = vals.get('city_id_pengiriman', self.city_id_pengiriman) + vals['district_id_pengiriman'] = vals.get('district_id_pengiriman', self.district_id_pengiriman) + vals['subDistrict_id_pengiriman'] = vals.get('subDistrict_id_pengiriman', self.subDistrict_id_pengiriman) + vals['zip_pengiriman'] = vals.get('zip_pengiriman', self.zip_pengiriman) + vals['invoice_pic'] = vals.get('invoice_pic', self.invoice_pic) + vals['street_invoice'] = vals.get('street_invoice', self.street_invoice) + vals['state_id_invoice'] = vals.get('state_id_invoice', self.state_id_invoice) + vals['city_id_invoice'] = vals.get('city_id_invoice', self.city_id_invoice) + vals['district_id_invoice'] = vals.get('district_id_invoice', self.district_id_invoice) + vals['subDistrict_id_invoice'] = vals.get('subDistrict_id_invoice', self.subDistrict_id_invoice) + vals['zip_invoice'] = vals.get('zip_invoice', self.zip_invoice) + vals['tukar_invoice'] = vals.get('tukar_invoice', self.tukar_invoice) + vals['jadwal_bayar'] = vals.get('jadwal_bayar', self.jadwal_bayar) + vals['dokumen_pengiriman'] = vals.get('dokumen_pengiriman', self.dokumen_pengiriman) + vals['dokumen_pengiriman_input'] = vals.get('dokumen_pengiriman_input', self.dokumen_pengiriman_input) + vals['dokumen_invoice'] = vals.get('dokumen_invoice', self.dokumen_invoice) + + # Dokumen + vals['dokumen_npwp'] = vals.get('dokumen_npwp', self.dokumen_npwp) + vals['dokumen_sppkp'] = vals.get('dokumen_sppkp', self.dokumen_sppkp) + vals['dokumen_nib'] = vals.get('dokumen_nib', self.dokumen_nib) + vals['dokumen_siup'] = vals.get('dokumen_siup', self.dokumen_siup) + vals['dokumen_tdp'] = vals.get('dokumen_tdp', self.dokumen_tdp) + vals['dokumen_skdp'] = vals.get('dokumen_skdp', self.dokumen_skdp) + vals['dokumen_skt'] = vals.get('dokumen_skt', self.dokumen_skt) + vals['dokumen_akta_perubahan'] = vals.get('dokumen_akta_perubahan', self.dokumen_akta_perubahan) + vals['dokumen_ktp_dirut'] = vals.get('dokumen_ktp_dirut', self.dokumen_ktp_dirut) + vals['dokumen_akta_pendirian'] = vals.get('dokumen_akta_pendirian', self.dokumen_akta_pendirian) + vals['dokumen_laporan_keuangan'] = vals.get('dokumen_laporan_keuangan', self.dokumen_laporan_keuangan) + vals['dokumen_foto_kantor'] = vals.get('dokumen_foto_kantor', self.dokumen_foto_kantor) + vals['dokumen_tempat_bekerja'] = vals.get('dokumen_tempat_bekerja', self.dokumen_tempat_bekerja) # Simpan hanya field yang perlu di-update pada child vals_for_child = { @@ -144,7 +281,67 @@ class ResPartner(models.Model): 'sppkp': vals.get('sppkp'), 'alamat_lengkap_text': vals.get('alamat_lengkap_text'), 'industry_id': vals.get('industry_id'), - 'company_type_id': vals.get('company_type_id') + 'company_type_id': vals.get('company_type_id'), + 'supplier_ids': vals.get('supplier_ids'), + 'name_tempo': vals.get('name_tempo'), + 'industry_id_tempo': vals.get('industry_id_tempo'), + 'street_tempo': vals.get('street_tempo'), + 'state_id_tempo': vals.get('state_id_tempo'), + 'city_id_tempo': vals.get('city_id_tempo'), + 'zip_tempo': vals.get('zip_tempo'), + 'bank_name_tempo': vals.get('bank_name_tempo'), + 'account_name_tempo': vals.get('account_name_tempo'), + 'account_number_tempo': vals.get('account_number_tempo'), + 'website_tempo': vals.get('website_tempo'), + 'portal': vals.get('portal'), + 'estimasi_tempo': vals.get('estimasi_tempo'), + 'tempo_duration': vals.get('tempo_duration'), + 'tempo_limit': vals.get('tempo_limit'), + 'category_produk_ids': vals.get('category_produk_ids'), + 'direktur_name': vals.get('direktur_name'), + 'direktur_mobile': vals.get('direktur_mobile'), + 'direktur_email': vals.get('direktur_email'), + 'purchasing_name': vals.get('purchasing_name'), + 'purchasing_mobile': vals.get('purchasing_mobile'), + 'purchasing_email': vals.get('purchasing_email'), + 'finance_name': vals.get('finance_name'), + 'finance_mobile': vals.get('finance_mobile'), + 'finance_email': vals.get('finance_email'), + 'pic_name': vals.get('pic_name'), + 'street_pengiriman': vals.get('street_pengiriman'), + 'state_id_pengiriman': vals.get('state_id_pengiriman'), + 'city_id_pengiriman': vals.get('city_id_pengiriman'), + 'district_id_pengiriman': vals.get('district_id_pengiriman'), + 'subDistrict_id_pengiriman': vals.get('subDistrict_id_pengiriman'), + 'zip_pengiriman': vals.get('zip_pengiriman'), + 'invoice_pic': vals.get('invoice_pic'), + 'street_invoice': vals.get('street_invoice'), + 'state_id_invoice': vals.get('state_id_invoice'), + 'city_id_invoice': vals.get('city_id_invoice'), + 'district_id_invoice': vals.get('district_id_invoice'), + 'subDistrict_id_invoice': vals.get('subDistrict_id_invoice'), + 'zip_invoice': vals.get('zip_invoice'), + 'tukar_invoice': vals.get('tukar_invoice'), + 'jadwal_bayar': vals.get('jadwal_bayar'), + 'dokumen_pengiriman': vals.get('dokumen_pengiriman'), + 'dokumen_pengiriman_input': vals.get('dokumen_pengiriman_input'), + 'dokumen_invoice': vals.get('dokumen_invoice'), + 'dokumen_npwp': vals.get('dokumen_npwp'), + 'dokumen_sppkp': vals.get('dokumen_sppkp'), + 'dokumen_nib': vals.get('dokumen_nib'), + 'dokumen_siup': vals.get('dokumen_siup'), + 'dokumen_tdp': vals.get('dokumen_tdp'), + 'dokumen_skdp': vals.get('dokumen_skdp'), + 'dokumen_skt': vals.get('dokumen_skt'), + 'dokumen_akta_perubahan': vals.get('dokumen_akta_perubahan'), + 'dokumen_ktp_dirut': vals.get('dokumen_ktp_dirut'), + 'dokumen_akta_pendirian': vals.get('dokumen_akta_pendirian'), + 'dokumen_laporan_keuangan': vals.get('dokumen_laporan_keuangan'), + 'dokumen_foto_kantor': vals.get('dokumen_foto_kantor'), + 'dokumen_tempat_bekerja': vals.get('dokumen_tempat_bekerja'), + + # internal_notes + 'comment': vals.get('comment') } # Lakukan update pada semua child secara rekursif @@ -245,13 +442,10 @@ class ResPartner(models.Model): if self.customer_type == 'nonpkp': self.npwp = '00.000.000.0-000.000' - def get_check_tempo_partner(self): + def get_check_payment_term(self): self.ensure_one() partner = self.parent_id or self - if not partner.property_payment_term_id or 'Tempo' not in partner.property_payment_term_id.name: - return False - else: - return True + return partner.property_payment_term_id.name if partner.property_payment_term_id.id else 'Cash Before Delivery (C.B.D)' diff --git a/indoteknik_custom/models/res_users.py b/indoteknik_custom/models/res_users.py index 5e16aad1..fb9e8bfb 100755 --- a/indoteknik_custom/models/res_users.py +++ b/indoteknik_custom/models/res_users.py @@ -46,6 +46,11 @@ class ResUsers(models.Model): for user in self: template.send_mail(user.id, force_send=True) + def send_company_request_tempo_review(self): + template = self.env.ref('indoteknik_custom.mail_template_res_user_company_tempo_review') + for user in self: + template.send_mail(user.id, force_send=True) + def get_activation_token_url(self): base_url = self.env['ir.config_parameter'].get_param('site.base.url') return f'{base_url}/register?activation=token&token={self.activation_token}' diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 7fc6d96a..7b2d9bf8 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -758,6 +758,7 @@ class SaleOrder(models.Model): raise UserError("Salesperson sudah tidak aktif, mohon diisi yang benar pada data SO dan Contact") def sale_order_approve(self): + self.check_credit_limit() if self.validate_different_vendor() and not self.vendor_approval: return self._create_notification_action('Notification', 'Terdapat Vendor yang berbeda dengan MD Vendor') self.check_due() @@ -890,6 +891,37 @@ class SaleOrder(models.Model): 'email_to': salesperson_email, }).send() + def check_credit_limit(self): + for rec in self: + outstanding_amount = rec.outstanding_amount + check_credit_limit = False + ###### + block_stage = 0 + if rec.partner_id.parent_id: + if rec.partner_id.parent_id.active_limit and rec.partner_id.parent_id.enable_credit_limit: + check_credit_limit = True + else: + if rec.partner_id.active_limit and rec.partner_id.enable_credit_limit: + check_credit_limit = True + + term_days = 0 + for term_line in rec.payment_term_id.line_ids: + term_days += term_line.days + if term_days == 0: + check_credit_limit = False + + if check_credit_limit: + if rec.partner_id.parent_id: + block_stage = rec.partner_id.parent_id.blocking_stage or 0 + else: + block_stage = rec.partner_id.blocking_stage or 0 + + if (outstanding_amount + rec.amount_total) >= block_stage: + if block_stage != 0: + remaining_credit_limit = block_stage - outstanding_amount + raise UserError(_("%s is in Blocking Stage, Remaining credit limit is %s, from %s and outstanding %s") + % (rec.partner_id.name, remaining_credit_limit, block_stage, outstanding_amount)) + def validate_different_vendor(self): if self.vendor_approval_id.filtered(lambda v: v.state == 'draft'): draft_names = ", ".join(self.vendor_approval_id.filtered(lambda v: v.state == 'draft').mapped('number')) @@ -999,8 +1031,9 @@ class SaleOrder(models.Model): if self.have_outstanding_invoice: raise UserError("Invoice harus di Cancel dahulu") - elif self.have_outstanding_picking: - raise UserError("DO harus di Cancel dahulu") + for line in self.order_line: + if line.qty_delivered > 0: + raise UserError("DO harus di-cancel terlebih dahulu.") if not self.web_approval: self.web_approval = 'company' @@ -1378,4 +1411,16 @@ class SaleOrder(models.Model): 'npwp': partner.npwp, 'email': partner.email, 'customer_type': partner.customer_type, - })
\ No newline at end of file + }) + + def write(self, vals): + for order in self: + if order.state in ['sale', 'cancel']: + if 'order_line' in vals: + new_lines = vals.get('order_line', []) + for command in new_lines: + if command[0] == 0: # A new line is being added + raise UserError( + "SO tidak dapat ditambahkan produk baru karena SO sudah menjadi sale order.") + res = super(SaleOrder, self).write(vals) + return res
\ No newline at end of file diff --git a/indoteknik_custom/models/sale_order_line.py b/indoteknik_custom/models/sale_order_line.py index a31ff569..29a046fa 100644 --- a/indoteknik_custom/models/sale_order_line.py +++ b/indoteknik_custom/models/sale_order_line.py @@ -38,6 +38,14 @@ class SaleOrderLine(models.Model): md_vendor_id = fields.Many2one('res.partner', string='MD Vendor', readonly=True) margin_md = fields.Float(string='Margin MD') qty_free_bu = fields.Float(string='Free BU', compute='_get_qty_free_bandengan') + desc_updatable = fields.Boolean(string='desc boolean', default=False, compute='_get_desc_updatable') + + def _get_desc_updatable(self): + for line in self: + if line.product_id.id != 417724: + line.desc_updatable = False + else: + line.desc_updatable = True def _get_qty_free_bandengan(self): for line in self: @@ -272,6 +280,10 @@ class SaleOrderLine(models.Model): (line.product_id.short_spesification if line.product_id.short_spesification else '') line.name = line_name line.weight = line.product_id.weight + if line.product_id.id != 417724: + line.desc_updatable = False + else: + line.desc_updatable = True @api.constrains('vendor_id') def _check_vendor_id(self): @@ -378,4 +390,14 @@ class SaleOrderLine(models.Model): if not line.product_id.product_tmpl_id.sale_ok: raise UserError('Product %s belum bisa dijual, harap hubungi finance' % line.product_id.display_name) if not line.vendor_id or not line.purchase_price and not line.display_type == 'line_note': - raise UserError(_('Isi Vendor dan Harga Beli sebelum Request Approval'))
\ No newline at end of file + raise UserError(_('Isi Vendor dan Harga Beli sebelum Request Approval')) + + @api.depends('state') + def _compute_product_updatable(self): + for line in self: + if line.state == 'draft': + line.product_updatable = True + # line.desc_updatable = True + else: + line.product_updatable = False + # line.desc_updatable = False diff --git a/indoteknik_custom/models/solr/apache_solr.py b/indoteknik_custom/models/solr/apache_solr.py index 6560c9b5..d111c1c1 100644 --- a/indoteknik_custom/models/solr/apache_solr.py +++ b/indoteknik_custom/models/solr/apache_solr.py @@ -22,7 +22,7 @@ class ApacheSolr(models.Model): url = '' if env == 'development': - url = 'http://192.168.23.5:8983/solr/' + url = 'http://localhost:8983/solr/' elif env == 'production': url = 'http://34.101.189.218:8983/solr/' diff --git a/indoteknik_custom/models/stock_immediate_transfer.py b/indoteknik_custom/models/stock_immediate_transfer.py new file mode 100644 index 00000000..4be0dff2 --- /dev/null +++ b/indoteknik_custom/models/stock_immediate_transfer.py @@ -0,0 +1,36 @@ +from odoo import models, api, _ +from odoo.exceptions import UserError + +class StockImmediateTransfer(models.TransientModel): + _inherit = 'stock.immediate.transfer' + + def process(self): + """Override process method to add send_mail_bills logic.""" + pickings_to_do = self.env['stock.picking'] + pickings_not_to_do = self.env['stock.picking'] + + for line in self.immediate_transfer_line_ids: + if line.to_immediate is True: + pickings_to_do |= line.picking_id + else: + pickings_not_to_do |= line.picking_id + + for picking in pickings_to_do: + picking.send_mail_bills() + # If still in draft => confirm and assign + if picking.state == 'draft': + picking.action_confirm() + if picking.state != 'assigned': + picking.action_assign() + if picking.state != 'assigned': + raise UserError(_("Could not reserve all requested products. Please use the 'Mark as Todo' button to handle the reservation manually.")) + for move in picking.move_lines.filtered(lambda m: m.state not in ['done', 'cancel']): + for move_line in move.move_line_ids: + move_line.qty_done = move_line.product_uom_qty + + pickings_to_validate = self.env.context.get('button_validate_picking_ids') + if pickings_to_validate: + pickings_to_validate = self.env['stock.picking'].browse(pickings_to_validate) + pickings_to_validate = pickings_to_validate - pickings_not_to_do + return pickings_to_validate.with_context(skip_immediate=True).button_validate() + return True diff --git a/indoteknik_custom/models/stock_move.py b/indoteknik_custom/models/stock_move.py index ac2e3cc0..e1d4e74c 100644 --- a/indoteknik_custom/models/stock_move.py +++ b/indoteknik_custom/models/stock_move.py @@ -7,6 +7,27 @@ class StockMove(models.Model): line_no = fields.Integer('No', default=0) sale_id = fields.Many2one('sale.order', string='SO') + print_barcode = fields.Boolean( + string="Print Barcode", + default=lambda self: self.product_id.print_barcode, + ) + qr_code_variant = fields.Binary("QR Code Variant", compute='_compute_qr_code_variant') + + def _compute_qr_code_variant(self): + for rec in self: + if rec.print_barcode and rec.print_barcode == True and rec.product_id and rec.product_id.qr_code_variant: + rec.qr_code_variant = rec.product_id.qr_code_variant + else: + rec.qr_code_variant = False + + + def write(self, vals): + res = super(StockMove, self).write(vals) + if 'print_barcode' in vals: + for line in self: + if line.product_id: + line.product_id.print_barcode = vals['print_barcode'] + return res def _do_unreserve(self, product=None, quantity=False): moves_to_unreserve = OrderedSet() diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index e6506a0b..cd330aeb 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -6,10 +6,17 @@ from itertools import groupby import pytz, requests, json, requests from dateutil import parser import datetime - +import hmac +import hashlib +import base64 +import requests +import time +import logging +_logger = logging.getLogger(__name__) class StockPicking(models.Model): _inherit = 'stock.picking' + # check_product_lines = fields.One2many('check.product', 'picking_id', string='Check Product', auto_join=True) is_internal_use = fields.Boolean('Internal Use', help='flag which is internal use or not') account_id = fields.Many2one('account.account', string='Account') efaktur_id = fields.Many2one('vit.efaktur', string='Faktur Pajak') @@ -115,6 +122,19 @@ class StockPicking(models.Model): ], string='Status Reserve', readonly=True, tracking=True, help="The current state of the stock picking.") notee = fields.Text(string="Note") + @api.model + def _compute_dokumen_tanda_terima(self): + for picking in self: + picking.dokumen_tanda_terima = picking.partner_id.dokumen_pengiriman + + @api.model + def _compute_dokumen_pengiriman(self): + for picking in self: + picking.dokumen_pengiriman = picking.partner_id.dokumen_pengiriman_input + + dokumen_tanda_terima = fields.Char(string='Dokumen Tanda Terima yang Diberikan Pada Saat Pengiriman Barang', readonly=True, compute=_compute_dokumen_tanda_terima) + dokumen_pengiriman = fields.Char(string='Dokumen yang Dibawa Saat Pengiriman Barang', readonly=True, compute=_compute_dokumen_pengiriman) + # Envio Tracking Section envio_id = fields.Char(string="Envio ID", readonly=True) envio_code = fields.Char(string="Envio Code", readonly=True) @@ -134,6 +154,86 @@ class StockPicking(models.Model): envio_latest_longitude = fields.Float(string="Log Longitude", readonly=True) tracking_by = fields.Many2one('res.users', string='Tracking By', readonly=True, tracking=True) + # Lalamove Section + lalamove_order_id = fields.Char(string="Lalamove Order ID", copy=False) + lalamove_address = fields.Char(string="Lalamove Address") + lalamove_name = fields.Char(string="Lalamove Name") + lalamove_phone = fields.Char(string="Lalamove Phone") + lalamove_status = fields.Char(string="Lalamove Status") + lalamove_delivered_at = fields.Datetime(string="Lalamove Delivered At") + lalamove_data = fields.Text(string="Lalamove Data", readonly=True) + lalamove_image_url = fields.Char(string="Lalamove Image URL") + lalamove_image_html = fields.Html(string="Lalamove Image", compute="_compute_lalamove_image_html") + + def _compute_lalamove_image_html(self): + for record in self: + if record.lalamove_image_url: + record.lalamove_image_html = f'<img src="{record.lalamove_image_url}" width="300" height="300"/>' + else: + record.lalamove_image_html = "No image available." + + def action_fetch_lalamove_order(self): + pickings = self.env['stock.picking'].search([ + ('picking_type_code', '=', 'outgoing'), + ('state', '=', 'done'), + ('carrier_id', '=', 9) + ]) + for picking in pickings: + try: + order_id = picking.lalamove_order_id + apikey = self.env['ir.config_parameter'].sudo().get_param('lalamove.apikey') + secret = self.env['ir.config_parameter'].sudo().get_param('lalamove.secret') + market = self.env['ir.config_parameter'].sudo().get_param('lalamove.market', default='ID') + + order_data = picking.get_lalamove_order(order_id, apikey, secret, market) + picking.lalamove_data = order_data + except Exception as e: + _logger.error(f"Error fetching Lalamove order for picking {picking.id}: {str(e)}") + continue + + def get_lalamove_order(self, order_id, apikey, secret, market): + timestamp = str(int(time.time() * 1000)) + message = f"{timestamp}\r\nGET\r\n/v3/orders/{order_id}\r\n\r\n" + signature = hmac.new(secret.encode('utf-8'), message.encode('utf-8'), hashlib.sha256).hexdigest() + + headers = { + "Content-Type": "application/json", + "Authorization": f"hmac {apikey}:{timestamp}:{signature}", + "Market": market + } + + url = f"https://rest.lalamove.com/v3/orders/{order_id}" + response = requests.get(url, headers=headers) + + if response.status_code == 200: + data = response.json() + stops = data.get("data", {}).get("stops", []) + + for stop in stops: + pod = stop.get("POD", {}) + if pod.get("status") == "DELIVERED": + image_url = pod.get("image") # Sesuaikan jika key berbeda + self.lalamove_image_url = image_url + + address = stop.get("address") + name = stop.get("name") + phone = stop.get("phone") + delivered_at = pod.get("deliveredAt") + + delivered_at_dt = self._convert_to_datetime(delivered_at) + + self.lalamove_address = address + self.lalamove_name = name + self.lalamove_phone = phone + self.lalamove_status = pod.get("status") + self.lalamove_delivered_at = delivered_at_dt + return data + + raise UserError("No delivered data found in Lalamove response.") + else: + raise UserError(f"Error {response.status_code}: {response.text}") + + def _convert_to_wib(self, date_str): """ Mengonversi string waktu ISO 8601 ke format waktu Indonesia (WIB) @@ -661,13 +761,13 @@ class StockPicking(models.Model): if not self.env.user.is_logistic_approver and self.env.context.get('active_model') == 'stock.picking': if self.origin and 'Return of' in self.origin: raise UserError("Button ini hanya untuk Logistik") - + if self.picking_type_code == 'internal': self.check_qty_done_stock() if self._name != 'stock.picking': return super(StockPicking, self).button_validate() - + if not self.picking_code: self.picking_code = self.env['ir.sequence'].next_by_code('stock.picking.code') or '0' @@ -681,15 +781,10 @@ class StockPicking(models.Model): raise UserError("Harus di Approve oleh Accounting") if self.picking_type_id.id == 28 and not self.env.user.is_logistic_approver: - raise UserError("Harus di Approve oleh Logistik") + raise UserError("Harus di Approve oleh Logistik") if self.location_dest_id.id == 47 and not self.env.user.is_purchasing_manager: - raise UserError("Transfer ke gudang selisih harus di approve Rafly Hanggara") - - # if self.group_id.sale_id: - # if self.group_id.sale_id.payment_link_midtrans: - # if self.group_id.sale_id.payment_status != 'settlement' and self.group_id.sale_id.state == 'draft': - # raise UserError('Uang belum masuk (settlement), mohon konfirmasi ke sales atau finance') + raise UserError("Transfer ke gudang selisih harus di approve Rafly Hanggara") if self.is_internal_use: self.approval_status = 'approved' @@ -707,7 +802,7 @@ class StockPicking(models.Model): if not self.date_reserved: current_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') self.date_reserved = current_time - + self.validation_minus_onhand_quantity() self.responsible = self.env.user.id res = super(StockPicking, self).button_validate() @@ -715,6 +810,59 @@ class StockPicking(models.Model): self.date_done = datetime.datetime.utcnow() self.state_reserve = 'done' return res + + + def send_mail_bills(self): + if self.picking_type_code == 'incoming' and self.purchase_id: + template = self.env.ref('indoteknik_custom.mail_template_invoice_po_document') + if template and self.purchase_id: + # Render email body + email_values = template.sudo().generate_email( + res_ids=[self.purchase_id.id], + fields=['body_html'] + ) + rendered_body = email_values.get(self.purchase_id.id, {}).get('body_html', '') + + # Render report dengan XML ID + report = self.env.ref('purchase.action_report_purchase_order') # Gunakan XML ID laporan + if not report: + raise UserError("Laporan dengan XML ID 'purchase.action_report_purchase_order' tidak ditemukan.") + + # Render laporan ke PDF + pdf_content, _ = report._render_qweb_pdf([self.purchase_id.id]) + report_content = base64.b64encode(pdf_content).decode('utf-8') + + # Kirim email menggunakan template + email_sent = template.sudo().send_mail(self.purchase_id.id, force_send=True) + + if email_sent: + # Buat attachment untuk laporan + attachment = self.env['ir.attachment'].create({ + 'name': self.purchase_id.name or "Laporan Invoice.pdf", + 'type': 'binary', + 'datas': report_content, + 'res_model': 'purchase.order', + 'res_id': self.purchase_id.id, + 'mimetype': 'application/pdf', + }) + + # Siapkan data untuk mail.compose.message + compose_values = { + 'subject': "Pengiriman Email Invoice", + 'body': rendered_body, + 'attachment_ids': [(4, attachment.id)], + 'res_id': self.purchase_id.id, + 'model': 'purchase.order', + } + + # Buat mail.compose.message + compose_message = self.env['mail.compose.message'].create(compose_values) + + # Kirim pesan melalui wizard + compose_message.action_send_mail() + + return True + def action_cancel(self): if not self.env.user.is_logistic_approver and self.env.context.get('active_model') == 'stock.picking': if self.origin and 'Return of' in self.origin: @@ -858,4 +1006,50 @@ class StockPicking(models.Model): formatted_fastest_eta = fastest_eta.strftime(format_time_fastest) formatted_longest_eta = longest_eta.strftime(format_time) - return f'{formatted_fastest_eta} - {formatted_longest_eta}'
\ No newline at end of file + return f'{formatted_fastest_eta} - {formatted_longest_eta}' + +# class CheckProduct(models.Model): +# _name = 'check.product' +# _description = 'Check Product' +# _order = 'picking_id, id' + +# picking_id = fields.Many2one('stock.picking', string='Picking Reference', required=True, ondelete='cascade', index=True, copy=False) +# product_id = fields.Many2one('product.product', string='Product') + + +# @api.constrains('product_id') +# def check_product_validity(self): +# """ +# Validate if the product exists in the related stock.picking's move_ids_without_package +# and ensure that the product's quantity does not exceed the available product_uom_qty. +# """ +# for record in self: +# if not record.picking_id or not record.product_id: +# continue + +# # Filter move lines in the related picking for the selected product +# moves = record.picking_id.move_ids_without_package.filtered( +# lambda move: move.product_id.id == record.product_id.id +# ) + +# if not moves: +# raise UserError(( +# "The product '%s' is not available in the related stock picking's moves. " +# "Please check and try again." +# ) % record.product_id.display_name) + +# # Calculate the total entries for the product in check.product for the same picking +# product_entries_count = self.search_count([ +# ('picking_id', '=', record.picking_id.id), +# ('product_id', '=', record.product_id.id) +# ]) + +# # Sum the product_uom_qty for all relevant moves +# total_qty_in_moves = sum(moves.mapped('product_uom_qty')) + +# # Compare the count of entries against the available quantity +# if product_entries_count > total_qty_in_moves: +# raise UserError(( +# "The product '%s' exceeds the allowable quantity (%s) in the related stock picking's moves. " +# "You can only add it %s times." +# ) % (record.product_id.display_name, total_qty_in_moves, total_qty_in_moves)) diff --git a/indoteknik_custom/models/user_company_request.py b/indoteknik_custom/models/user_company_request.py index dd9a35c1..3de3d751 100644 --- a/indoteknik_custom/models/user_company_request.py +++ b/indoteknik_custom/models/user_company_request.py @@ -64,6 +64,7 @@ class UserCompanyRequest(models.Model): user.parent_name = self.user_input is_approve = vals.get('is_approve') is_internal_input = vals.get('internal_input') + is_company_id = vals.get('user_company_id') if self.is_approve and is_approve: raise UserError('Tidak dapat mengubah approval yang sudah diisi') @@ -71,20 +72,35 @@ class UserCompanyRequest(models.Model): if self.user_company_id.nama_wajib_pajak == self.user_company_id.name: self.user_company_id.nama_wajib_pajak = is_internal_input self.user_company_id.name = is_internal_input + user_company_id = [] + if is_company_id: + user_company_id = request.env['res.partner'].search([('id', '=', is_company_id)], limit=1) + # self.user_company_id.customer_type = self.similar_company_ids.customer_type + # self.user_company_id.npwp = self.similar_company_ids.npwp + # self.user_company_id.sppkp = self.similar_company_ids.sppkp + # self.user_company_id.nama_wajib_pajak = self.similar_company_ids.nama_wajib_pajak + # self.user_company_id.alamat_lengkap_text = self.similar_company_ids.alamat_lengkap_text + # self.user_company_id.industry_id = self.similar_company_ids.industry_id + # self.user_company_id.company_type_id = self.similar_company_ids.company_type_id + # self.user_company_id.user_id = self.similar_company_ids.user_id + # self.user_company_id.property_account_receivable_id = self.similar_company_ids.property_account_receivable_id + # self.user_company_id.property_account_payable_id = self.similar_company_ids.property_account_payable_id if not self.is_approve and is_approve: if is_approve == 'approved': - self.user_id.parent_id = vals.get('user_company_id') if vals.get('user_company_id') else self.user_company_id.id - self.user_id.customer_type = self.user_company_id.customer_type - self.user_id.npwp = self.user_company_id.npwp - self.user_id.sppkp = self.user_company_id.sppkp - self.user_id.nama_wajib_pajak = self.user_company_id.nama_wajib_pajak - self.user_id.alamat_lengkap_text = self.user_company_id.alamat_lengkap_text - self.user_id.industry_id = self.user_company_id.industry_id.id - self.user_id.company_type_id = self.user_company_id.company_type_id.id - self.user_id.user_id = self.user_company_id.user_id - self.user_id.property_account_receivable_id = self.user_company_id.property_account_receivable_id - self.user_id.property_account_payable_id = self.user_company_id.property_account_payable_id + self.user_id.parent_id = user_company_id if user_company_id else self.user_company_id + self.user_id.customer_type = user_company_id.customer_type if user_company_id else self.user_company_id.customer_type + self.user_id.npwp = user_company_id.npwp if user_company_id else self.user_company_id.npwp + self.user_id.sppkp = user_company_id.sppkp if user_company_id else self.user_company_id.sppkp + self.user_id.nama_wajib_pajak = user_company_id.nama_wajib_pajak if user_company_id else self.user_company_id.nama_wajib_pajak + self.user_id.alamat_lengkap_text = user_company_id.alamat_lengkap_text if user_company_id else self.user_company_id.alamat_lengkap_text + self.user_id.industry_id = user_company_id.industry_id.id if user_company_id else self.user_company_id.industry_id + self.user_id.company_type_id = user_company_id.company_type_id.id if user_company_id else self.user_company_id.company_type_id + self.user_id.user_id = user_company_id.user_id if user_company_id else self.user_company_id.user_id + self.user_id.property_account_receivable_id = user_company_id.property_account_receivable_id if user_company_id else self.user_company_id.property_account_receivable_id + self.user_id.property_account_payable_id = user_company_id.property_account_payable_id if user_company_id else self.user_company_id.property_account_payable_id + self.user_id.property_payment_term_id = user_company_id.property_payment_term_id if user_company_id else self.user_company_id.property_payment_term_id + self.user_id.property_supplier_payment_term_id = user_company_id.property_supplier_payment_term_id if user_company_id else self.user_company_id.property_supplier_payment_term_id self.user_company_id.active = True user.send_company_request_approve_mail() else: diff --git a/indoteknik_custom/models/user_pengajuan_tempo.py b/indoteknik_custom/models/user_pengajuan_tempo.py new file mode 100644 index 00000000..0fdcdbeb --- /dev/null +++ b/indoteknik_custom/models/user_pengajuan_tempo.py @@ -0,0 +1,134 @@ +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') + + # 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') + district_id_tempo = fields.Many2one('vit.kecamatan', string='Kecamatan') + subDistrict_id_tempo = fields.Many2one('vit.kelurahan', string='Kelurahan') + 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') + portal = fields.Boolean(string='Portal Website') + bersedia = 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_tittle = fields.Char(string='tittle Direktur') + direktur_name = fields.Char(string='Nama Lengkap Direktur') + direktur_mobile = fields.Char(string='No. Telpon Direktur') + direktur_email = fields.Char(string='Email Direktur') + purchasing_tittle = fields.Char(string='tittle Purchasing') + purchasing_name = fields.Char(string='Nama Purchasing') + purchasing_mobile = fields.Char(string='No. Telpon Purchasing') + purchasing_email = fields.Char(string='Email Purchasing') + finance_tittle = fields.Char(string='tittle Finance') + finance_name = fields.Char(string='Nama Finance') + finance_mobile = fields.Char(string='No. Telpon Finance') + finance_email = fields.Char(string='Email Finance') + + # Pengiriman + pic_tittle = fields.Char(string='Tittle PIC Penerimaan Barang') + 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') + district_id_pengiriman = fields.Many2one('vit.kecamatan', string='Kecamatan') + subDistrict_id_pengiriman = fields.Many2one('vit.kelurahan', string='Kelurahan') + zip_pengiriman = fields.Char(string="Zip") + invoice_pic_tittle = fields.Char(string='Tittle PIC Penerimaan Invoice') + 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') + district_id_invoice = fields.Many2one('vit.kecamatan', string='Kecamatan') + subDistrict_id_invoice = fields.Many2one('vit.kelurahan', string='Kelurahan') + zip_invoice = fields.Char(string="Zip") + tukar_invoice = fields.Char(string='Jadwal Penukaran Invoice') + jadwal_bayar = fields.Char(string='Jadwal Pembayaran') + dokumen_pengiriman = fields.Char(string='Dokumen Tanda Terima yang Diberikan Pada Saat Pengiriman Barang') + dokumen_kirim_input = fields.Char(string='Dokumen lain yang diterima saat pengiriman barang') + dokumen_pengiriman_input = fields.Char(string='Dokumen yang Dibawa 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", tracking=True, track_visibility="onchange") + dokumen_npwp = fields.Many2many('ir.attachment', 'pengajuan_dokumen_npwp_rel', string="NPWP Perusahaan", tracking=True) + dokumen_sppkp = fields.Many2many('ir.attachment', 'pengajuan_dokumen_sppkp_rel', string="SPPKP Perusahaan", tracking=True) + dokumen_siup = fields.Many2many('ir.attachment', 'pengajuan_dokumen_siup_rel', string="SIUP Perusahaan", tracking=True) + dokumen_tdp = fields.Many2many('ir.attachment', 'pengajuan_dokumen_tdp_rel', string="TDP Perusahaan", tracking=True) + dokumen_skdp = fields.Many2many('ir.attachment', 'pengajuan_dokumen_skdp_rel', string="SKDP Perusahaan", tracking=True) + dokumen_skt = fields.Many2many('ir.attachment', 'pengajuan_dokumen_skt_rel', string="SKT Perusahaan", tracking=True) + dokumen_akta_perubahan = fields.Many2many('ir.attachment', 'pengajuan_dokumen_akta_perubahan_rel', + string="Akta Perubahan", tracking=True) + dokumen_ktp_dirut = fields.Many2many('ir.attachment', 'pengajuan_dokumen_ktp_dirut_rel', + string="KTP Dirut/Direktur", tracking=True) + dokumen_akta_pendirian = fields.Many2many('ir.attachment', 'pengajuan_dokumen_angkta_pendirian_rel', + string="Akta Pendirian", tracking=True) + dokumen_laporan_keuangan = fields.Many2many('ir.attachment', 'pengajuan_dokumen_laporan_keuangan_rel', + string="Laporan Keuangan", tracking=True) + dokumen_foto_kantor = fields.Many2many('ir.attachment', 'pengajuan_dokumen_foto_kantor_rel', + string=" Foto Kantor (Tampak Depan)", tracking=True) + dokumen_tempat_bekerja = fields.Many2many('ir.attachment', 'pengajuan_dokumen_tempat_bekerja_rel', + string="Tempat Bekerja", tracking=True) + + @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 diff --git a/indoteknik_custom/models/user_pengajuan_tempo_line.py b/indoteknik_custom/models/user_pengajuan_tempo_line.py new file mode 100644 index 00000000..db519ed6 --- /dev/null +++ b/indoteknik_custom/models/user_pengajuan_tempo_line.py @@ -0,0 +1,12 @@ +from odoo import models, fields + + +class PengajuanTempoLine(models.Model): + _name = 'user.pengajuan.tempo.line' + + # Fields untuk tabel supplier + name_supplier = fields.Char(string="Nama Supplier") + pic_name = fields.Char(string="PIC") + phone = fields.Char(string="Telepon") + tempo_duration = fields.Char(string="Durasi Tempo") + credit_limit = fields.Char(string="Credit Limit")
\ No newline at end of file diff --git a/indoteknik_custom/models/user_pengajuan_tempo_request.py b/indoteknik_custom/models/user_pengajuan_tempo_request.py new file mode 100644 index 00000000..f5261cd4 --- /dev/null +++ b/indoteknik_custom/models/user_pengajuan_tempo_request.py @@ -0,0 +1,630 @@ +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) + + 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, domain=[('id', 'in', [24, 25, 29, 32])]) + 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') + reason_reject = fields.Char(string='Limit Tempo') + + # 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='pengajuan_tempo_id.tempo_duration', store=True, tracking=True, readonly=False, domain=[('id', 'in', [24, 25, 29, 32])]) + 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_name = fields.Char(string='Nama PIC Penerimaan Barang', related='pengajuan_tempo_id.pic_name', store=True, readonly=False) + street_pengiriman = fields.Char(string="Alamat Perusahaan", 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 = fields.Char(string='Nama PIC Penerimaan Invoice', related='pengajuan_tempo_id.invoice_pic', store=True, readonly=False) + street_invoice = fields.Char(string="Alamat Perusahaan", 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) + + #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_name', 'street_pengiriman', 'state_id_pengiriman', 'city_id_pengiriman', + 'zip_pengiriman', 'district_id_pengiriman', 'subDistrict_id_pengiriman' + 'invoice_pic_tittle', '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') + 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_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 = 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 + + @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_nib = self.dokumen_nib + 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, vals): + for tempo in self: + if tempo.env.user.id not in (7, 377, 12182): + 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, 377, 12182): + 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 (377, 12182): + # 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, 12182): + # 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 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, + "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, + "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: + 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 + + # 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.pengajuan_tempo_id.tempo_duration.id + self.user_company_id.active_limit = True + self.user_company_id.warning_stage = float(limit_tempo) - (float(limit_tempo)/2) + self.user_company_id.blocking_stage = limit_tempo + + # 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 format_currency(self, number): + number = int(number) + return "{:,}".format(number).replace(',', '.')
\ No newline at end of file diff --git a/indoteknik_custom/models/wati.py b/indoteknik_custom/models/wati.py index f3632334..a0619f83 100644 --- a/indoteknik_custom/models/wati.py +++ b/indoteknik_custom/models/wati.py @@ -32,28 +32,43 @@ class WatiNotification(models.Model): ]).unlink() _logger.info('Success Cleanup WATI Notification') - def _parse_notification(self, limit = 0): + def _parse_notification(self, limit=0): domain = [('is_parsed', '=', False)] notifications = self.search(domain, order='id', limit=limit) notification_not_parsed_count = self.search_count(domain) i = 0 for notification in notifications: i += 1 - _logger.info('[Parse Notification][%s] Process: %s/%s | Not Parsed: %s' % (notification.id, i, str(limit), str(notification_not_parsed_count))) + _logger.info('[Parse Notification][%s] Process: %s/%s | Not Parsed: %s' % + (notification.id, i, str(limit), str(notification_not_parsed_count))) + notification_json = json.loads(notification.json_raw) sender_name = 'Indoteknik' if 'senderName' in notification_json: sender_name = notification_json['senderName'] - ticket_id = notification_json['ticketId'] - date_wati = float(notification_json['timestamp']) - date_wati = datetime.fromtimestamp(date_wati) + ticket_id = notification_json.get('ticketId') + timestamp = notification_json.get('timestamp') + + if not timestamp: + _logger.warning('[Parse Notification][%s] Missing timestamp in notification JSON: %s' % + (notification.id, notification.json_raw)) + continue # Skip this notification + + try: + date_wati = datetime.fromtimestamp(float(timestamp)) + except ValueError as e: + _logger.error('[Parse Notification][%s] Invalid timestamp format: %s. Error: %s' % + (notification.id, timestamp, str(e))) + continue + wati_history = self.env['wati.history'].search([('ticket_id', '=', ticket_id)], limit=1) if wati_history: self._create_wati_history_line(wati_history, ticket_id, sender_name, notification_json, date_wati) else: new_header = self._create_wati_history_header(ticket_id, sender_name, notification_json, date_wati) self._create_wati_history_line(new_header, ticket_id, sender_name, notification_json, date_wati) + notification.is_parsed = True return @@ -217,26 +232,42 @@ class WatiHistory(models.Model): limit = 50 wati_histories = self.env['wati.history'].search(domain, limit=limit) count = 0 + for wati_history in wati_histories: count += 1 - _logger.info('[Parse Notification] Process: %s/%s' % (str(count), str(limit))) + _logger.info('[Parse Notification] Processing: %s/%s', count, limit) wati_api = self.env['wati.api'] - # Perbaikan pada params 'attribute' untuk menghindari masalah "type object is not subscriptable" + # Perbaikan pada parameter JSON params = { 'pageSize': 1, 'pageNumber': 1, - 'attribute': json.dumps([{'name': "phone", 'operator': "contain", 'value': wati_history.wa_id}]), + 'attribute': json.dumps([ + {'name': "phone", 'operator': "contain", 'value': wati_history.wa_id} + ]), } - wati_contacts = wati_api.http_get('/api/v1/getContacts', params) + try: + wati_contacts = wati_api.http_get('/api/v1/getContacts', params) + except Exception as e: + _logger.error('Error while calling WATI API: %s', str(e)) + continue + # Validasi respons dari API + if not isinstance(wati_contacts, dict): + _logger.error('Invalid response format from WATI API: %s', wati_contacts) + continue + if wati_contacts.get('result') != 'success': - return + _logger.warning('WATI API request failed with result: %s', wati_contacts.get('result')) + continue contact_list = wati_contacts.get('contact_list', []) - + if not contact_list: + _logger.info('No contacts found for WA ID: %s', wati_history.wa_id) + continue + perusahaan = email = '' for data in contact_list: custom_params = data.get('customParams', []) @@ -247,12 +278,14 @@ class WatiHistory(models.Model): perusahaan = value elif name == 'email': email = value - # End inner loop # Update wati_history fields - wati_history.perusahaan = perusahaan - wati_history.email = email - wati_history.is_get_attribute = True + wati_history.write({ + 'perusahaan': perusahaan, + 'email': email, + 'is_get_attribute': True, + }) + _logger.info('Wati history updated: %s', wati_history.id) # @api.onchange('last_reply_date') # def _compute_expired_date(self): |
