summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/letter_receivable.py
diff options
context:
space:
mode:
authorIndoteknik . <it@fixcomart.co.id>2025-09-03 13:52:09 +0700
committerIndoteknik . <it@fixcomart.co.id>2025-09-03 13:52:09 +0700
commit4aae32a042a5f77feebfa7e4f504f32a5375eaae (patch)
tree5c519f2356f10dfe1c2e3418093da51ea5d1523a /indoteknik_custom/models/letter_receivable.py
parent1c71710dbf42106a82c0a8e30ec9cee7f452a387 (diff)
(andri) add validasi email, terbilang, & approval pimpinan
Diffstat (limited to 'indoteknik_custom/models/letter_receivable.py')
-rw-r--r--indoteknik_custom/models/letter_receivable.py39
1 files changed, 38 insertions, 1 deletions
diff --git a/indoteknik_custom/models/letter_receivable.py b/indoteknik_custom/models/letter_receivable.py
index 10198fbf..550aa9e3 100644
--- a/indoteknik_custom/models/letter_receivable.py
+++ b/indoteknik_custom/models/letter_receivable.py
@@ -1,4 +1,8 @@
-from odoo import models, fields, api
+from odoo import models, fields, api, _
+from odoo.exceptions import UserError
+from odoo.exceptions import ValidationError
+from odoo.tools import mail
+from terbilang import Terbilang
class SuratPiutang(models.Model):
_name = "surat.piutang"
@@ -33,6 +37,23 @@ class SuratPiutang(models.Model):
compute='_compute_grand_total',
)
+ grand_total_text = fields.Char(
+ string="Total Terbilang",
+ compute="_compute_grand_total_text",
+ )
+
+ def _compute_grand_total_text(self):
+ tb = Terbilang()
+ for record in self:
+ res = ""
+ if record.grand_total and record.grand_total > 0:
+ try:
+ tb.parse(int(record.grand_total))
+ res = tb.getresult().title() + " Rupiah"
+ except Exception:
+ res = ""
+ record.grand_total_text = res
+
@api.depends('line_ids.amount_residual', 'line_ids.selected')
def _compute_grand_total(self):
for rec in self:
@@ -40,6 +61,21 @@ class SuratPiutang(models.Model):
line.amount_residual or 0.0 for line in rec.line_ids if line.selected
)
+ @api.constrains("tujuan_email")
+ def _check_email_format(self):
+ for rec in self:
+ if rec.tujuan_email and not mail.single_email_re.match(rec.tujuan_email):
+ raise ValidationError(_("Format email tidak valid: %s") % rec.tujuan_email)
+
+ def action_approve(self):
+ pimpinan_user_ids = [7] # Pak Akbar
+ if self.env.user.id not in pimpinan_user_ids:
+ raise UserError("Hanya Pimpinan yang berhak menyetujui tahap ini.")
+ for rec in self:
+ if rec.state == "approval_pimpinan":
+ rec.state = "sent"
+ rec.send_date = fields.Datetime.now()
+
@api.onchange('partner_id')
def _onchange_partner_id(self):
if self.partner_id:
@@ -128,6 +164,7 @@ class SuratPiutang(models.Model):
tahun = today.strftime("%y")
vals["name"] = f"{seq}/LO/FAT/IDG/{bulan_romawi}/{tahun}"
+ vals["state"] = "approval_pimpinan"
return super().create(vals)
class SuratPiutangLine(models.Model):