[FIX] barcodes,point_of_sale,stock,base: minor changes from code review
authorAaron Bohy <aab@odoo.com>
Thu, 13 Nov 2014 08:50:25 +0000 (09:50 +0100)
committerFrédéric van der Essen <fvdessen@gmail.com>
Wed, 26 Nov 2014 11:06:21 +0000 (12:06 +0100)
15 files changed:
addons/barcodes/__openerp__.py
addons/barcodes/barcodes.py
addons/barcodes/barcodes_view.xml
addons/barcodes/static/src/js/barcode_parser.js
addons/barcodes/static/src/js/main.js [deleted file]
addons/barcodes/views/templates.xml
addons/point_of_sale/static/src/js/db.js
addons/point_of_sale/static/src/js/devices.js
addons/point_of_sale/static/src/js/models.js
addons/point_of_sale/static/src/js/screens.js
addons/point_of_sale/static/src/js/widgets.js
addons/point_of_sale/static/src/xml/pos.xml
addons/product/product.py
addons/stock/stock.py
openerp/addons/base/res/res_partner.py

index 53a4773..c4a74f3 100644 (file)
@@ -21,7 +21,7 @@
 
 
 {
-    'name': 'Advanced Barcodes',
+    'name': 'Barcodes',
     'version': '1.0',
     'category': '',
     'sequence': 6,
index ab0e7ba..4f19240 100644 (file)
@@ -33,7 +33,6 @@ class barcode_nomenclature(osv.osv):
     _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'),
     }
 
@@ -166,15 +165,15 @@ class barcode_rule(models.Model):
         '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",
     }
index efc9404..e799ab4 100644 (file)
@@ -58,8 +58,8 @@
                     <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>
index e3b9ae3..8a8c2ff 100644 (file)
@@ -1,10 +1,18 @@
-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: [
diff --git a/addons/barcodes/static/src/js/main.js b/addons/barcodes/static/src/js/main.js
deleted file mode 100644 (file)
index 69e702e..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-
-openerp.barcodes = function(instance) {
-    "use strict";
-
-    instance.barcode_parser = {};
-    var module = instance.barcode_parser;
-
-    openerp_barcode_parser(instance,module);         // import barcodes.js
-};
index 965eab7..9e255e5 100644 (file)
@@ -7,7 +7,6 @@
        <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>
 
index 2711dbc..8447362 100644 (file)
@@ -24,7 +24,6 @@ function openerp_pos_db(instance, module){
             this.product_by_id = {};
             this.product_by_barcode = {};
             this.product_by_category_id = {};
-            //this.product_by_reference = {};
 
             this.partner_sorted = [];
             this.partner_by_id = {};
@@ -212,9 +211,6 @@ function openerp_pos_db(instance, module){
                 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){
@@ -359,15 +355,12 @@ function openerp_pos_db(instance, module){
             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 = [];
index 7ca14d1..4e2cce1 100644 (file)
@@ -508,22 +508,21 @@ function openerp_pos_devices(instance,module){ //module is instance.point_of_sal
         },
 
         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 
index 39415f5..b88f82f 100644 (file)
@@ -3,7 +3,7 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal
 
     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
@@ -80,9 +80,6 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal
             // 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();
                     }
@@ -368,7 +365,14 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal
 
                 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. 
@@ -695,11 +699,7 @@ function openerp_pos_models(instance, module){ //module is instance.point_of_sal
         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;
index 9d3b996..831bdf3 100644 (file)
@@ -212,11 +212,6 @@ function openerp_pos_screens(instance, module){ //module is instance.point_of_sa
                 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);
@@ -243,7 +238,6 @@ function openerp_pos_screens(instance, module){ //module is instance.point_of_sa
                 '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,
             });
         },
@@ -351,15 +345,6 @@ function openerp_pos_screens(instance, module){ //module is instance.point_of_sa
         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){
index f47ebb5..ae46906 100644 (file)
@@ -1025,9 +1025,6 @@ function openerp_pos_widgets(instance, module){ //module is instance.point_of_sa
             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);
 
@@ -1118,7 +1115,6 @@ function openerp_pos_widgets(instance, module){ //module is instance.point_of_sa
                 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,
index 898c56b..146b8a1 100644 (file)
         </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">
index f20ad81..23684bf 100644 (file)
@@ -55,18 +55,6 @@ def ean_checksum(eancode):
     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:
@@ -1177,14 +1165,6 @@ class product_packaging(osv.osv):
             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 []
index bfc214c..e02767b 100644 (file)
@@ -1452,12 +1452,11 @@ class stock_picking(osv.osv):
         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
index 45e35b5..90e6763 100644 (file)
@@ -395,24 +395,6 @@ class res_partner(osv.Model, format_address):
             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 = {}