summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--indoteknik_custom/models/upah_harian_office.py311
-rwxr-xr-xindoteknik_custom/security/ir.model.access.csv1
-rw-r--r--indoteknik_custom/views/upah_harian_office_views.xml92
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 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
- <!-- View upah.harian.office View Tree -->
+ <!-- ================= TREE ================= -->
<record id="view_upah_harian_tree" model="ir.ui.view">
<field name="name">view.upah.harian.tree</field>
<field name="model">upah.harian</field>
@@ -15,92 +15,148 @@
</field>
</record>
- <!-- View upah.harian.office form -->
+
+ <!-- ================= FORM ================= -->
<record id="view_upah_harian_form" model="ir.ui.view">
<field name="name">view.upah.harian.form</field>
<field name="model">upah.harian</field>
<field name="arch" type="xml">
+
<form string="Upah Harian Office">
+
<header>
- <button name="action_create_journal_entries" class="btn-primary" type="object" string="Create Journal Entries" attrs="{'invisible': [('state', 'not in', ['done'])]}"/>
+
+ <button name="action_create_journal_entries" class="btn-primary" type="object" string="Create Journal Entries" attrs="{'invisible': [('state', 'not in', ['approved'])]}"/>
+
<field name="state" widget="statusbar" readonly="1"/>
+
</header>
+
<sheet>
+
<div class="oe_title">
<h1>
<field name="name"/>
</h1>
</div>
+
<group>
+
<group>
<field name="pemohon"/>
<field name="departement_type"/>
<field name="tanggal"/>
<field name="upah_harian"/>
+
+ <field name="sisa_jam_mingguan" class="text-danger" attrs="{'invisible':[('sisa_jam_mingguan','=',0)]}"/>
</group>
+
+ <!-- ATTACHMENT -->
<group>
+
<field name="attachment_type" attrs="{'readonly': [('state', '=', 'approved')]}"/>
- <field name="attachment_file_pdf" filename="attachment_filename"
- widget="pdf_viewer"
- attrs="{'invisible': [('attachment_type', '!=', 'pdf')], 'readonly': [('state', '=', 'approved')]}"/>
+ <field name="attachment_file_pdf" filename="attachment_filename" widget="pdf_viewer" attrs="{'invisible': [('attachment_type', '!=', 'pdf')],
+ 'readonly': [('state', '=', 'approved')]}"/>
+
+ <field name="attachment_file_image" filename="attachment_filename" widget="image" attrs="{'invisible': [('attachment_type', '!=', 'image')],
+ 'readonly': [('state', '=', 'approved')]}" style="max-width:250px; max-height:250px; object-fit:contain;"/>
- <field name="attachment_file_image" filename="attachment_filename"
- widget="image"
- attrs="{'invisible': [('attachment_type', '!=', 'image')], 'readonly': [('state', '=', 'approved')]}"
- style="max-width:250px; max-height:250px; object-fit:contain;"/>
+ <field name="total_upah" readonly="1"/>
- <field name="total_upah"/>
</group>
+
</group>
+
+
+ <!-- ACTIVITY LINE -->
<notebook>
- <page string="Activity Line" name="activity_line">
+
+ <page string="Activity Line">
+
<field name="upah_harian_line">
- <tree editable="top">
- <field name="hari" width="100px"/>
+
+ <!-- LIST -->
+ <tree>
<field name="tanggal_line"/>
+ <field name="hari"/>
<field name="jam_masuk"/>
<field name="jam_keluar"/>
<field name="total_jam_kerja"/>
<field name="is_ganti_jam"/>
<field name="kegiatan"/>
</tree>
+
+ <!-- POPUP FORM -->
+ <form string="Activity">
+
+ <group col="2">
+
+ <field name="tanggal_line"/>
+ <field name="hari" readonly="1"/>
+
+ <field name="jam_masuk"/>
+ <field name="jam_keluar"/>
+
+ <field name="total_jam_kerja" readonly="1"/>
+
+ <field name="is_ganti_jam"/>
+
+ <field name="kegiatan" colspan="2" widget="text" placeholder="Tuliskan kegiatan hari ini..." style="min-height:120px;"/>
+
+ </group>
+
+ </form>
+
</field>
+
</page>
+
</notebook>
+
</sheet>
+
+
+ <!-- CHATTER -->
<div class="oe_chatter">
<field name="message_follower_ids" widget="mail_followers"/>
<field name="message_ids" widget="mail_thread"/>
</div>
</form>
+
</field>
</record>
- <!-- View upah.harian.office search -->
+
<record id="view_upah_harian_search" model="ir.ui.view">
<field name="name">view.upah.harian.search</field>
<field name="model">upah.harian</field>
<field name="arch" type="xml">
<search>
+
+ <field name="name"/>
+ <field name="pemohon"/>
+
<group expand="1" string="Group By">
- <filter string="Name" name="name" domain="[]" context="{'group_by':'name'}"/>
+ <filter string="Pemohon" name="group_pemohon" context="{'group_by':'pemohon'}"/>
</group>
+
</search>
</field>
</record>
+
<record id="action_upah_harian" model="ir.actions.act_window">
<field name="name">Upah Harian</field>
<field name="res_model">upah.harian</field>
<field name="view_mode">tree,form</field>
</record>
- <menuitem id="menu_upah_harian" name="Upah Harian" parent="account.menu_finance_entries" sequence="114" action="action_upah_harian" />
+ <menuitem id="menu_upah_harian" name="Upah Harian" parent="account.menu_finance_entries" sequence="114" action="action_upah_harian"/>
-</odoo>
+</odoo> \ No newline at end of file