From 40549064c699592c776871f401772c18f438b603 Mon Sep 17 00:00:00 2001 From: Cedric Snauwaert Date: Mon, 28 Apr 2014 12:12:26 +0200 Subject: [PATCH] [FIX]barcode interface: allow user to choose name of lot when creating a lot bzr revid: csn@openerp.com-20140428101226-4d7kcaq29d3ofgqm --- addons/stock/static/src/js/widgets.js | 28 ++++++++++++++++++++++--- addons/stock/static/src/xml/picking.xml | 19 +++++++++++++++++ addons/stock/stock.py | 7 +++++-- 3 files changed, 49 insertions(+), 5 deletions(-) diff --git a/addons/stock/static/src/js/widgets.js b/addons/stock/static/src/js/widgets.js index 6a770a777b3..3274924c581 100644 --- a/addons/stock/static/src/js/widgets.js +++ b/addons/stock/static/src/js/widgets.js @@ -193,7 +193,29 @@ function openerp_picking_widgets(instance){ }); this.$('.js_create_lot').click(function(){ var op_id = $(this).parents("[data-id]:first").data('id'); - self.getParent().create_lot(op_id); + var lot_name = false; + self.$('.js_lot_scan').val(''); + var $lot_modal = self.$el.siblings('#js_LotChooseModal'); + self.getParent().barcode_scanner.disconnect(); + $lot_modal.modal() + //focus input + $lot_modal.on('shown.bs.modal', function(){ + self.$('.js_lot_scan').focus(); + }) + self.$('.js_lot_scan').focus(); + //button action + self.$('.js_validate_lot').click(function(){ + //get content of input + var name = self.$('.js_lot_scan').val(); + if (name.length !== 0){ + lot_name = name; + } + self.getParent().barcode_scanner.connect(function(ean){ + self.getParent().scan(ean); + }); + $lot_modal.modal('hide'); + self.getParent().create_lot(op_id, lot_name); + }); }); this.$('.js_delete_pack').click(function(){ var pack_id = $(this).parents("[data-id]:first").data('id'); @@ -846,10 +868,10 @@ function openerp_picking_widgets(instance){ } }); }, - create_lot: function(op_id){ + create_lot: function(op_id, lot_name){ var self = this; new instance.web.Model('stock.pack.operation') - .call('create_and_assign_lot',[parseInt(op_id)]) + .call('create_and_assign_lot',[parseInt(op_id), lot_name]) .then(function(){ return self.refresh_ui(self.picking.id); }); diff --git a/addons/stock/static/src/xml/picking.xml b/addons/stock/static/src/xml/picking.xml index 5bca5221ff8..8bc25b51d96 100644 --- a/addons/stock/static/src/xml/picking.xml +++ b/addons/stock/static/src/xml/picking.xml @@ -27,6 +27,25 @@ + +
diff --git a/addons/stock/stock.py b/addons/stock/stock.py index 6eea4d3e432..b8169513a4d 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -3746,13 +3746,16 @@ class stock_pack_operation(osv.osv): processed_ids.append(op) self.write(cr, uid, processed_ids, {'processed': 'true'}, context=context) - def create_and_assign_lot(self, cr, uid, id, context=None): + def create_and_assign_lot(self, cr, uid, id, name, context=None): ''' Used by barcode interface to create a new lot and assign it to the operation ''' obj = self.browse(cr,uid,id,context) product_id = obj.product_id.id + val = {'product_id': product_id} + if name: + val.update({'name': name}) if not obj.lot_id: - new_lot_id = self.pool.get('stock.production.lot').create(cr, uid, {'product_id': product_id}, context=context) + new_lot_id = self.pool.get('stock.production.lot').create(cr, uid, val, context=context) self.write(cr, uid, id, {'lot_id': new_lot_id}, context=context) def _search_and_increment(self, cr, uid, picking_id, domain, filter_visible=False ,visible_op_ids=False, increment=True, context=None):