{
- 'name': 'Advanced Barcodes',
+ 'name': 'Barcodes',
'version': '1.0',
'category': '',
'sequence': 6,
_name = 'barcode.nomenclature'
_columns = {
'name': fields.char('Nomenclature Name', size=32, required=True, help='An internal identification of the barcode nomenclature'),
- #'convert_to_ean13': fields.boolean('Convert to EAN-13',help='Numerical Barcodes shorter than EAN-13 will be automatically converted to EAN-13'),
'rule_ids': fields.one2many('barcode.rule','barcode_nomenclature_id','Rules', help='The list of barcode rules'),
}
'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([('any','Any'),('ean13','EAN-13'),('ean8','EAN-8'),('codabar','Codabar'),('upca','UPC-A'),('upce','UPC-E')],'Encoding',help='This rule will apply only if the barcode is encoded with the specified encoding'),
'encoding': fields.selection([('any','Any'),('ean13','EAN-13')],'Encoding',required=True,help='This rule will apply only if the barcode is encoded with the specified encoding'),
'type': fields.selection([('alias','Alias'),('product','Unit Product')],'Type', required=True),
'pattern': fields.char('Barcode Pattern', size=32, help="The barcode matching pattern"),
- 'alias': fields.char('Alias',size=32,help='The matched pattern will alias to this barcode'),
+ 'alias': fields.char('Alias',size=32,help='The matched pattern will alias to this barcode',required=True),
}
_defaults = {
'type': 'product',
'pattern': '*',
'encoding': 'any',
+ 'alias': "0",
}
<group col="4">
<field name="name" />
<field name="sequence" />
- <field name="type" />
- <field name="encoding"/>
+ <field name="type"/>
+ <field name="encoding" attrs="{'invisible': [('type','=', 'alias')]}"/>
<field name="pattern" />
<field name="alias" attrs="{'invisible': [('type','!=', 'alias')]}"/>
</group>
-function openerp_barcode_parser(instance,module){
+openerp.barcodes = function(instance) {
+ "use strict";
+
+ instance.barcodes = {};
+ var module = instance.barcodes;
module.BarcodeParser = instance.web.Class.extend({
init: function(attributes) {
var self = this;
this.nomenclature_id = attributes.nomenclature_id;
- this.load_server_data();
+ this.loaded = this.load_server_data();
+ },
+
+ is_loaded: function() {
+ return self.loaded;
},
models: [
+++ /dev/null
-
-openerp.barcodes = function(instance) {
- "use strict";
-
- instance.barcode_parser = {};
- var module = instance.barcode_parser;
-
- openerp_barcode_parser(instance,module); // import barcodes.js
-};
<template id="assets_backend" name="barcodes assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/barcodes/static/src/js/barcode_parser.js"></script>
- <script type="text/javascript" src="/barcodes/static/src/js/main.js"></script>
</xpath>
</template>
this.product_by_id = {};
this.product_by_barcode = {};
this.product_by_category_id = {};
- //this.product_by_reference = {};
this.partner_sorted = [];
this.partner_by_id = {};
if(product.barcode){
this.product_by_barcode[product.barcode] = product;
}
- /*if(product.default_code){
- this.product_by_reference[product.default_code] = product;
- }*/
}
},
add_packagings: function(packagings){
if(this.product_by_barcode[barcode]){
return this.product_by_barcode[barcode];
}
- var pack = this.packagings_by_barcode<[barcode];
+ var pack = this.packagings_by_barcode[barcode];
if(pack){
return this.product_by_id[pack.product_tmpl_id[0]];
}
return undefined;
},
- /*get_product_by_reference: function(ref){
- return this.product_by_reference[ref];
- },*/
get_product_by_category: function(category_id){
var product_ids = this.product_by_category_id[category_id];
var list = [];
},
scan: function(code){
- if(this.barcode_parser) {
- var parsed_result = this.barcode_parser.parse_barcode(code);
- }
- else{
- console.error("Barcode Parser not yet initialized!");
- }
+ var parsed_result = this.barcode_parser.parse_barcode(code);
+
if(parsed_result.type in {'product':'', 'weight':'', 'price':''}){ //barcode is associated to a product
if(this.action_callback['product']){
this.action_callback['product'](parsed_result);
}
}
- else{
+ else if (parsed_result.type in {'cashier':'', 'client':''}){
if(this.action_callback[parsed_result.type]){
this.action_callback[parsed_result.type](parsed_result);
}
}
+ else{
+ this.action_callback['error'](parsed_result);
+ }
},
// starts catching keyboard events and tries to interpret codebar
var QWeb = instance.web.qweb;
var _t = instance.web._t;
- var barcode_parser_module = instance.barcode_parser;
+ var barcode_parser_module = instance.barcodes;
var round_di = instance.web.round_decimals;
var round_pr = instance.web.round_precision
// when all the data has loaded, we compute some stuff, and declare the Pos ready to be used.
this.ready = this.load_server_data()
.then(function(){
- var barcode_parser = new barcode_parser_module.BarcodeParser({'nomenclature_id': self.config.barcode_nomenclature_id});
- self.barcode_reader.set_barcode_parser(barcode_parser);
-
if(self.config.use_proxy){
return self.connect_to_proxy();
}
return logo_loaded;
},
- },
+ }, {
+ label: 'barcodes',
+ loaded: function(self) {
+ var barcode_parser = new barcode_parser_module.BarcodeParser({'nomenclature_id': self.config.barcode_nomenclature_id});
+ self.barcode_reader.set_barcode_parser(barcode_parser);
+ return barcode_parser.is_loaded();
+ },
+ }
],
// loads all the needed data on the sever. returns a deferred indicating when all the data has loaded.
scan_product: function(parsed_code){
var self = this;
var selectedOrder = this.get_order();
- //if(parsed_code.encoding === 'barcode'){
- var product = this.db.get_product_by_barcode(parsed_code.base_code);
- /*}else if(parsed_code.encoding === 'reference'){
- var product = this.db.get_product_by_reference(parsed_code.code);
- }*/
+ var product = this.db.get_product_by_barcode(parsed_code.base_code);
if(!product){
return false;
last_orderline.set_discount(code.value)
}
},
- // What happens when an alias barcode is scanned, but the barcode referenced
- // in the alias finds no match : shows an error popup.
- barcode_alias_action: function(code){
- this.pos_widget.screen_selector.show_popup('error-alias-barcode',code);
- },
// What happens when an invalid barcode is scanned : shows an error popup.
barcode_error_action: function(code){
this.pos_widget.screen_selector.show_popup('error-barcode',code.code);
'product': self.barcode_product_action ? function(code){ self.barcode_product_action(code); } : undefined ,
'client' : self.barcode_client_action ? function(code){ self.barcode_client_action(code); } : undefined ,
'discount': self.barcode_discount_action ? function(code){ self.barcode_discount_action(code); } : undefined,
- 'alias': self.barcode_alias_action ? function(code){ self.barcode_alias_action(code); } : undefined,
'error' : self.barcode_error_action ? function(code){ self.barcode_error_action(code); } : undefined,
});
},
template:'ErrorTracebackPopupWidget',
});
- module.ErrorAliasBarcodePopupWidget = module.ErrorPopupWidget.extend({
- template:'ErrorAliasBarcodePopupWidget',
- show: function(barcode){
- this.barcode = barcode.code;
- this.alias = barcode.base_code;
- this._super();
- },
- });
-
module.ErrorBarcodePopupWidget = module.ErrorPopupWidget.extend({
template:'ErrorBarcodePopupWidget',
show: function(barcode){
this.error_barcode_popup = new module.ErrorBarcodePopupWidget(this, {});
this.error_barcode_popup.appendTo(this.$el);
- this.error_alias_barcode_popup = new module.ErrorAliasBarcodePopupWidget(this, {});
- this.error_alias_barcode_popup.appendTo(this.$el);
-
this.error_traceback_popup = new module.ErrorTracebackPopupWidget(this,{});
this.error_traceback_popup.appendTo(this.$el);
popup_set:{
'error': this.error_popup,
'error-barcode': this.error_barcode_popup,
- 'error-alias-barcode': this.error_alias_barcode_popup,
'error-traceback': this.error_traceback_popup,
'textinput': this.textinput_popup,
'textarea': this.textarea_popup,
</div>
</t>
- <t t-name="ErrorAliasBarcodePopupWidget">
- <div class="modal-dialog">
- <div class="popup popup-barcode">
- <p class="message">Unknown Barcode
- <br />
- <span class='barcode'><t t-esc="widget.barcode" /></span>
- </p>
- <p class="comment">
- The Point of Sale could not find any product, client, employee
- or action associated with the scanned alias <t t-esc="widget.alias" />.
- </p>
- <div class="footer">
- <div class="button">
- Ok
- </div>
- </div>
- </div>
- </div>
- </t>
-
<t t-name="ConfirmPopupWidget">
<div class="modal-dialog">
<div class="popup popup-confirm">
check = int(10 - math.ceil(total % 10.0)) %10
return check
-# def check_ean(eancode):
-# """returns True if eancode is a valid ean13 string, or null"""
-# if not eancode:
-# return True
-# if len(eancode) != 13:
-# return False
-# try:
-# int(eancode)
-# except:
-# return False
-# return ean_checksum(eancode) == int(eancode[-1])
-
def sanitize_ean13(ean13):
"""Creates and returns a valid ean13 from an invalid one"""
if not ean13:
help='The weight of a full package, pallet or box.'),
}
- # def _check_ean_key(self, cr, uid, ids, context=None):
- # for pack in self.browse(cr, uid, ids, context=context):
- # if not check_ean(pack.ean):
- # return False
- # return True
-
- # _constraints = [(_check_ean_key, 'Error: Invalid ean code', ['ean'])]
-
def name_get(self, cr, uid, ids, context=None):
if not len(ids):
return []
answer = {'filter_loc': False, 'operation_id': False}
# Barcode Nomenclatures
+ #this_picking ==? self
this_picking = self.search(cr, uid, [('id', '=', picking_id)], context=context)
- rec = self.browse(cr, uid, this_picking, context=context)
- if not rec:
- return answer # TODO: return specific error?
- else:
- barcode_nom = rec.barcode_nomenclature_id
+ #this_picking = self.read(cr, uid, picking_id, context=context)
+ rec = self.browse(cr, uid, self, context=context)
+ barcode_nom = rec.barcode_nomenclature_id
parsed_result = barcode_nom.parse_barcode(barcode_str)
#check if the barcode is a weighted barcode or simply a product
return {'value': {'country_id': state.country_id.id}}
return {}
- # def _check_ean_key(self, cr, uid, ids, context=None):
- # for partner_o in self.pool['res.partner'].read(cr, uid, ids, ['barcode',]):
- # thisean=partner_o['barcode']
- # if thisean and thisean!='':
- # if len(thisean)!=13:
- # return False
- # sum=0
- # for i in range(12):
- # if not (i % 2):
- # sum+=int(thisean[i])
- # else:
- # sum+=3*int(thisean[i])
- # if math.ceil(sum/10.0)*10-sum!=int(thisean[12]):
- # return False
- # return True
-
-# _constraints = [(_check_ean_key, 'Error: Invalid ean code', ['ean13'])]
-
def _update_fields_values(self, cr, uid, partner, fields, context=None):
""" Returns dict of write() values for synchronizing ``fields`` """
values = {}