diff options
| -rw-r--r-- | indoteknik_custom/models/down_payment.py | 123 | ||||
| -rw-r--r-- | indoteknik_custom/views/down_payment_realization.xml | 34 |
2 files changed, 148 insertions, 9 deletions
diff --git a/indoteknik_custom/models/down_payment.py b/indoteknik_custom/models/down_payment.py index 573028b9..e43d2a0c 100644 --- a/indoteknik_custom/models/down_payment.py +++ b/indoteknik_custom/models/down_payment.py @@ -347,6 +347,24 @@ class RealizationDownPayment(models.Model): note_approval = fields.Text(string='Note Persetujuan', tracking=3) + status = fields.Selection([ + ('draft', 'Draft'), + ('pengajuan1', 'Menunggu Approval Departement'), + ('pengajuan2', 'Menunggu Pengecekan AP'), + ('pengajuan3', 'Menunggu Approval Pimpinan'), + ('approved', 'Approved'), + ('reject', 'Rejected') + ], string='Status', default='draft', tracking=3, index=True, track_visibility='onchange') + + last_status = fields.Selection([ + ('draft', 'Draft'), + ('pengajuan1', 'Menunggu Approval Departement'), + ('pengajuan2', 'Menunggu Pengecekan AP'), + ('pengajuan3', 'Menunggu Approval Pimpinan'), + ('approved', 'Approved'), + ('reject', 'Rejected') + ], string='Status') + done_status = fields.Selection([ ('remaining', 'Remaining'), ('done_not_realized', 'Done Not Realized'), @@ -368,6 +386,30 @@ class RealizationDownPayment(models.Model): ('image', 'Image'), ], string="Attachment Type", default='pdf') + 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') + + @api.depends('move_id.state') + def _compute_is_cab_visible(self): + for rec in self: + move = rec.move_id + rec.is_cab_visible = bool(move and move.state == 'posted') + + def action_view_journal_uangmuka(self): + self.ensure_one() + if not self.move_id: + raise UserError("Journal Uang Muka belum tersedia.") + + return { + 'name': 'Journal Entry', + 'view_mode': 'form', + 'res_model': 'account.move', + 'type': 'ir.actions.act_window', + 'res_id': self.move_id.id, + 'target': 'current', + } + + @api.onchange('attachment_type') def _onchange_attachment_type(self): self.attachment_file_image = False @@ -407,8 +449,85 @@ class RealizationDownPayment(models.Model): # Opsional: Tambah log di chatter self.message_post(body=f"Status realisasi diperbarui menjadi <b>{dict(self._fields['done_status'].selection).get(self.done_status)}</b> oleh {self.env.user.name}.") - def action_misc(self): - return + def action_cab(self): + self.ensure_one() + + if not self.pum_id or not self.pum_id.move_id: + raise UserError("PUM terkait atau CAB belum tersedia.") + + partner_id = self.pum_id.user_id.partner_id.id + cab_move = self.pum_id.move_id + + # Account Bank Intransit dari CAB: + bank_intransit_line = cab_move.line_ids.filtered(lambda l: l.account_id.id in [573, 389, 392]) + if not bank_intransit_line: + raise UserError("Account Bank Intransit dengan tidak ditemukan di CAB terkait.") + account_sisa_pum = bank_intransit_line[0].account_id.id + + # Account Uang Muka Operasional + account_uang_muka = 403 + + # Tanggal pakai create_date atau hari ini + account_date = self.create_date.date() if self.create_date else fields.Date.today() + + ref_label = f"Realisasi {self.pum_id.number} Biaya {self.pum_id.detail_note} ({cab_move.name})" + + label_sisa_pum = f"Sisa PUM {self.pum_id.detail_note} {self.pum_id.number} ({cab_move.name})" + + lines = [] + + # Sisa PUM (Debit) + if self.remaining_value > 0: + lines.append((0, 0, { + 'account_id': account_sisa_pum, + 'partner_id': partner_id, + 'name': label_sisa_pum, + 'debit': self.remaining_value, + 'credit': 0, + })) + + # Biaya Penggunaan (Debit) + total_biaya = 0 + for line in self.penggunaan_line_ids: + lines.append((0, 0, { + 'account_id': line.account_id.id, + 'partner_id': partner_id, + 'name': f"{line.description} ({line.date})", + 'debit': line.nominal, + 'credit': 0, + })) + total_biaya += line.nominal + + # Uang Muka Operasional (Credit) + total_credit = self.remaining_value + total_biaya + if total_credit > 0: + lines.append((0, 0, { + 'account_id': account_uang_muka, + 'partner_id': partner_id, + 'name': ref_label, + 'debit': 0, + 'credit': total_credit, + })) + + move = self.env['account.move'].create({ + 'ref': ref_label, + 'date': account_date, + 'journal_id': 11, # MISC + 'line_ids': lines, + }) + + # self.message_post(body=f"Jurnal CAB telah dibuat dengan nomor: <b>{move.name}</b>.") + + self.move_id = move.id + + return { + 'name': _('Journal Entry'), + 'view_mode': 'form', + 'res_model': 'account.move', + 'type': 'ir.actions.act_window', + 'res_id': move.id, + 'target': 'current', + } class DownPaymentApOnly(models.TransientModel): _name = 'down.payment.ap.only' diff --git a/indoteknik_custom/views/down_payment_realization.xml b/indoteknik_custom/views/down_payment_realization.xml index 1138b59e..64b3af91 100644 --- a/indoteknik_custom/views/down_payment_realization.xml +++ b/indoteknik_custom/views/down_payment_realization.xml @@ -9,18 +9,34 @@ type="object" string="Validasi" class="btn-primary"/> - <button name="action_misc" + <button name="action_cab" type="object" string="AP Only"/> - <field name="done_status" widget="statusbar" - statusbar_visible="remaining,done_not_realized,done_realized" - statusbar_colors='{"done_realized":"green"}' + <field name="status" widget="statusbar" + statusbar_visible="draft,pengajuan1,pengajuan2,pengajuan3,approved" + statusbar_colors='{"reject":"red"}' readonly="1"/> </header> - <sheet> - <h1><field name="name" class="oe_title"/></h1> - + <div class="oe_button_box" name="button_box"> + <field name="is_cab_visible" invisible="1"/> + <button type="object" + name="action_view_journal_uangmuka" + class="oe_stat_button" + icon="fa-book" + attrs="{'invisible': [('is_cab_visible', '=', False)]}" + style="width: 200px;"> + <field name="move_id" widget="statinfo" string="Journal MISC"/> + <span class="o_stat_text"> + <t t-esc="record.move_misc_id.name"/> + </span> + </button> + </div> + <div class="oe_title"> + <h1> + <field name="name" readonly="1"/> + </h1> + </div> <group col="2"> <group> <field name="pum_id" readonly="1"/> @@ -29,6 +45,10 @@ <field name="related" required="1"/> </group> <group> + <field name="done_status" + decoration-success="done_status == 'done_realized'" + decoration-danger="done_status == 'remaining'" + widget="badge" readonly="1"/> <field name="note_approval" required="1"/> </group> </group> |
