From 5ff183f7ee77c99327d90e178bdccf77ab2c2cc4 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 23 Aug 2023 15:05:00 +0700 Subject: add new validation for product and product attribute --- indoteknik_custom/models/product_attribute.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 indoteknik_custom/models/product_attribute.py (limited to 'indoteknik_custom/models/product_attribute.py') diff --git a/indoteknik_custom/models/product_attribute.py b/indoteknik_custom/models/product_attribute.py new file mode 100644 index 00000000..51ef97cf --- /dev/null +++ b/indoteknik_custom/models/product_attribute.py @@ -0,0 +1,13 @@ +from odoo import fields, models, api, _ +from odoo.exceptions import AccessError, UserError, ValidationError +import re + +class ProductAttributeValue(models.Model): + _inherit = 'product.attribute.value' + + @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.') + \ No newline at end of file -- cgit v1.2.3