summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models
diff options
context:
space:
mode:
authorIndoteknik . <it@fixcomart.co.id>2025-07-21 14:26:24 +0700
committerIndoteknik . <it@fixcomart.co.id>2025-07-21 14:26:24 +0700
commit6b68c39ebe116ccb16a5d77ab74b8b4a59958f20 (patch)
tree6a9de7aad1ddde10fa42a268e8b16347e08c1988 /indoteknik_custom/models
parent1b17c9e9c9c6f9b2e177a0c9e7a7e5a2c5535be4 (diff)
(andri) add wizard CAB di PUM dan hanya AP yang bisa akses
Diffstat (limited to 'indoteknik_custom/models')
-rw-r--r--indoteknik_custom/models/down_payment.py97
1 files changed, 97 insertions, 0 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 <b>{dict(self._fields['done_status'].selection).get(self.done_status)}</b> 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',
+ }
+
+
+