summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/product_attribute.py
blob: e3076805c98e0164c13497c0de7b1f98e9655371 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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):
        rule_regex = self.env['ir.config_parameter'].sudo().get_param('product.product.rule_name_regex') or ''
        pattern = rf'^{rule_regex}$'
        if not re.match(pattern, self.name):
            pattern_suggest = rf"{rule_regex}"
            suggest = ''.join(re.findall(pattern_suggest, self.name))
            raise UserError(f'Contoh yang benar adalah {suggest}')