summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/product_template.py
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2023-08-23 15:05:00 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2023-08-23 15:05:00 +0700
commit5ff183f7ee77c99327d90e178bdccf77ab2c2cc4 (patch)
treedabca3543c725ac0fc5d66e734c57f2b75fd6d50 /indoteknik_custom/models/product_template.py
parent1e172ec6265592dbd92789c216983ffee5f40e9f (diff)
add new validation for product and product attribute
Diffstat (limited to 'indoteknik_custom/models/product_template.py')
-rwxr-xr-xindoteknik_custom/models/product_template.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py
index bc54b703..a69d6942 100755
--- a/indoteknik_custom/models/product_template.py
+++ b/indoteknik_custom/models/product_template.py
@@ -4,6 +4,7 @@ from odoo.exceptions import AccessError, UserError, ValidationError
import logging
import requests
import json
+import re
_logger = logging.getLogger(__name__)
@@ -50,6 +51,13 @@ class ProductTemplate(models.Model):
is_new_product = fields.Boolean(string='Produk Baru',
help='Centang jika ingin ditammpilkan di website sebagai segment Produk Baru')
seq_new_product = fields.Integer(string='Seq New Product', help='Urutan Sequence New Product')
+
+ @api.constrains('name')
+ def _validate_name(self):
+ pattern = r'^[a-zA-Z0-9\[\]\(\)\.\s/]+$'
+ if not re.match(pattern, self.name):
+ raise UserError('Nama hanya bisa menggunakan angka, huruf kecil, huruf besar, titik, kurung lengkung, kurung siku, garis miring.')
+
# def write(self, vals):
# if 'solr_flag' not in vals and self.solr_flag == 1:
@@ -278,6 +286,12 @@ class ProductProduct(models.Model):
qty_onhand_bandengan = fields.Float(string='Qty Incoming Bandengan', compute='_get_qty_onhand_bandengan')
qty_incoming_bandengan = fields.Float(string='Qty Incoming Bandengan', compute='_get_qty_incoming_bandengan')
sla_version = fields.Integer(string="SLA Version", default=0)
+
+ @api.constrains('name')
+ def _validate_name(self):
+ pattern = r'^[a-zA-Z0-9\[\]\(\)\.\s/]+$'
+ if not re.match(pattern, self.name):
+ raise UserError('Nama hanya bisa menggunakan angka, huruf kecil, huruf besar, titik, kurung lengkung, kurung siku, garis miring.')
def _get_qty_incoming_bandengan(self):
for product in self: