From 6b68c39ebe116ccb16a5d77ab74b8b4a59958f20 Mon Sep 17 00:00:00 2001 From: "Indoteknik ." Date: Mon, 21 Jul 2025 14:26:24 +0700 Subject: (andri) add wizard CAB di PUM dan hanya AP yang bisa akses --- indoteknik_custom/models/down_payment.py | 97 ++++++++++++++++++++++++++ indoteknik_custom/security/ir.model.access.csv | 3 +- indoteknik_custom/views/down_payment.xml | 55 ++++++++++++++- 3 files changed, 151 insertions(+), 4 deletions(-) diff --git a/indoteknik_custom/models/down_payment.py b/indoteknik_custom/models/down_payment.py index 0f39c98a..881829c8 100644 --- a/indoteknik_custom/models/down_payment.py +++ b/indoteknik_custom/models/down_payment.py @@ -16,6 +16,7 @@ class DownPayment(models.Model): _inherit = ['mail.thread'] user_id = fields.Many2one('res.users', string='Diajukan Oleh', default=lambda self: self.env.user, tracking=3) + partner_id = fields.Many2one('res.partner', string='Partner', related='user_id.partner_id', readonly=True) number = fields.Char(string='No. Dokumen', default='New Draft', tracking=3) @@ -79,6 +80,29 @@ class DownPayment(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 @@ -171,6 +195,22 @@ class DownPayment(models.Model): record.status = record.last_status if record.last_status else 'draft' return + def action_ap_only(self): + # if self.env.user.id != 23: + # raise UserError('Hanya AP yang dapat menggunakan ini.') + return { + 'name': 'Create CAB AP Only', + 'type': 'ir.actions.act_window', + 'res_model': 'down.payment.ap.only', + 'view_mode': 'form', + 'target': 'new', + 'context': { + 'default_nominal': self.nominal, + 'default_down_payment_id': self.id, + } + } + + @api.depends('create_date') def _compute_days_remaining(self): today = date.today() @@ -325,6 +365,63 @@ class RealizationDownPayment(models.Model): self.message_post(body=f"Status realisasi diperbarui menjadi {dict(self._fields['done_status'].selection).get(self.done_status)} oleh {self.env.user.name}.") +class DownPaymentApOnly(models.TransientModel): + _name = 'down.payment.ap.only' + _description = 'Create CAB from Down Payment for AP Only' + + down_payment_id = fields.Many2one('down.payment', string='Down Payment', required=True) + account_id = fields.Many2one( + 'account.account', string='Bank Intransit', required=True, + domain="[('name', 'ilike', 'intransit')]" + ) + nominal = fields.Float(string='Nominal', related='down_payment_id.nominal', readonly=True) + + def action_create_cab(self): + self.ensure_one() + + # if self.env.user.id != 23: + # raise UserError('Hanya AP yang dapat menggunakan ini.') + + dp = self.down_payment_id + partner_id = dp.user_id.partner_id.id + + ref_label = f'{dp.number} - Biaya {dp.detail_note or "-"}' + + move = self.env['account.move'].create({ + 'ref': ref_label, + 'date': fields.Date.context_today(self), + 'journal_id': 11, # Cash & Bank + 'line_ids': [ + (0, 0, { + 'account_id': 403, # Uang Muka Operasional + 'partner_id': partner_id, + 'name': ref_label, + 'debit': dp.nominal, + 'credit': 0, + }), + (0, 0, { + 'account_id': self.account_id.id, # Bank Intransit yang dipilih + 'partner_id': partner_id, + 'name': ref_label, + 'debit': 0, + 'credit': dp.nominal, + }) + ] + }) + + dp.move_id = move.id # jika ada field untuk menampung move_id + + return { + 'name': _('Journal Entry'), + 'view_mode': 'form', + 'res_model': 'account.move', + 'type': 'ir.actions.act_window', + 'res_id': move.id, + 'target': 'current', + } + + + diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv index 349ed40b..e463caa8 100755 --- a/indoteknik_custom/security/ir.model.access.csv +++ b/indoteknik_custom/security/ir.model.access.csv @@ -186,4 +186,5 @@ access_approval_payment_term,access.approval.payment.term,model_approval_payment 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 \ No newline at end of file +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 diff --git a/indoteknik_custom/views/down_payment.xml b/indoteknik_custom/views/down_payment.xml index 3c5f4f1f..47e3c2be 100644 --- a/indoteknik_custom/views/down_payment.xml +++ b/indoteknik_custom/views/down_payment.xml @@ -27,15 +27,35 @@ type="object" string="Checking/Approval" attrs="{}"/> + + +
+

+ +

+
@@ -43,8 +63,10 @@ +
+ + + + + down.payment.ap.only.form + down.payment.ap.only + +
+ + + + +
+
+
+
+
+ + + Create CAB AP Only + down.payment.ap.only + form + + new + + \ No newline at end of file -- cgit v1.2.3