[FIX]barcode interface: allow user to choose name of lot when creating a lot
authorCedric Snauwaert <csn@openerp.com>
Mon, 28 Apr 2014 10:12:26 +0000 (12:12 +0200)
committerCedric Snauwaert <csn@openerp.com>
Mon, 28 Apr 2014 10:12:26 +0000 (12:12 +0200)
bzr revid: csn@openerp.com-20140428101226-4d7kcaq29d3ofgqm

addons/stock/static/src/js/widgets.js
addons/stock/static/src/xml/picking.xml
addons/stock/stock.py

index 6a770a7..3274924 100644 (file)
@@ -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);
                 });
index 5bca522..8bc25b5 100644 (file)
             </div>
         </div>
 
+        <div class="modal fade" id="js_LotChooseModal" tabindex="-1" role="dialog" aria-labelledby="LotChooseModal" aria-hidden="true">
+            <div class="modal-dialog">
+                <div class="modal-content">
+                    <div class="modal-header">
+                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>
+                        <h4 class="modal-title" id="myModalLabel">Create Lot</h4>
+                    </div>
+                    <div class="modal-body">
+                        <p>Scan a lot or type it below (leave empty to generate one automatically)</p>
+                        <input class='col-xs-6 js_lot_scan' type='text'/>
+                    </div>
+                    <div class="modal-footer">
+                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
+                        <button type="button" class="btn btn-primary js_validate_lot">Create Lot</button>
+                    </div>
+                </div>
+            </div>
+        </div>        
+
         <div class="row">
                 <div>
                     <div class="col-sm-4 col-xs-6">
index 6eea4d3..b816951 100644 (file)
@@ -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):