Browse Source

[BACKPORT] to V7. use old api. backport data from stock point_of_sale and barcodes V9.0 modules. Disable JS features.

pull/121/head
Sylvain LE GAL 8 years ago
parent
commit
05364b75b5
  1. 23
      barcodes/__openerp__.py
  2. 67
      barcodes/barcodes.py
  3. 8
      barcodes/barcodes_view.xml
  4. 79
      barcodes/data/default_barcode_patterns.xml
  5. 2
      barcodes/models/__init__.py
  6. BIN
      barcodes/static/src/description/barcode_nomenclature.png

23
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,

67
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

8
barcodes/barcodes_view.xml

@ -6,7 +6,7 @@
<field name="name">Barcode Nomenclatures</field>
<field name="model">barcode.nomenclature</field>
<field name="arch" type="xml">
<form string="Barcode Nomenclature">
<form string="Barcode Nomenclature" version="7.0">
<sheet>
<group col="4">
<field name="name" />
@ -82,5 +82,11 @@
</form>
</field>
</record>
<!-- Barcode Nomenclatures -->
<!-- Backport Note : come from point_of_sale V9.0 module -->
<menuitem parent="point_of_sale.menu_point_config_product" action="action_barcode_nomenclature_form" id="point_of_sale.menu_pos_barcode_nomenclature_all"
sequence="30"/>
</data>
</openerp>

79
barcodes/data/default_barcode_patterns.xml

@ -0,0 +1,79 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!-- Backport Note : come from point_of_sale V9.0 module -->
<record id="point_of_sale.barcode_rule_cashier" model="barcode.rule">
<field name="name">Cashier Barcodes</field>
<field name="barcode_nomenclature_id" ref="default_barcode_nomenclature"/>
<field name="sequence">50</field>
<field name="type">cashier</field>
<field name="encoding">any</field>
<field name="pattern">041</field>
</record>
<record id="point_of_sale.barcode_rule_client" model="barcode.rule">
<field name="name">Customer Barcodes</field>
<field name="barcode_nomenclature_id" ref="default_barcode_nomenclature"/>
<field name="sequence">40</field>
<field name="type">client</field>
<field name="encoding">any</field>
<field name="pattern">042</field>
</record>
<record id="point_of_sale.barcode_rule_discount" model="barcode.rule">
<field name="name">Discount Barcodes</field>
<field name="barcode_nomenclature_id" ref="default_barcode_nomenclature"/>
<field name="sequence">20</field>
<field name="type">discount</field>
<field name="encoding">any</field>
<field name="pattern">22{NN}</field>
</record>
<record id="point_of_sale.barcode_rule_price_two_dec" model="barcode.rule">
<field name="name">Price Barcodes 2 Decimals</field>
<field name="barcode_nomenclature_id" ref="default_barcode_nomenclature"/>
<field name="sequence">14</field>
<field name="type">price</field>
<field name="encoding">ean13</field>
<field name="pattern">23.....{NNNDD}</field>
</record>
<!-- Backport Note : come from stock V9.0 module -->
<record id="stock.barcode_rule_weight_three_dec" model="barcode.rule">
<field name="name">Weight Barcodes 3 Decimals</field>
<field name="barcode_nomenclature_id" ref="default_barcode_nomenclature"/>
<field name="sequence">36</field>
<field name="type">weight</field>
<field name="encoding">ean13</field>
<field name="pattern">21.....{NNDDD}</field>
</record>
<record id="stock.barcode_rule_package" model="barcode.rule">
<field name="name">Package barcodes</field>
<field name="barcode_nomenclature_id" ref="default_barcode_nomenclature"/>
<field name="sequence">70</field>
<field name="type">package</field>
<field name="encoding">any</field>
<field name="pattern">PACK</field>
</record>
<record id="stock.barcode_rule_lot" model="barcode.rule">
<field name="name">Lot barcodes</field>
<field name="barcode_nomenclature_id" ref="default_barcode_nomenclature"/>
<field name="sequence">80</field>
<field name="type">lot</field>
<field name="encoding">any</field>
<field name="pattern">10</field>
</record>
<record id="stock.barcode_rule_location" model="barcode.rule">
<field name="name">Location barcodes</field>
<field name="barcode_nomenclature_id" ref="default_barcode_nomenclature"/>
<field name="sequence">60</field>
<field name="type">location</field>
<field name="encoding">any</field>
<field name="pattern">414</field>
</record>
</data>
</openerp>

2
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

BIN
barcodes/static/src/description/barcode_nomenclature.png

After

Width: 1075  |  Height: 487  |  Size: 67 KiB

Loading…
Cancel
Save