diff options
| author | Aaron Bohy <aab@odoo.com> | 2014-11-13 09:50:25 +0100 |
|---|---|---|
| committer | Frédéric van der Essen <fvdessen@gmail.com> | 2014-11-26 12:06:21 +0100 |
| commit | 84c743dd40b473f9334dc22d4f2802a274abccbd (patch) | |
| tree | 9ef28f8133f6e31b2720ba259ef246ea8618eb38 | |
| parent | 956faa62f74035733da52c9c479013653ab66ccd (diff) | |
[FIX] barcodes,point_of_sale,stock,base: minor changes from code review
| -rw-r--r-- | addons/barcodes/__openerp__.py | 2 | ||||
| -rw-r--r-- | addons/barcodes/barcodes.py | 5 | ||||
| -rw-r--r-- | addons/barcodes/barcodes_view.xml | 4 | ||||
| -rw-r--r-- | addons/barcodes/static/src/js/barcode_parser.js | 12 | ||||
| -rw-r--r-- | addons/barcodes/static/src/js/main.js | 9 | ||||
| -rw-r--r-- | addons/barcodes/views/templates.xml | 1 | ||||
| -rw-r--r-- | addons/point_of_sale/static/src/js/db.js | 9 | ||||
| -rw-r--r-- | addons/point_of_sale/static/src/js/devices.js | 13 | ||||
| -rw-r--r-- | addons/point_of_sale/static/src/js/models.js | 20 | ||||
| -rw-r--r-- | addons/point_of_sale/static/src/js/screens.js | 15 | ||||
| -rw-r--r-- | addons/point_of_sale/static/src/js/widgets.js | 4 | ||||
| -rw-r--r-- | addons/point_of_sale/static/src/xml/pos.xml | 20 | ||||
| -rw-r--r-- | addons/product/product.py | 20 | ||||
| -rw-r--r-- | addons/stock/stock.py | 9 | ||||
| -rw-r--r-- | openerp/addons/base/res/res_partner.py | 18 |
15 files changed, 36 insertions, 125 deletions
diff --git a/addons/barcodes/__openerp__.py b/addons/barcodes/__openerp__.py index 53a4773b65f..c4a74f38037 100644 --- a/addons/barcodes/__openerp__.py +++ b/addons/barcodes/__openerp__.py @@ -21,7 +21,7 @@ { - 'name': 'Advanced Barcodes', + 'name': 'Barcodes', 'version': '1.0', 'category': '', 'sequence': 6, diff --git a/addons/barcodes/barcodes.py b/addons/barcodes/barcodes.py index ab0e7bac6ab..4f192403501 100644 --- a/addons/barcodes/barcodes.py +++ b/addons/barcodes/barcodes.py @@ -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", } diff --git a/addons/barcodes/barcodes_view.xml b/addons/barcodes/barcodes_view.xml index efc940475de..e799ab43563 100644 --- a/addons/barcodes/barcodes_view.xml +++ b/addons/barcodes/barcodes_view.xml @@ -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> diff --git a/addons/barcodes/static/src/js/barcode_parser.js b/addons/barcodes/static/src/js/barcode_parser.js index e3b9ae3fd4e..8a8c2ff5399 100644 --- a/addons/barcodes/static/src/js/barcode_parser.js +++ b/addons/barcodes/static/src/js/barcode_parser.js @@ -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 index 69e702ebe74..00000000000 --- a/addons/barcodes/static/src/js/main.js +++ /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 -}; diff --git a/addons/barcodes/views/templates.xml b/addons/barcodes/views/templates.xml index 965eab7e221..9e255e57290 100644 --- a/addons/barcodes/views/templates.xml +++ b/addons/barcodes/views/templates.xml @@ -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> diff --git a/addons/point_of_sale/static/src/js/db.js b/addons/point_of_sale/static/src/js/db.js index 2711dbcf9f9..84473626b01 100644 --- a/addons/point_of_sale/static/src/js/db.js +++ b/addons/point_of_sale/static/src/js/db.js @@ -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 = []; diff --git a/addons/point_of_sale/static/src/js/devices.js b/addons/point_of_sale/static/src/js/devices.js index 7ca14d16be1..4e2cce1c0e9 100644 --- a/addons/point_of_sale/static/src/js/devices.js +++ b/addons/point_of_sale/static/src/js/devices.js @@ -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 diff --git a/addons/point_of_sale/static/src/js/models.js b/addons/point_of_sale/static/src/js/models.js index 39415f5fd99..b88f82faa20 100644 --- a/addons/point_of_sale/static/src/js/models.js +++ b/addons/point_of_sale/static/src/js/models.js @@ -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; diff --git a/addons/point_of_sale/static/src/js/screens.js b/addons/point_of_sale/static/src/js/screens.js index 9d3b99631e7..831bdf3b9e3 100644 --- a/addons/point_of_sale/static/src/js/screens.js +++ b/addons/point_of_sale/static/src/js/screens.js @@ -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){ diff --git a/addons/point_of_sale/static/src/js/widgets.js b/addons/point_of_sale/static/src/js/widgets.js index f47ebb57518..ae469060b3a 100644 --- a/addons/point_of_sale/static/src/js/widgets.js +++ b/addons/point_of_sale/static/src/js/widgets.js @@ -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, diff --git a/addons/point_of_sale/static/src/xml/pos.xml b/addons/point_of_sale/static/src/xml/pos.xml index 898c56b4e8d..146b8a1a9ae 100644 --- a/addons/point_of_sale/static/src/xml/pos.xml +++ b/addons/point_of_sale/static/src/xml/pos.xml @@ -912,26 +912,6 @@ </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"> diff --git a/addons/product/product.py b/addons/product/product.py index f20ad8154a7..23684bfa3b6 100644 --- a/addons/product/product.py +++ b/addons/product/product.py @@ -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 [] diff --git a/addons/stock/stock.py b/addons/stock/stock.py index bfc214c35a7..e02767b5cc1 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -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 diff --git a/openerp/addons/base/res/res_partner.py b/openerp/addons/base/res/res_partner.py index 45e35b5621d..90e6763acfe 100644 --- a/openerp/addons/base/res/res_partner.py +++ b/openerp/addons/base/res/res_partner.py @@ -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 = {} |
