From 4aae32a042a5f77feebfa7e4f504f32a5375eaae Mon Sep 17 00:00:00 2001 From: "Indoteknik ." Date: Wed, 3 Sep 2025 13:52:09 +0700 Subject: (andri) add validasi email, terbilang, & approval pimpinan --- indoteknik_custom/models/letter_receivable.py | 39 ++++++++++++++++++++++++++- indoteknik_custom/views/letter_receivable.xml | 29 +++++++++++++++++--- 2 files changed, 63 insertions(+), 5 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): diff --git a/indoteknik_custom/views/letter_receivable.xml b/indoteknik_custom/views/letter_receivable.xml index fe60eb39..15875da9 100644 --- a/indoteknik_custom/views/letter_receivable.xml +++ b/indoteknik_custom/views/letter_receivable.xml @@ -26,8 +26,7 @@
- +