summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/advance_payment_request.py
diff options
context:
space:
mode:
authorMqdd <ahmadmiqdad27@gmail.com>2026-02-17 16:40:42 +0700
committerMqdd <ahmadmiqdad27@gmail.com>2026-02-17 16:40:42 +0700
commit7c893b6cfeae88c82231f682517ae143b4cf580b (patch)
treeb249c3d3a462d4817a39ff00954765f3a4f7788f /indoteknik_custom/models/advance_payment_request.py
parent8bb3696e35dc122ea153566834a48ec0659e0101 (diff)
parenta461efcda1637c267b3c4195eb0f7d649f10f145 (diff)
Merge branch 'odoo-backup' of https://bitbucket.org/altafixco/indoteknik-addons into cr_renca_find
Diffstat (limited to 'indoteknik_custom/models/advance_payment_request.py')
-rw-r--r--indoteknik_custom/models/advance_payment_request.py62
1 files changed, 58 insertions, 4 deletions
diff --git a/indoteknik_custom/models/advance_payment_request.py b/indoteknik_custom/models/advance_payment_request.py
index f973a9da..8cadb1b6 100644
--- a/indoteknik_custom/models/advance_payment_request.py
+++ b/indoteknik_custom/models/advance_payment_request.py
@@ -55,12 +55,14 @@ class AdvancePaymentRequest(models.Model):
('pengajuan2', 'Menunggu Approval AP'),
('pengajuan3', 'Menunggu Approval Pimpinan'),
('approved', 'Approved'),
+ ('cancel','Cancel')
], string='Status', default='draft', tracking=3, index=True, track_visibility='onchange')
status_pay_down_payment = fields.Selection([
('pending', 'Pending'),
('payment', 'Payment'),
+ ('cancel','Cancel')
], string='Status Pembayaran', default='pending', tracking=3)
name_approval_departement = fields.Char(string='Approval Departement')
@@ -639,10 +641,16 @@ class AdvancePaymentRequest(models.Model):
today = date.today()
for rec in self:
- current_days = rec.days_remaining or 0
- current_due_date = rec.estimated_return_date or False
- if rec.type_request == 'pum':
- is_settlement_approved = any(s.status == 'approved' for s in rec.settlement_ids)
+ # current_days = rec.days_remaining or 0
+ # current_due_date = rec.estimated_return_date or False
+ current_days = 0
+ current_due_date = False
+
+ is_settlement_approved = any(s.status == 'approved' for s in rec.settlement_ids)
+ is_pum_canceled = (rec.status == 'cancel')
+
+ if rec.type_request == 'pum' and not is_pum_canceled and not is_settlement_approved:
+
if not is_settlement_approved:
due_date = False
@@ -816,6 +824,52 @@ class AdvancePaymentRequest(models.Model):
rec._compute_grand_total_reimburse()
rec.nominal = rec.grand_total_reimburse
return rec
+
+ def action_open_cancel_wizard(self):
+ """Membuka Wizard Pop-up untuk Cancel PUM/Reimburse"""
+ self.ensure_one()
+
+ if self.move_id:
+ raise UserError(_("Pengajuan tidak dapat dibatalkan karena Journal sudah terbentuk."))
+
+ if self.settlement_ids and any(s.status != 'draft' for s in self.settlement_ids):
+ raise UserError(_("Pengajuan tidak dapat dibatalkan karena sudah ada proses realisasi."))
+
+ return {
+ 'name': _('Alasan Pembatalan'),
+ 'type': 'ir.actions.act_window',
+ 'res_model': 'advance.payment.cancel.wizard',
+ 'view_mode': 'form',
+ 'target': 'new',
+ 'context': {
+ 'default_request_id': self.id,
+ }
+ }
+
+class AdvancePaymentCancelWizard(models.TransientModel):
+ _name = 'advance.payment.cancel.wizard'
+ _description = 'Wizard untuk Membatalkan PUM/Reimburse'
+
+ request_id = fields.Many2one('advance.payment.request', string='Dokumen', readonly=True)
+ reason = fields.Text(string='Alasan Pembatalan', required=True)
+
+ def action_confirm_cancel(self):
+ self.ensure_one()
+ request = self.request_id
+ if request.move_id:
+ raise UserError("Tidak bisa melakukan cancel karena Jurnal (Move ID) sudah terbentuk.")
+
+ request.write({'status': 'cancel'})
+ request.write({'status_pay_down_payment': 'cancel'})
+
+ request.message_post(
+ body=f"Pengajuan telah <b>DIBATALKAN</b> oleh {self.env.user.name}.<br/>"
+ f"<b>Alasan:</b> {self.reason}",
+ message_type="comment",
+ subtype_xmlid="mail.mt_note",
+ )
+
+ return {'type': 'ir.actions.act_window_close'}
class AdvancePaymentUsageLine(models.Model):