summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/product_attribute.py
blob: 784ccd81f7e545794f9b9844ec9c40751668d19c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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):
            pattern_suggest = r'[a-zA-Z0-9\[\]\(\)\.\s/%]+'
            suggest = ''.join(re.findall(pattern_suggest, self.name))
            raise UserError(f'Nama hanya bisa menggunakan angka, huruf kecil, huruf besar, titik, kurung lengkung, kurung siku, garis miring. Contoh: {suggest}')