From fdfe8fbfc45c1d5eb5cfef696bfb21024de19ab5 Mon Sep 17 00:00:00 2001 From: Mqdd Date: Fri, 6 Mar 2026 14:11:05 +0700 Subject: start logic --- indoteknik_custom/models/upah_harian_office.py | 43 +++++++++++++++++----- .../views/upah_harian_office_views.xml | 3 +- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/indoteknik_custom/models/upah_harian_office.py b/indoteknik_custom/models/upah_harian_office.py index 9666a304..d18ce64d 100644 --- a/indoteknik_custom/models/upah_harian_office.py +++ b/indoteknik_custom/models/upah_harian_office.py @@ -28,7 +28,7 @@ class UpahHarianOffice(models.Model): ('hr_ga', 'HR & GA'), ], string='Departement Type', tracking=3, required=True) is_ganti_jam = fields.Boolean('Ganti Jam?', default="False") - total_upah = fields.Float('Total Upah Harian', compute='_compute_total_upah') + total_upah = fields.Float('Total Upah Harian', compute='_compute_total_upah', readonly=True) attachment_file_image = fields.Binary(string='Attachment Image', attachment_filename='attachment_filename_image') attachment_file_pdf = fields.Binary(string='Attachment PDF', attachment_filename='attachment_filename_pdf') attachment_filename_image = fields.Char(string='Filename Image') @@ -49,7 +49,7 @@ class UpahHarianOffice(models.Model): def action_approve(self): if self.state == 'draft' and self.env.user.pic: - self.state = 'done' + self.state = 'approved' self.approved_by = self.env.user.name if not self.env.user.pic: @@ -67,10 +67,10 @@ class UpahHarianOffice(models.Model): else: self.state = 'cancel' + @api.depends('upah_harian_line.upah_harian_compute') def _compute_total_upah(self): - if self.departement_type != 'logistic': - for line in self: - line.total_upah = sum(line.mapped('upah_harian_line').mapped('upah_harian')) + for rec in self: + rec.total_upah = sum(rec.upah_harian_line.mapped('upah_harian_compute')) def action_create_journal_entries(self): return @@ -79,6 +79,9 @@ class UpahHarianOffice(models.Model): class UpahHarianOfficeLine(models.Model): _name = 'upah.harian.line' _description = 'Upah Harian Line' + _order = 'id asc' + + MAX_WORKING_HOUR = 7.5 upah_harian_id = fields.Many2one('upah.harian') upah_harian_compute = fields.Float('Upah Harian Computed', required=True, compute='_compute_upah_harian') @@ -90,10 +93,32 @@ class UpahHarianOfficeLine(models.Model): total_jam_kerja = fields.Float('Total Jam Kerja', compute='_compute_total_jam_kerja') is_ganti_jam = fields.Boolean('Ganti Jam Kerja', default = False) - def _compute_total_jam_kerja(self): + @api.depends('total_jam_kerja', 'upah_harian_id.upah_harian') + def _compute_upah_harian(self): for line in self: - line.total_jam_kerja = line.jam + if line.upah_harian_id.upah_harian: + upah_full = line.upah_harian_id.upah_harian + rate_per_hour = upah_full / self.MAX_WORKING_HOUR + line.upah_harian_compute = rate_per_hour * line.total_jam_kerja + else: + line.upah_harian_compute = 0 - def _compute_upah_harian(self): + @api.depends('jam_masuk', 'jam_keluar') + def _compute_total_jam_kerja(self): + for line in self: + if line.jam_keluar and line.jam_masuk: + total = line.jam_keluar - line.jam_masuk + # Maksimal 7.5 jam + if total > self.MAX_WORKING_HOUR: + total = self.MAX_WORKING_HOUR + if total < 0: + total = 0 + line.total_jam_kerja = total + else: + line.total_jam_kerja = 0 + + @api.constrains('jam_masuk', 'jam_keluar') + def _check_jam_valid(self): for line in self: - line.upah_harian = line.jam + if line.jam_keluar <= line.jam_masuk: + raise ValidationError("Jam keluar harus lebih besar dari jam masuk.") \ 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 9a0c3a2f..f8260552 100644 --- a/indoteknik_custom/views/upah_harian_office_views.xml +++ b/indoteknik_custom/views/upah_harian_office_views.xml @@ -28,7 +28,6 @@
-