From d02c3d5d0522e6ec5a43d1380c078f0dd5fd1275 Mon Sep 17 00:00:00 2001 From: "Indoteknik ." Date: Wed, 23 Jul 2025 11:06:12 +0700 Subject: (andri) add reject & set to draft Pengajuan PUM --- indoteknik_custom/models/down_payment.py | 55 +++++++++++++++++++++++--- indoteknik_custom/security/ir.model.access.csv | 3 +- indoteknik_custom/views/down_payment.xml | 39 ++++++++++++++---- 3 files changed, 84 insertions(+), 13 deletions(-) diff --git a/indoteknik_custom/models/down_payment.py b/indoteknik_custom/models/down_payment.py index afb8ca73..8f449566 100644 --- a/indoteknik_custom/models/down_payment.py +++ b/indoteknik_custom/models/down_payment.py @@ -95,6 +95,8 @@ class DownPayment(models.Model): move_id = fields.Many2one('account.move', string='Journal Entries', domain=[('move_type', '=', 'entry')]) is_cab_visible = fields.Boolean(string='Is Journal Uang Muka Visible', compute='_compute_is_cab_visible') + reason_reject = fields.Text(string='Alasan Penolakan') + @api.depends('move_id.state') def _compute_is_cab_visible(self): for rec in self: @@ -268,13 +270,42 @@ class DownPayment(models.Model): def action_reject(self): - # Logic untuk konfirmasi pembayaran - return + return { + 'type': 'ir.actions.act_window', + 'name': 'Alasan Penolakan', + 'res_model': 'reject.reason.downpayment', + 'view_mode': 'form', + 'target': 'new', + 'context': {'default_request_id': self.id}, + } def action_draft(self): for record in self: - record.status = record.last_status if record.last_status else 'draft' - return + # Pastikan hanya yang statusnya 'reject' yang bisa di-reset + if record.status != 'reject': + raise UserError("Hanya data dengan status 'Reject' yang bisa dikembalikan ke Draft atau status sebelumnya.") + + # Jika ada last_status, gunakan itu; jika tidak, fallback ke 'draft' + new_status = record.last_status or 'draft' + + # Reset field-field approval & alasan reject + record.write({ + 'status': new_status, + 'reason_reject': False, + 'last_status': False, + 'name_approval_departement': False, + 'name_approval_ap': False, + 'name_approval_pimpinan': False, + 'date_approved_department': False, + 'date_approved_ap': False, + 'date_approved_pimpinan': False, + 'position_department': False, + 'position_ap': False, + 'position_pimpinan': False, + }) + + record.message_post(body=f"Status dikembalikan ke {new_status.capitalize()} oleh {self.env.user.name}.") + def action_ap_only(self): # if self.env.user.id != 23: @@ -657,7 +688,21 @@ class RealizationDownPayment(models.Model): # rec.message_post(body=f"Approval oleh {self.env.user.name} pada tahap {rec.status}.") - +class RejectReasonDownPayment(models.TransientModel): + _name = 'reject.reason.downpayment' + _description = 'Wizard for Reject Reason Down Payment' + + request_id = fields.Many2one('down.payment', string='Pengajuan PUM') + reason_reject = fields.Text(string='Alasan Penolakan', required=True) + + def confirm_reject(self): + if self.request_id: + self.request_id.write({ + 'status': 'reject', + 'last_status': self.request_id.status, + 'reason_reject': self.reason_reject, + }) + return {'type': 'ir.actions.act_window_close'} class DownPaymentApOnly(models.TransientModel): _name = 'down.payment.ap.only' diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv index e463caa8..2fd497b9 100755 --- a/indoteknik_custom/security/ir.model.access.csv +++ b/indoteknik_custom/security/ir.model.access.csv @@ -187,4 +187,5 @@ access_down_payment,access.down.payment,model_down_payment,,1,1,1,1 access_realization_down_payment,access.realization.down.payment,model_realization_down_payment,,1,1,1,1 access_realization_down_payment_line,access.realization.down.payment.line,model_realization_down_payment_line,,1,1,1,1 access_realization_down_payment_use_line,access.realization.down.payment.use.line,model_realization_down_payment_use_line,,1,1,1,1 -access_down_payment_ap_only,access.down.payment.ap.only,model_down_payment_ap_only,,1,1,1,1 \ No newline at end of file +access_down_payment_ap_only,access.down.payment.ap.only,model_down_payment_ap_only,,1,1,1,1 +access_reject_reason_downpayment,access.reject.reason.downpayment,model_reject_reason_downpayment,,1,1,1,1 \ No newline at end of file diff --git a/indoteknik_custom/views/down_payment.xml b/indoteknik_custom/views/down_payment.xml index 47e3c2be..467697a4 100644 --- a/indoteknik_custom/views/down_payment.xml +++ b/indoteknik_custom/views/down_payment.xml @@ -10,7 +10,7 @@ type="object" string="Realisasi" class="btn-primary" - attrs="{}"/> + attrs="{'invisible': [('status', '=', 'reject')]}"/>