diff --git a/barcodes/__openerp__.py b/barcodes/__openerp__.py
index 74a1a961..06acc990 100644
--- a/barcodes/__openerp__.py
+++ b/barcodes/__openerp__.py
@@ -27,13 +27,32 @@ It provides the following features:
- Patterns to identify barcodes containing a numerical value (e.g. weight, price)
- Definition of barcode aliases that allow to identify the same product with different barcodes
- Support for encodings EAN-13, EAN-8 and UPC-A
+
+Backport Note
+-------------
+This module is a backport of Odoo 9.0 modules. It has been done to have
+a module in V7 that have the same models. barcode, nomenclatures, rules than
+in V9.0 and same rules (same xml_ids).
+
+Data comes from stock, point_of_sale and barcodes V9.0 modules.
+
+The following changes has been done:
+- copyright has been added to Odoo SA in the header and licence LGPLv3 has been mentionned
+- new api usage has been removed
+- noqa has been set for all py files, to avoid to break OCA rules checked by Travis
+
+The following features has not been backported
+- JS feature. (PoS features, etc.)
+- abstract model. "barcodes.barcode_events_mixin"
+
""",
- 'depends': ['web'],
+ 'depends': ['web', 'stock', 'point_of_sale'],
'data': [
'data/barcodes_data.xml',
+ 'data/default_barcode_patterns.xml',
'barcodes_view.xml',
'security/ir.model.access.csv',
- 'views/templates.xml',
+ # 'views/templates.xml',
],
'installable': True,
'auto_install': False,
diff --git a/barcodes/barcodes.py b/barcodes/barcodes.py
index bdd4d711..1b61735d 100644
--- a/barcodes/barcodes.py
+++ b/barcodes/barcodes.py
@@ -2,16 +2,10 @@
# Copyright (C) 2004-Today Odoo S.A.
# License LGPLv3 (https://github.com/odoo/odoo/blob/9.0/LICENSE).
# flake8: noqa
-import logging
import re
-import openerp
-from openerp import tools, models, fields, api
from openerp.osv import fields, osv
from openerp.tools.translate import _
-from openerp.exceptions import ValidationError
-
-_logger = logging.getLogger(__name__)
UPC_EAN_CONVERSIONS = [
@@ -177,29 +171,38 @@ class barcode_nomenclature(osv.osv):
return parsed_result
-class barcode_rule(models.Model):
+class barcode_rule(osv.osv):
_name = 'barcode.rule'
_order = 'sequence asc'
- @api.model
- def _encoding_selection_list(self):
- return [
+ _encoding_selection_list = [
('any', _('Any')),
('ean13', 'EAN-13'),
('ean8', 'EAN-8'),
('upca', 'UPC-A'),
]
- @api.model
- def _get_type_selection(self):
- return [('alias', _('Alias')), ('product', _('Unit Product'))]
+ _get_type_selection = [
+ ('alias', _('Alias')),
+ ('product', _('Unit Product')),
+ # Backport Note : come from point_of_sale V9.0 module
+ ('weight', _('Weighted Product')),
+ ('price', _('Priced Product')),
+ ('discount', _('Discounted Product')),
+ ('client', _('Client')),
+ ('cashier', _('Cashier')),
+ # Backport Note : come from stock V9.0 module
+ ('location', _('Location')),
+ ('lot', _('Lot')),
+ ('package', _('Package')),
+ ]
_columns = {
'name': fields.char('Rule Name', size=32, required=True, help='An internal identification for this barcode nomenclature rule'),
'barcode_nomenclature_id': fields.many2one('barcode.nomenclature','Barcode Nomenclature'),
'sequence': fields.integer('Sequence', help='Used to order rules such that rules with a smaller sequence match first'),
- 'encoding': fields.selection('_encoding_selection_list','Encoding',required=True,help='This rule will apply only if the barcode is encoded with the specified encoding'),
- 'type': fields.selection('_get_type_selection','Type', required=True),
+ 'encoding': fields.selection(selection=_encoding_selection_list,string='Encoding',required=True,help='This rule will apply only if the barcode is encoded with the specified encoding'),
+ 'type': fields.selection(selection=_get_type_selection,string='Type', required=True),
'pattern': fields.char('Barcode Pattern', size=32, help="The barcode matching pattern", required=True),
'alias': fields.char('Alias',size=32,help='The matched pattern will alias to this barcode', required=True),
}
@@ -211,19 +214,37 @@ class barcode_rule(models.Model):
'alias': "0",
}
- @api.one
- @api.constrains('pattern')
- def _check_pattern(self):
- p = self.pattern.replace("\\\\", "X").replace("\{", "X").replace("\}", "X")
+ def _check_pattern_multi(self, cr, uid, ids, context=None):
+ res = []
+ for rule in self.browse(cr, uid, ids, context=context):
+ res.append(self._check_pattern_one(cr, uid, rule, context=context))
+ return all(res)
+
+ _constraints = [
+ (
+ _check_pattern_multi,
+ "There is a syntax error in the barcode pattern. "
+ "One of the following errors occured : \n"
+ "- braces can only contain N's followed by D's.\n"
+ "- empty braces\n"
+ "- a rule can only contain one pair of braces\n"
+ "- '*' is not a valid Regex Barcode Pattern. "
+ "(Did you mean '.*' ?)",
+ ['pattern']),
+ ]
+
+ def _check_pattern_one(self, cr, uid, rule, context=None):
+ 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 ") + self.pattern + _(": braces can only contain N's followed by D's."))
+ return False
elif re.search("[{][}]", p):
- raise ValidationError(_("There is a syntax error in the barcode pattern ") + self.pattern + _(": empty braces."))
+ return False
elif len(findall) != 0:
- raise ValidationError(_("There is a syntax error in the barcode pattern ") + self.pattern + _(": a rule can only contain one pair of braces."))
+ return False
elif p == '*':
- raise ValidationError(_(" '*' is not a valid Regex Barcode Pattern. Did you mean '.*' ?"))
+ return False
+ return True
diff --git a/barcodes/barcodes_view.xml b/barcodes/barcodes_view.xml
index 06ae009e..1da523e6 100644
--- a/barcodes/barcodes_view.xml
+++ b/barcodes/barcodes_view.xml
@@ -6,7 +6,7 @@
Barcode Nomenclatures
barcode.nomenclature
-
+
+
+
+
+
diff --git a/barcodes/data/default_barcode_patterns.xml b/barcodes/data/default_barcode_patterns.xml
new file mode 100644
index 00000000..630f510a
--- /dev/null
+++ b/barcodes/data/default_barcode_patterns.xml
@@ -0,0 +1,79 @@
+
+
+
+
+
+ Cashier Barcodes
+
+ 50
+ cashier
+ any
+ 041
+
+
+
+ Customer Barcodes
+
+ 40
+ client
+ any
+ 042
+
+
+
+ Discount Barcodes
+
+ 20
+ discount
+ any
+ 22{NN}
+
+
+
+ Price Barcodes 2 Decimals
+
+ 14
+ price
+ ean13
+ 23.....{NNNDD}
+
+
+
+
+ Weight Barcodes 3 Decimals
+
+ 36
+ weight
+ ean13
+ 21.....{NNDDD}
+
+
+
+ Package barcodes
+
+ 70
+ package
+ any
+ PACK
+
+
+
+ Lot barcodes
+
+ 80
+ lot
+ any
+ 10
+
+
+
+ Location barcodes
+
+ 60
+ location
+ any
+ 414
+
+
+
+
diff --git a/barcodes/models/__init__.py b/barcodes/models/__init__.py
index 11c1bcaa..d7e5fa76 100644
--- a/barcodes/models/__init__.py
+++ b/barcodes/models/__init__.py
@@ -3,4 +3,4 @@
# License LGPLv3 (https://github.com/odoo/odoo/blob/9.0/LICENSE).
# flake8: noqa
-import barcode_events_mixin
+# import barcode_events_mixin
diff --git a/barcodes/static/src/description/barcode_nomenclature.png b/barcodes/static/src/description/barcode_nomenclature.png
new file mode 100644
index 00000000..59ce830e
Binary files /dev/null and b/barcodes/static/src/description/barcode_nomenclature.png differ