From 6481b0748f6872a37961252a213e55cec8227ed5 Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Wed, 20 Sep 2023 09:42:33 +0700 Subject: fix product attribute name --- indoteknik_custom/models/product_attribute.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'indoteknik_custom/models/product_attribute.py') diff --git a/indoteknik_custom/models/product_attribute.py b/indoteknik_custom/models/product_attribute.py index 784ccd81..e3076805 100644 --- a/indoteknik_custom/models/product_attribute.py +++ b/indoteknik_custom/models/product_attribute.py @@ -5,11 +5,16 @@ import re class ProductAttributeValue(models.Model): _inherit = 'product.attribute.value' + @api.constrains('name') def _validate_name(self): - pattern = r'^[a-zA-Z0-9\[\]\(\)\.\s/%]+$' + 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 = r'[a-zA-Z0-9\[\]\(\)\.\s/%]+' + pattern_suggest = rf"{rule_regex}" 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}') + raise UserError(f'Contoh yang benar adalah {suggest}') + + + \ No newline at end of file -- cgit v1.2.3