diff options
| author | Indoteknik . <it@fixcomart.co.id> | 2025-07-21 14:26:24 +0700 |
|---|---|---|
| committer | Indoteknik . <it@fixcomart.co.id> | 2025-07-21 14:26:24 +0700 |
| commit | 6b68c39ebe116ccb16a5d77ab74b8b4a59958f20 (patch) | |
| tree | 6a9de7aad1ddde10fa42a268e8b16347e08c1988 | |
| parent | 1b17c9e9c9c6f9b2e177a0c9e7a7e5a2c5535be4 (diff) | |
(andri) add wizard CAB di PUM dan hanya AP yang bisa akses
| -rw-r--r-- | indoteknik_custom/models/down_payment.py | 97 | ||||
| -rwxr-xr-x | indoteknik_custom/security/ir.model.access.csv | 3 | ||||
| -rw-r--r-- | 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 <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', + } + + + 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="{}"/> + <button name="action_ap_only" + type="object" + string="AP Only" + attrs="{}"/> <field name="status" widget="statusbar" statusbar_visible="draft,pengajuan1,pengajuan2,pengajuan3,approved" statusbar_colors='{"reject":"red"}' readonly="1"/> </header> <sheet> - <h1> - <field name="number" readonly="1" 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 Uang Muka"/> + <span class="o_stat_text"> + <t t-esc="record.move_id.name"/> + </span> + </button> + </div> + <div class="oe_title"> + <h1> + <field name="number" readonly="1"/> + </h1> + </div> <group col="2"> <group string=""> <field name="applicant_name" colspan="2" attrs="{'readonly': [('status', '=', 'approved')]}"/> @@ -43,8 +63,10 @@ <field name="bank_name" colspan="2" attrs="{'readonly': [('status', '=', 'approved')]}"/> <field name="account_name" colspan="2" attrs="{'readonly': [('status', '=', 'approved')]}"/> <field name="bank_account" colspan="2" attrs="{'readonly': [('status', '=', 'approved')]}"/> + <!-- <field name="move_id" readonly="1"/> --> <hr/> <field name="user_id" readonly="1"/> + <field name="partner_id" readonly="1"/> <field name="departement_type"/> <field name="status_pay_down_payment" readonly="1" @@ -124,4 +146,31 @@ sequence="101" action="action_down_payment" /> + + <!-- view form untuk popup CAB AP Only --> + <record id="view_down_payment_ap_only_form" model="ir.ui.view"> + <field name="name">down.payment.ap.only.form</field> + <field name="model">down.payment.ap.only</field> + <field name="arch" type="xml"> + <form string="Create CAB AP Only"> + <group> + <field name="nominal"/> + <field name="account_id"/> + </group> + <footer> + <button name="action_create_cab" type="object" string="Create CAB" class="btn-primary"/> + <button string="Cancel" class="btn-secondary" special="cancel"/> + </footer> + </form> + </field> + </record> + + <record id="action_down_payment_cab_ap_only" model="ir.actions.act_window"> + <field name="name">Create CAB AP Only</field> + <field name="res_model">down.payment.ap.only</field> + <field name="view_mode">form</field> + <field name="view_id" ref="view_down_payment_ap_only_form"/> + <field name="target">new</field> + </record> + </odoo>
\ No newline at end of file |
