From 38313de6949c4f39ebe7cb431d5beb15baa38d06 Mon Sep 17 00:00:00 2001 From: Mqdd Date: Wed, 11 Mar 2026 10:42:53 +0700 Subject: major fix --- indoteknik_custom/models/upah_harian_office.py | 73 +++++++++++++++++----- indoteknik_custom/views/ir_sequence.xml | 12 +++- .../views/upah_harian_office_views.xml | 8 ++- 3 files changed, 72 insertions(+), 21 deletions(-) diff --git a/indoteknik_custom/models/upah_harian_office.py b/indoteknik_custom/models/upah_harian_office.py index e2f87242..a77281f6 100644 --- a/indoteknik_custom/models/upah_harian_office.py +++ b/indoteknik_custom/models/upah_harian_office.py @@ -12,7 +12,8 @@ class UpahHarian(models.Model): 'res.users', string='Pemohon', required=True, - domain=[('active', '=', True), ('share', '=', False)] + domain=[('active', '=', True), ('share', '=', False)], + default=lambda self: self.env.user ) tanggal = fields.Date( @@ -26,10 +27,12 @@ class UpahHarian(models.Model): state = fields.Selection([ ('draft', 'Draft'), - ('approved', 'Approved'), + ('pic', 'Approval PIC'), + ('approved', 'Approval Kepala Departemen'), + ('waiting_payment', 'Waiting for Payment'), ('paid', 'Paid'), ('cancel', 'Canceled') - ], default='draft') + ], default='draft', tracking=True) cancel_reason = fields.Text('Alasan Cancel') @@ -70,12 +73,14 @@ class UpahHarian(models.Model): attachment_file_image = fields.Binary( string='Attachment Image', - attachment_filename='attachment_filename_image' + attachment_filename='attachment_filename_image', + compute = 'auto_paid_attachment' ) attachment_file_pdf = fields.Binary( string='Attachment PDF', - attachment_filename='attachment_filename_pdf' + attachment_filename='attachment_filename_pdf', + compute = 'auto_paid_attachment' ) attachment_filename_image = fields.Char() @@ -131,7 +136,12 @@ class UpahHarian(models.Model): @api.model def create(self, vals): - vals['name'] = self.env['ir.sequence'].next_by_code('upah.harian.office') + dept = vals.get('departement_type') + + if dept == 'logistic': + vals['name'] = self.env['ir.sequence'].next_by_code('upah.harian.logistic') + else: + vals['name'] = self.env['ir.sequence'].next_by_code('upah.harian.office') return super().create(vals) @@ -140,31 +150,59 @@ class UpahHarian(models.Model): # ========================================================= def action_approve(self): + self.cancel_reason = False or "" + if not self.upah_harian_line.mapped('kegiatan'): + raise UserError("Harus Isi Kegiatan yang dilakukan") if not self.env.user.pic: raise UserError("Only PIC user can approve this document.") + approver = self.env.user.name + if self.state == 'draft': + self.state = 'pic' + elif self.state == 'pic': self.state = 'approved' - self.approved_by = self.env.user.name + elif self.state == 'approved': + self.state = 'waiting_payment' - def action_reset_to_draft(self): + if self.approved_by: + self.approved_by = f"{self.approved_by}, {approver}" + else: + self.approved_by = approver - if self.state == 'cancel': - self.state = 'draft' + def action_reset_to_draft(self): + if self.state != 'cancel': + raise UserError("Cancel Pengajuan Dahulu Sebelum set to Draft") + self.state ='draft' + self.approved_by = False or "" def action_cancel(self): - - if self.state == 'draft': - - if not self.cancel_reason: - raise UserError('Harus Isi Alasan Cancel') - - self.state = 'cancel' + if not self.cancel_reason: + raise UserError('Harus Isi Alasan Cancel') + if self.state in ['paid', 'approved']: + raise UserError('Tidak Bisa Cancel Karena pengajuan sudah diapprove') + self.state = 'cancel' + self.approved_by = False or "" + + @api.depends('attachment_file_image', 'attachment_file_pdf') + def auto_paid_attachment(self): + if self.attachment_file_image or self.attachment_file_pdf: + self.state = 'paid' + self.message_post(body = _("Auto Paid by %s") % self.env.user.name) + def action_create_journal_entries(self): return + # Constrains + @api.constrains('attachment_file_image', 'attachment_file_pdf', 'attachment_type') + def _check_finance_only_attachment(self): + if not self.env.user.has_group('indoteknik_custom.group_role_fat'): + for rec in self: + if rec.attachment_file_image or rec.attachment_file_pdf: + raise ValidationError("Only Finance can upload attachment.") + class UpahHarianLine(models.Model): _name = 'upah.harian.line' @@ -283,6 +321,7 @@ class UpahHarianLine(models.Model): line.total_jam_kerja += tambahan excess_pool -= tambahan + @api.depends('total_jam_kerja', 'upah_harian_id.upah_harian') def _compute_upah_harian(self): diff --git a/indoteknik_custom/views/ir_sequence.xml b/indoteknik_custom/views/ir_sequence.xml index aa56e46a..983cd2f4 100644 --- a/indoteknik_custom/views/ir_sequence.xml +++ b/indoteknik_custom/views/ir_sequence.xml @@ -271,12 +271,20 @@ - + Upah Harian Office upah.harian.office UPHO/%(year)s/%(month)s/ 4 - 1 1 + + + Upah Harian Logistic + upah.harian.logistic + UPHL/%(year)s/%(month)s/ + 4 + 1 + + \ No newline at end of file diff --git a/indoteknik_custom/views/upah_harian_office_views.xml b/indoteknik_custom/views/upah_harian_office_views.xml index a88a1e66..bc4c548a 100644 --- a/indoteknik_custom/views/upah_harian_office_views.xml +++ b/indoteknik_custom/views/upah_harian_office_views.xml @@ -26,7 +26,10 @@
-