From 54219f08d0269ba7f33445aa0da18e1f19aed5c3 Mon Sep 17 00:00:00 2001 From: Mqdd Date: Sun, 8 Mar 2026 21:37:10 +0700 Subject: ganti jam logic --- indoteknik_custom/models/upah_harian_office.py | 311 ++++++++++++++++----- indoteknik_custom/security/ir.model.access.csv | 1 + .../views/upah_harian_office_views.xml | 92 ++++-- 3 files changed, 322 insertions(+), 82 deletions(-) diff --git a/indoteknik_custom/models/upah_harian_office.py b/indoteknik_custom/models/upah_harian_office.py index d18ce64d..0e91a402 100644 --- a/indoteknik_custom/models/upah_harian_office.py +++ b/indoteknik_custom/models/upah_harian_office.py @@ -7,71 +7,157 @@ class UpahHarianOffice(models.Model): _inherit = ['mail.thread', 'mail.activity.mixin'] name = fields.Char(readonly=True) - pemohon = fields.Many2one('res.users', String='Pemohon', required=True, domain = ([('active', '=', True), ('share', '=', False)])) - tanggal = fields.Date('Tanggal Pengajuan', required=True) + + pemohon = fields.Many2one( + 'res.users', + string='Pemohon', + required=True, + domain=[('active', '=', True), ('share', '=', False)] + ) + + tanggal = fields.Date( + 'Tanggal Pengajuan', + required=True, + default=fields.Date.today() + ) + upah_harian = fields.Float('Upah Harian') notes = fields.Text('Notes') - state = fields.Selection([('draft', 'Draft'), ('approved', 'Approved'), ('paid', 'Paid'), ('cancel', 'Canceled')], default='draft') + + state = fields.Selection([ + ('draft', 'Draft'), + ('approved', 'Approved'), + ('paid', 'Paid'), + ('cancel', 'Canceled') + ], default='draft') + cancel_reason = fields.Text('Alasan Cancel') - attachment = fields.Binary('Attachment') + approved_by = fields.Char('Approved By') - attachment_type = fields.Selection([('pdf', 'PDF'), ('image', 'Image')]) - upah_harian_line = fields.One2many('upah.harian.line', 'upah_harian_id') + departement_type = fields.Selection([ - ('sales', 'Sales'), - ('merchandiser', 'Merchandiser'), - ('marketing', 'Marketing'), - ('logistic', 'Logistic'), + ('sales', 'Sales'), + ('merchandiser', 'Merchandiser'), + ('marketing', 'Marketing'), + ('logistic', 'Logistic'), ('procurement', 'Procurement'), ('fat', 'FAT'), - ('it', 'IT'), + ('it', 'IT'), ('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', 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') - attachment_filename_pdf = fields.Char(string='Filename PDF') + ], string='Departement Type', required=True, tracking=True) + + upah_harian_line = fields.One2many( + 'upah.harian.line', + 'upah_harian_id', + string='Activity Line' + ) + + total_upah = fields.Float( + 'Total Upah Harian', + compute='_compute_total_upah', + store=True + ) + + sisa_jam_mingguan = fields.Float( + string='Sisa Jam Mingguan', + compute='_compute_sisa_jam_mingguan' + ) + + attachment_type = fields.Selection([ + ('pdf', 'PDF'), + ('image', 'Image') + ]) + + 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() + attachment_filename_pdf = fields.Char() + + # ========================================================= + # COMPUTE + # ========================================================= + + @api.depends('upah_harian_line.upah_harian_compute') + def _compute_total_upah(self): + for rec in self: + rec.total_upah = sum(rec.upah_harian_line.mapped('upah_harian_compute')) + + @api.depends('upah_harian_line.jam_masuk', 'upah_harian_line.jam_keluar') + def _compute_sisa_jam_mingguan(self): + + MAX = 7.5 + + for rec in self: + total_kurang = 0 + + for line in rec.upah_harian_line: + jam = max(line.jam_keluar - line.jam_masuk, 0) + + if jam < MAX: + total_kurang += (MAX - jam) + + rec.sisa_jam_mingguan = total_kurang + + # ========================================================= + # ONCHANGE + # ========================================================= @api.onchange('attachment_type') def _onchange_attachment_type(self): + self.attachment_file_image = False self.attachment_filename_image = False + self.attachment_file_pdf = False self.attachment_filename_pdf = False + # ========================================================= + # CREATE + # ========================================================= + @api.model def create(self, vals): + vals['name'] = self.env['ir.sequence'].next_by_code('upah.harian.office') - return super(UpahHarianOffice, self).create(vals) - + + return super().create(vals) + + # ========================================================= + # ACTION + # ========================================================= + def action_approve(self): - if self.state == 'draft' and self.env.user.pic: - self.state = 'approved' - self.approved_by = self.env.user.name if not self.env.user.pic: raise UserError("Only PIC user can approve this document.") - self.state = 'done' + if self.state == 'draft': + self.state = 'approved' + self.approved_by = self.env.user.name + def action_reset_to_draft(self): + if self.state == 'cancel': self.state = 'draft' - + def action_cancel(self): + if self.state == 'draft': - if self.cancel_reason == '' or self.cancel_reason == False: - raise UserError ('Harus Isi Alasan Cancel') - else: - self.state = 'cancel' - - @api.depends('upah_harian_line.upah_harian_compute') - def _compute_total_upah(self): - for rec in self: - rec.total_upah = sum(rec.upah_harian_line.mapped('upah_harian_compute')) - + + if not self.cancel_reason: + raise UserError('Harus Isi Alasan Cancel') + + self.state = 'cancel' + def action_create_journal_entries(self): return @@ -79,46 +165,143 @@ class UpahHarianOffice(models.Model): class UpahHarianOfficeLine(models.Model): _name = 'upah.harian.line' _description = 'Upah Harian Line' - _order = 'id asc' + _order = 'tanggal_line 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') + upah_harian_id = fields.Many2one( + 'upah.harian', + ondelete='cascade' + ) + + tanggal_line = fields.Date( + 'Tanggal', + required=True + ) + hari = fields.Char('Hari') - jam_masuk = fields.Float('Jam Masuk', required=True) - jam_keluar = fields.Float('Jam Keluar', required=True) - tanggal_line = fields.Date('Tanggal', required=True) - kegiatan = fields.Char('Kegiatan', required=True) - total_jam_kerja = fields.Float('Total Jam Kerja', compute='_compute_total_jam_kerja') - is_ganti_jam = fields.Boolean('Ganti Jam Kerja', default = False) - - @api.depends('total_jam_kerja', 'upah_harian_id.upah_harian') + + jam_masuk = fields.Float( + 'Jam Masuk', + required=True + ) + + jam_keluar = fields.Float( + 'Jam Keluar', + required=True + ) + + kegiatan = fields.Text( + 'Kegiatan', + required=True + ) + + is_ganti_jam = fields.Boolean( + 'Ganti Jam Kerja', + default=False + ) + + total_jam_kerja = fields.Float( + 'Total Jam Kerja', + compute='_compute_total_jam_kerja', + store=True + ) + + upah_harian_compute = fields.Float( + 'Upah Harian', + compute='_compute_upah_harian', + store=True + ) + + # ========================================================= + # COMPUTE + # ========================================================= + + @api.depends('jam_masuk', 'jam_keluar', 'is_ganti_jam') + def _compute_total_jam_kerja(self): + for rec in self: + + if not rec.jam_masuk or not rec.jam_keluar: + rec.total_jam_kerja = 0 + continue + + masuk = rec.jam_masuk + keluar = rec.jam_keluar + + if rec.is_ganti_jam: + rec.total_jam_kerja = keluar - masuk + else: + normal_start = 8.5 + normal_end = 16.5 + + start = max(masuk, normal_start) + end = min(keluar, normal_end) + + total = end - start + + if total < 0: + total = 0 + + if total > 7.5: + total = 7.5 + + rec.total_jam_kerja = total + + @api.depends( + 'jam_masuk', + 'jam_keluar', + 'is_ganti_jam', + 'upah_harian_id.upah_harian' + ) def _compute_upah_harian(self): + + MAX = self.MAX_WORKING_HOUR + for line in self: + + jam = max(line.jam_keluar - line.jam_masuk, 0) + + jam_final = min(jam, MAX) + 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 + rate = line.upah_harian_id.upah_harian / MAX + line.upah_harian_compute = jam_final * rate else: line.upah_harian_compute = 0 - @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 - + # ========================================================= + # VALIDATION + # ========================================================= + @api.constrains('jam_masuk', 'jam_keluar') def _check_jam_valid(self): + for line in self: + if line.jam_keluar <= line.jam_masuk: - raise ValidationError("Jam keluar harus lebih besar dari jam masuk.") \ No newline at end of file + raise ValidationError( + "Jam keluar harus lebih besar dari jam masuk." + ) + + # ========================================================= + # ONCHANGE + # ========================================================= + + @api.onchange('tanggal_line') + def _onchange_tanggal(self): + + if self.tanggal_line: + + day = self.tanggal_line.strftime('%A') + + mapping = { + 'Monday': 'Senin', + 'Tuesday': 'Selasa', + 'Wednesday': 'Rabu', + 'Thursday': 'Kamis', + 'Friday': 'Jumat', + 'Saturday': 'Sabtu', + 'Sunday': 'Minggu', + } + + self.hari = mapping.get(day) \ No newline at end of file diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv index 362e0951..25c39522 100755 --- a/indoteknik_custom/security/ir.model.access.csv +++ b/indoteknik_custom/security/ir.model.access.csv @@ -225,4 +225,5 @@ access_token_log,access.token.log,model_token_log,,1,1,1,1 access_upah_harian_office,upah.harian.office,model_upah_harian,base.group_user,1,1,1,1 access_upah_harian_office_line,upah.harian.line,model_upah_harian_line,base.group_user,1,1,1,1 + access_account_move_change_date_wizard,access.account.move.change.date.wizard,model_account_move_change_date_wizard,,1,1,1,1 diff --git a/indoteknik_custom/views/upah_harian_office_views.xml b/indoteknik_custom/views/upah_harian_office_views.xml index f8260552..a88a1e66 100644 --- a/indoteknik_custom/views/upah_harian_office_views.xml +++ b/indoteknik_custom/views/upah_harian_office_views.xml @@ -1,7 +1,7 @@ - + view.upah.harian.tree upah.harian @@ -15,92 +15,148 @@ - + + view.upah.harian.form upah.harian +
+
-
+ +

+ + + + + + + - + + + - + - + + + + - + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
- + view.upah.harian.search upah.harian + + + + - + + + Upah Harian upah.harian tree,form - + -
+ \ No newline at end of file -- cgit v1.2.3