Rohan Nayani(Open ERP) has proposed merging 
lp:~openerp-dev/openobject-addons/trunk-bug-776245-ron into 
lp:openobject-addons.

Requested reviews:
  Rohan Nayani(Open ERP) (ron-tinyerp)
  Rucha (Open ERP) (rpa-openerp)
Related bugs:
  Bug #776245 in OpenERP Addons: "stock: when splitting incoming shipments, 
system allows to split lots in more than the total quantity, without warning"
  https://bugs.launchpad.net/openobject-addons/+bug/776245

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-bug-776245-ron/+merge/61725
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-bug-776245-ron/+merge/61725
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-addons/trunk-bug-776245-ron.
=== modified file 'stock/wizard/stock_move.py'
--- stock/wizard/stock_move.py	2011-05-02 18:46:43 +0000
+++ stock/wizard/stock_move.py	2011-06-13 12:41:38 +0000
@@ -20,6 +20,7 @@
 ##############################################################################
 
 from osv import fields, osv
+from tools.translate import _
 
 import decimal_precision as dp
 
@@ -169,6 +170,58 @@
 
 stock_move_scrap()
 
+class stock_move_split_message(osv.osv_memory):
+    _name = "stock.move.split.message"
+    _description = "You are spliting more quantity then order its give warning"
+
+    def default_get(self, cr, uid, fields, context=None):
+        """ Get default values
+        @param self: The object pointer.
+        @param cr: A database cursor
+        @param uid: ID of the user currently logged in
+        @param fields: List of fields for default value
+        @param context: A standard dictionary
+        @return: Default values of fields
+        """
+        if context is None:
+            context = {}
+        res ={}
+        if context.get('active_id'):
+            split_qty = 0.0
+            move = self.pool.get('stock.move').browse(cr, uid, context['active_id'], context=context)
+            uom = self.pool.get('product.uom').browse(cr, uid, move.product_uom.id, context=context).name
+            if context.get('line'):
+                for qty in context.get('line'):
+                    split_qty += qty['quantity']
+                if 'message' in fields:
+                    res.update({'message': _('Warning ! \nYou are spliting %.2f %s but you have only %.2f %s in this order. If you continue, your information will be lost.') %(split_qty, uom, move.product_qty, uom)})
+        return res
+
+    _columns = {
+        'message' : fields.text('Message', size=64, readonly=True),
+     }
+
+    def continue_split(self, cr, uid, ids, context=None):
+        if context is None:
+            context = {}
+        split_obj = self.pool.get('stock.move.split')
+        split_obj.split(cr, uid, ids, context.get('active_ids'), context=context)
+        return {'type': 'ir.actions.act_window_close'}
+
+    def back_split(self,cr, uid, ids, context=None):
+        if context is None:
+            context = {}
+        return {
+            'view_type': 'form',
+            'view_mode': 'form',
+            'res_model': 'stock.move.split',
+            'type': 'ir.actions.act_window',
+            'target': 'new',
+            'context': context
+               }
+    
+stock_move_split_message()
+
 
 class split_in_production_lot(osv.osv_memory):
     _name = "stock.move.split"
@@ -185,10 +238,10 @@
         """
         if context is None:
             context = {}
-
         res = super(split_in_production_lot, self).default_get(cr, uid, fields, context=context)
         if context.get('active_id'):
             move = self.pool.get('stock.move').browse(cr, uid, context['active_id'], context=context)
+            uom = self.pool.get('product.uom').browse(cr, uid, move.product_uom.id, context=context).name
             if 'product_id' in fields:
                 res.update({'product_id': move.product_id.id})
             if 'product_uom' in fields:
@@ -197,6 +250,11 @@
                 res.update({'qty': move.product_qty})
             if 'use_exist' in fields:
                 res.update({'use_exist': (move.picking_id and move.picking_id.type=='out' and True) or False})
+            if context.get('line'):
+                if 'line_ids' in fields:
+                    res.update({'line_ids': (context.get('line')) or False})
+                if ('use_exist_true' in context['line'][0].keys()) and ('line_exist_ids' in fields):
+                        res.update({'use_exist': True, 'line_exist_ids': (context.get('line')) or False})
         return res
 
     _columns = {
@@ -208,6 +266,63 @@
         'use_exist' : fields.boolean('Existing Lots', help="Check this option to select existing lots in the list below, otherwise you should enter new ones line by line."),
      }
 
+    def get_split_line(self, cr, uid, ids, data, context=None):
+        """ 
+        @param self: The object pointer.
+        @param cr: A database cursor
+        @param uid: ID of the user currently logged in
+        @param ids: An ID or list of IDs if we want more than one
+        @param data: data of current object
+        @param context: A standard dictionary
+        @return: wizard move lines:
+        """
+        if context is None:
+            context = {}
+        if data.use_exist:
+            lines = [l for l in data.line_exist_ids if l]
+        else:
+            lines = [l for l in data.line_ids if l]
+        return lines
+
+    def lot_check_qty(self, cr, uid, ids, context=None):
+        """ To split a lot
+        @param self: The object pointer.
+        @param cr: A database cursor
+        @param uid: ID of the user currently logged in
+        @param ids: An ID or list of IDs if we want more than one
+        @param context: A standard dictionary
+        @return:if  splitting Quantity bigger then order Quantity Its gives warning
+        """
+
+        if context is None:
+            context = {}
+        move_obj = self.pool.get('stock.move')
+        mod_obj = self.pool.get('ir.model.data')
+        model_data_ids = mod_obj.search(cr, uid,[('model','=','ir.ui.view'),('name','=','view_stock_track_lot_wizard')], context=context)
+        resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']
+        track_qty = 0.0
+        result = []
+        for data in self.browse(cr, uid, ids, context=context):
+            for move in move_obj.browse(cr, uid, context.get('active_ids'), context=context):
+                lines = self.get_split_line(cr, uid, ids, data, context=context)
+        for line in lines:
+            track_qty += line.quantity
+            if data.use_exist:
+                result.append({'quantity':line.quantity, 'prodlot_id':line.prodlot_id.id, 'use_exist_true': True})
+            else:
+                result.append({'quantity':line.quantity, 'name':line.name})
+        if track_qty > move.product_qty:
+            context.update({'line': result})
+            return {
+                'view_type': 'form',
+                'view_mode': 'form',
+                'res_model': 'stock.move.split.message',
+                'views': [(resource_id,'form')],
+                'type': 'ir.actions.act_window',
+                'target': 'new',
+                'context': context
+            }
+        
     def split_lot(self, cr, uid, ids, context=None):
         """ To split a lot
         @param self: The object pointer.
@@ -217,8 +332,12 @@
         @param context: A standard dictionary
         @return:
         """
+        res = {}
         if context is None:
             context = {}
+        res = self.lot_check_qty(cr, uid, ids, context=context)
+        if res:
+            return res
         self.split(cr, uid, ids, context.get('active_ids'), context=context)
         return {'type': 'ir.actions.act_window_close'}
 
@@ -245,10 +364,7 @@
                 quantity_rest = move.product_qty
                 uos_qty_rest = move.product_uos_qty
                 new_move = []
-                if data.use_exist:
-                    lines = [l for l in data.line_exist_ids if l]
-                else:
-                    lines = [l for l in data.line_ids if l]
+                lines = self.get_split_line(cr, uid, ids, data, context=context)
                 for line in lines:
                     quantity = line.quantity
                     if quantity <= 0 or move_qty == 0:
@@ -269,7 +385,6 @@
                         if inventory_id and current_move:
                             inventory_obj.write(cr, uid, inventory_id, {'move_ids': [(4, current_move)]}, context=context)
                         new_move.append(current_move)
-
                     if quantity_rest == 0:
                         current_move = move.id
                     prodlot_id = False
@@ -280,9 +395,7 @@
                             'name': line.name,
                             'product_id': move.product_id.id},
                         context=context)
-
                     move_obj.write(cr, uid, [current_move], {'prodlot_id': prodlot_id, 'state':move.state})
-
                     update_val = {}
                     if quantity_rest > 0:
                         update_val['product_qty'] = quantity_rest
@@ -323,4 +436,5 @@
         'quantity': 1.00,
         'action' : 'split',
     }
+
 stock_move_split_lines()

=== modified file 'stock/wizard/stock_move_view.xml'
--- stock/wizard/stock_move_view.xml	2011-03-14 10:27:42 +0000
+++ stock/wizard/stock_move_view.xml	2011-06-13 12:41:38 +0000
@@ -163,5 +163,21 @@
 	            <field name="target">new</field>
 	        </record>
 
+        <record id="view_stock_track_lot_wizard" model="ir.ui.view">
+                <field name="name">Tracking a lot</field>
+                <field name="model">stock.move.split.message</field>
+                <field name="type">form</field>
+                <field name="arch" type="xml">
+                    <form string="Tracking a lot">
+                    <newline/>
+                    <field colspan="4" name="message" nolabel="1" width="450" height="50"/>
+                        <newline/>
+                        <separator string="" colspan="4" />
+                        <button name="back_split"  string="Back" type="object" icon="gtk-go-back"/>
+                        <button name="continue_split" string="Continue" colspan="1" type="object" icon="terp-camera_test"/>
+                    </form>
+                </field>
+            </record>
+
 	</data>
 </openerp>

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to