← Back to team overview

openerp-dev-web team mailing list archive

[Merge] lp:~openerp-dev/openobject-addons/trunk-bug-771377-ron into lp:openobject-addons

 

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

Requested reviews:
  Rucha (Open ERP) (rpa-openerp)
Related bugs:
  Bug #771377 in OpenERP Addons: "Splitting moves doesn't warn if lot contains insufficient quantity of product"
  https://bugs.launchpad.net/openobject-addons/+bug/771377

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-bug-771377-ron/+merge/59921

stock:Splitting moves doesn't warn if lot contains insufficient quantity of product
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-bug-771377-ron/+merge/59921
Your team OpenERP R&D Team is subscribed to branch lp:~openerp-dev/openobject-addons/trunk-bug-771377-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-05-04 13:24:26 +0000
@@ -20,6 +20,7 @@
 ##############################################################################
 
 from osv import fields, osv
+from tools.translate import _
 
 import decimal_precision as dp
 
@@ -280,7 +281,6 @@
                             '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 = {}
@@ -306,6 +306,25 @@
     _defaults = {
         'quantity': 1.0,
     }
+    
+    def onchange_lot_id(self, cr, uid, ids, prodlot_id=False, product_id=False, 
+                        product_qty=False, uom_id=False, context=None):
+        if not prodlot_id or not product_id:
+            return {}
+        prodlot_obj = self.pool.get('stock.production.lot')
+        product_obj = self.pool.get('product.product')
+        uom_obj = self.pool.get('product.uom')
+        uom = uom_obj.browse(cr, uid, uom_id, context=context)
+        product_uom = product_obj.browse(cr, uid, product_id, context=context).uom_id
+        warning = {}
+        lot_avail_qty = prodlot_obj.browse(cr, uid, prodlot_id, context=context)
+        quantity = uom_obj._compute_qty_obj(cr, uid, product_uom, lot_avail_qty.stock_available, uom, context=context)
+        if product_qty > quantity:
+            warning = {
+                        'title': _('Insufficient Stock in Lot !'),
+                        'message': _('You are moving %.2f %s products but only %.2f %s available in this lot.') % (product_qty, uom.name, quantity, uom.name)
+                        }
+        return {'warning': warning}
 
 stock_move_split_lines_exist()
 

=== 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-05-04 13:24:26 +0000
@@ -134,12 +134,12 @@
                   <group colspan="4" attrs="{'invisible':[('use_exist','!=',True)]}">
                         <field name="line_exist_ids" colspan="4" nolabel="1">
                             <tree string="Production Lot Numbers" editable="bottom">
-                                <field name="prodlot_id" string="Lot number" domain="[('product_id','=',parent.product_id)]"/>
-                                <field name="quantity" />
+                                <field name="prodlot_id" string="Lot number" on_change="onchange_lot_id(prodlot_id, parent.product_id, quantity, parent.product_uom)" domain="[('product_id','=',parent.product_id)]"/>
+                                <field name="quantity" on_change="onchange_lot_id(prodlot_id, parent.product_id, quantity, parent.product_uom)"/>
                             </tree>
                             <form string="Production Lot Number">
-                                <field name="prodlot_id" string="Lot number" domain="[('product_id','=',parent.product_id)]"/>
-                                <field name="quantity" />
+                                <field name="prodlot_id" string="Lot number" on_change="onchange_lot_id(prodlot_id, product_id, quantity, parent.product_uom)" domain="[('product_id','=',parent.product_id)]"/>
+                                <field name="quantity" on_change="onchange_lot_id(prodlot_id, parent.product_id, quantity, parent.product_uom)"/>
                             </form>
                         </field>
                     </group>


Follow ups