summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMqdd <ahmadmiqdad27@gmail.com>2026-03-11 10:42:53 +0700
committerMqdd <ahmadmiqdad27@gmail.com>2026-03-11 10:42:53 +0700
commit38313de6949c4f39ebe7cb431d5beb15baa38d06 (patch)
tree9e6e52129ed7bb672cd849564a5931925236b91c
parent8f59bd1fc09040241408b3bb2389c76b0e111e6e (diff)
<Miqdad> major fix
-rw-r--r--indoteknik_custom/models/upah_harian_office.py73
-rw-r--r--indoteknik_custom/views/ir_sequence.xml12
-rw-r--r--indoteknik_custom/views/upah_harian_office_views.xml8
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 @@
</record>
<record id="seq_upah_harian_office" model="ir.sequence">
- <field name="name"></field>
+ <field name="name">Upah Harian Office</field>
<field name="code">upah.harian.office</field>
<field name="prefix">UPHO/%(year)s/%(month)s/</field>
<field name="padding">4</field>
- <field name="number_next">1</field>
<field name="number_increment">1</field>
</record>
+
+ <record id="seq_upah_harian_logistic" model="ir.sequence">
+ <field name="name">Upah Harian Logistic</field>
+ <field name="code">upah.harian.logistic</field>
+ <field name="prefix">UPHL/%(year)s/%(month)s/</field>
+ <field name="padding">4</field>
+ <field name="number_increment">1</field>
+ </record>
+
</data>
</odoo> \ 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 @@
<header>
- <button name="action_create_journal_entries" class="btn-primary" type="object" string="Create Journal Entries" attrs="{'invisible': [('state', 'not in', ['approved'])]}"/>
+ <button name="action_create_journal_entries" class="btn-primary" type="object" string="Create Journal Entries" attrs="{'invisible': [('state', 'not in', ['waiting_payment'])]}"/>
+ <button name="action_approve" class="btn-primary" type="object" string="Approve" attrs="{'invisible': [('state', 'in', ['paid', 'cancel', 'waiting_payment'])]}"/>
+ <button name="action_cancel" class="btn-secondary" type="object" string="Cancel" attrs="{'invisible': [('state', 'in', ['paid', 'cancel'])]}"/>
+ <button name="action_reset_to_draft" class="btn-secondary" type="object" string="Reset to Draft" attrs="{'invisible': [('state', 'not in', ['cancel'])]}"/>
<field name="state" widget="statusbar" readonly="1"/>
@@ -49,8 +52,9 @@
<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)]}"/>
+ <field name="approved_by" attrs="{'invisible': [('state', 'in', ['draft', 'cancel'])]}"/>
+ <field name="cancel_reason"/>
</group>