[MOV] barcodes: split barcodes.py
Separates `barcode.nomenclature` and `barcode.rule` in their own file. task-1968113 Co-authored-by: ryv-odoo<ryv@odoo.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from . import barcodes
|
||||
from . import barcode_events_mixin
|
||||
from . import barcode_nomenclature
|
||||
from . import barcode_rule
|
||||
from . import ir_http
|
||||
from . import res_company
|
||||
|
||||
+1
-39
@@ -1,8 +1,7 @@
|
||||
import logging
|
||||
import re
|
||||
|
||||
from odoo import tools, models, fields, api, _
|
||||
from odoo.exceptions import ValidationError
|
||||
from odoo import models, fields
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -165,40 +164,3 @@ class BarcodeNomenclature(models.Model):
|
||||
return parsed_result
|
||||
|
||||
return parsed_result
|
||||
|
||||
class BarcodeRule(models.Model):
|
||||
_name = 'barcode.rule'
|
||||
_description = 'Barcode Rule'
|
||||
_order = 'sequence asc'
|
||||
|
||||
|
||||
name = fields.Char(string='Rule Name', size=32, required=True, help='An internal identification for this barcode nomenclature rule')
|
||||
barcode_nomenclature_id = fields.Many2one('barcode.nomenclature', string='Barcode Nomenclature')
|
||||
sequence = fields.Integer(string='Sequence', help='Used to order rules such that rules with a smaller sequence match first')
|
||||
encoding = fields.Selection([
|
||||
('any', 'Any'),
|
||||
('ean13', 'EAN-13'),
|
||||
('ean8', 'EAN-8'),
|
||||
('upca', 'UPC-A'),
|
||||
], string='Encoding', required=True, default='any', help='This rule will apply only if the barcode is encoded with the specified encoding')
|
||||
type = fields.Selection([
|
||||
('alias', 'Alias'),
|
||||
('product', 'Unit Product')
|
||||
], string='Type', required=True, default='product')
|
||||
pattern = fields.Char(string='Barcode Pattern', size=32, help="The barcode matching pattern", required=True, default='.*')
|
||||
alias = fields.Char(string='Alias', size=32, default='0', help='The matched pattern will alias to this barcode', required=True)
|
||||
|
||||
@api.constrains('pattern')
|
||||
def _check_pattern(self):
|
||||
for rule in self:
|
||||
p = rule.pattern.replace("\\\\", "X").replace("\{", "X").replace("\}", "X")
|
||||
findall = re.findall("[{]|[}]", p) # p does not contain escaped { or }
|
||||
if len(findall) == 2:
|
||||
if not re.search("[{][N]*[D]*[}]", p):
|
||||
raise ValidationError(_("There is a syntax error in the barcode pattern %(pattern)s: braces can only contain N's followed by D's.", pattern=rule.pattern))
|
||||
elif re.search("[{][}]", p):
|
||||
raise ValidationError(_("There is a syntax error in the barcode pattern %(pattern)s: empty braces.", pattern=rule.pattern))
|
||||
elif len(findall) != 0:
|
||||
raise ValidationError(_("There is a syntax error in the barcode pattern %(pattern)s: a rule can only contain one pair of braces.", pattern=rule.pattern))
|
||||
elif p == '*':
|
||||
raise ValidationError(_(" '*' is not a valid Regex Barcode Pattern. Did you mean '.*' ?"))
|
||||
@@ -0,0 +1,42 @@
|
||||
import re
|
||||
|
||||
from odoo import models, fields, api, _
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class BarcodeRule(models.Model):
|
||||
_name = 'barcode.rule'
|
||||
_description = 'Barcode Rule'
|
||||
_order = 'sequence asc'
|
||||
|
||||
|
||||
name = fields.Char(string='Rule Name', size=32, required=True, help='An internal identification for this barcode nomenclature rule')
|
||||
barcode_nomenclature_id = fields.Many2one('barcode.nomenclature', string='Barcode Nomenclature')
|
||||
sequence = fields.Integer(string='Sequence', help='Used to order rules such that rules with a smaller sequence match first')
|
||||
encoding = fields.Selection([
|
||||
('any', 'Any'),
|
||||
('ean13', 'EAN-13'),
|
||||
('ean8', 'EAN-8'),
|
||||
('upca', 'UPC-A'),
|
||||
], string='Encoding', required=True, default='any', help='This rule will apply only if the barcode is encoded with the specified encoding')
|
||||
type = fields.Selection([
|
||||
('alias', 'Alias'),
|
||||
('product', 'Unit Product')
|
||||
], string='Type', required=True, default='product')
|
||||
pattern = fields.Char(string='Barcode Pattern', size=32, help="The barcode matching pattern", required=True, default='.*')
|
||||
alias = fields.Char(string='Alias', size=32, default='0', help='The matched pattern will alias to this barcode', required=True)
|
||||
|
||||
@api.constrains('pattern')
|
||||
def _check_pattern(self):
|
||||
for rule in self:
|
||||
p = rule.pattern.replace("\\\\", "X").replace("\{", "X").replace("\}", "X")
|
||||
findall = re.findall("[{]|[}]", p) # p does not contain escaped { or }
|
||||
if len(findall) == 2:
|
||||
if not re.search("[{][N]*[D]*[}]", p):
|
||||
raise ValidationError(_("There is a syntax error in the barcode pattern %(pattern)s: braces can only contain N's followed by D's.", pattern=rule.pattern))
|
||||
elif re.search("[{][}]", p):
|
||||
raise ValidationError(_("There is a syntax error in the barcode pattern %(pattern)s: empty braces.", pattern=rule.pattern))
|
||||
elif len(findall) != 0:
|
||||
raise ValidationError(_("There is a syntax error in the barcode pattern %(pattern)s: a rule can only contain one pair of braces.", pattern=rule.pattern))
|
||||
elif p == '*':
|
||||
raise ValidationError(_(" '*' is not a valid Regex Barcode Pattern. Did you mean '.*' ?"))
|
||||
Reference in New Issue
Block a user