summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMqdd <ahmadmiqdad27@gmail.com>2026-02-25 11:41:20 +0700
committerMqdd <ahmadmiqdad27@gmail.com>2026-02-25 11:41:20 +0700
commitcbbf60e2fbf86dd50397342ce171796e1f983448 (patch)
treecad193148a371f95c85707c76b07a2a88de6c354
parent1112947139e69732589352359105e7602d6539b2 (diff)
<MIqdad> fix format npwp from website
-rw-r--r--indoteknik_custom/models/res_partner.py34
1 files changed, 22 insertions, 12 deletions
diff --git a/indoteknik_custom/models/res_partner.py b/indoteknik_custom/models/res_partner.py
index 7f4feb75..5bbaaf1c 100644
--- a/indoteknik_custom/models/res_partner.py
+++ b/indoteknik_custom/models/res_partner.py
@@ -298,26 +298,36 @@ class ResPartner(models.Model):
def _check_npwp(self):
for record in self:
npwp = record.npwp.strip() if record.npwp else ''
- # Abaikan validasi jika NPWP kosong atau diisi "0"
+
if not npwp or npwp == '0' or npwp == '00.000.000.0-000.000':
continue
-
- # Validasi untuk NPWP 15 digit (format: 99.999.999.9-999.999)
- if len(npwp) == 20:
- # Regex untuk 15 digit dengan format titik dan tanda hubung
+
+ elif len(npwp) == 15 and npwp.isdigit():
+ formatted = f"{npwp[0:2]}.{npwp[2:5]}.{npwp[5:8]}.{npwp[8]}-{npwp[9:12]}.{npwp[12:15]}"
+ record.npwp = formatted
+
+ elif len(npwp) == 20:
pattern_15_digit = r'^\d{2}\.\d{3}\.\d{3}\.\d{1}-\d{3}\.\d{3}$'
if not re.match(pattern_15_digit, npwp):
- raise ValidationError("Format NPWP 15 digit yang dimasukkan salah. Pastikan format yang benar adalah: 99.999.999.9-999.999")
-
- # Validasi untuk NPWP 16 digit (hanya angka tanpa titik atau tanda hubung)
+ raise ValidationError(
+ "Format NPWP 15 digit yang dimasukkan salah. "
+ "Pastikan format yang benar adalah: 99.999.999.9-999.999"
+ )
+
elif len(npwp) == 16:
pattern_16_digit = r'^\d{16}$'
if not re.match(pattern_16_digit, npwp):
- raise ValidationError("Format NPWP 16 digit yang dimasukkan salah. Format yang benar adalah 16 digit angka tanpa titik atau tanda hubung.")
-
- # Validasi panjang NPWP jika lebih atau kurang dari 15 atau 16 digit
+ raise ValidationError(
+ "Format NPWP 16 digit yang dimasukkan salah. "
+ "Format yang benar adalah 16 digit angka tanpa titik atau tanda hubung."
+ )
+
else:
- raise ValidationError("Digit NPWP yang dimasukkan tidak sesuai. Pastikan NPWP memiliki 15 digit dengan format tertentu (99.999.999.9-999.999) atau 16 digit tanpa tanda hubung.")
+ raise ValidationError(
+ "Digit NPWP yang dimasukkan tidak sesuai. "
+ "Pastikan NPWP memiliki 15 digit dengan format tertentu "
+ "(99.999.999.9-999.999) atau 16 digit tanpa tanda hubung."
+ )
# def write(self, vals):