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

Requested reviews:
  Rohan Nayani(Open ERP) (ron-tinyerp)
  qdp (OpenERP) (qdp)
  Rucha (Open ERP) (rpa-openerp)
Related bugs:
  Bug #751222 in OpenERP Addons: "[6.0 - trunk] partial stock move wizard bugs 
: uom, new lines, production lot attrs"
  https://bugs.launchpad.net/openobject-addons/+bug/751222

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

https://bugs.launchpad.net/openobject-addons/+bug/751222
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-bug-751222-ron/+merge/57112
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-addons/trunk-bug-751222-ron.
=== modified file 'stock/stock.py'
--- stock/stock.py	2011-11-15 09:50:27 +0000
+++ stock/stock.py	2011-11-16 12:38:29 +0000
@@ -1168,9 +1168,7 @@
         for pick in self.browse(cr, uid, ids, context=context):
             new_picking = None
             complete, too_many, too_few = [], [], []
-            move_product_qty = {}
-            prodlot_ids = {}
-            product_avail = {}
+            move_product_qty, prodlot_ids, product_avail, partial_qty, product_uoms = {}, {}, {}, {}, {}
             for move in pick.move_lines:
                 if move.state in ('done', 'cancel'):
                     continue
@@ -1182,9 +1180,11 @@
                 product_currency = partial_data.get('product_currency',False)
                 prodlot_id = partial_data.get('prodlot_id')
                 prodlot_ids[move.id] = prodlot_id
-                if move.product_qty == product_qty:
+                product_uoms[move.id] = product_uom
+                partial_qty[move.id] = uom_obj._compute_qty(cr, uid, product_uoms[move.id], product_qty, move.product_uom.id)
+                if move.product_qty == partial_qty[move.id]:
                     complete.append(move)
-                elif move.product_qty > product_qty:
+                elif move.product_qty > partial_qty[move.id]:
                     too_few.append(move)
                 else:
                     too_many.append(move)
@@ -1225,7 +1225,6 @@
 
             for move in too_few:
                 product_qty = move_product_qty[move.id]
-
                 if not new_picking:
                     new_picking = self.copy(cr, uid, pick.id,
                             {
@@ -1241,28 +1240,32 @@
                             'state': 'assigned',
                             'move_dest_id': False,
                             'price_unit': move.price_unit,
+                            'product_uom': product_uoms[move.id]
                     }
                     prodlot_id = prodlot_ids[move.id]
                     if prodlot_id:
                         defaults.update(prodlot_id=prodlot_id)
                     move_obj.copy(cr, uid, move.id, defaults)
-
                 move_obj.write(cr, uid, [move.id],
                         {
-                            'product_qty' : move.product_qty - product_qty,
-                            'product_uos_qty':move.product_qty - product_qty, #TODO: put correct uos_qty
+                            'product_qty' : move.product_qty - partial_qty[move.id],
+                            'product_uos_qty': move.product_qty - partial_qty[move.id], #TODO: put correct uos_qty
+                            
                         })
 
             if new_picking:
                 move_obj.write(cr, uid, [c.id for c in complete], {'picking_id': new_picking})
             for move in complete:
+                defaults = {'product_uom': product_uoms[move.id], 'product_qty': move_product_qty[move.id]}
                 if prodlot_ids.get(move.id):
-                    move_obj.write(cr, uid, [move.id], {'prodlot_id': prodlot_ids[move.id]})
+                    defaults.update({'prodlot_id': prodlot_ids[move.id]})
+                move_obj.write(cr, uid, [move.id], defaults)
             for move in too_many:
                 product_qty = move_product_qty[move.id]
                 defaults = {
                     'product_qty' : product_qty,
                     'product_uos_qty': product_qty, #TODO: put correct uos_qty
+                    'product_uom': product_uoms[move.id]
                 }
                 prodlot_id = prodlot_ids.get(move.id)
                 if prodlot_ids.get(move.id):
@@ -1271,7 +1274,6 @@
                     defaults.update(picking_id=new_picking)
                 move_obj.write(cr, uid, [move.id], defaults)
 
-
             # At first we confirm the new picking (if necessary)
             if new_picking:
                 wf_service.trg_validate(uid, 'stock.picking', new_picking, 'button_confirm', cr)

=== modified file 'stock/wizard/stock_partial_picking.py'
--- stock/wizard/stock_partial_picking.py	2011-11-09 18:12:56 +0000
+++ stock/wizard/stock_partial_picking.py	2011-11-16 12:38:29 +0000
@@ -22,12 +22,25 @@
 import time
 from osv import fields, osv
 from tools.misc import DEFAULT_SERVER_DATETIME_FORMAT
+from tools.translate import _
 
 class stock_partial_picking_line(osv.TransientModel):
+
+    def _tracking(self, cursor, user, ids, name, arg, context=None):
+        res = {}
+        for tracklot in self.browse(cursor, user, ids, context=context):
+            tracking = False
+            if (tracklot.move_id.picking_id.type == 'in' and tracklot.product_id.track_incoming == True) or \
+                (tracklot.move_id.picking_id.type == 'out' and tracklot.product_id.track_outgoing == True):
+                tracking = True
+            res[tracklot.id] = tracking
+        return res
+
+
     _name = "stock.partial.picking.line"
     _rec_name = 'product_id'
     _columns = {
-        'product_id' : fields.many2one('product.product', string="Product", required=True, ondelete='CASCADE'),
+        'product_id' : fields.many2one('product.product', string="Product", required=True, readonly=True, ondelete='CASCADE'),
         'quantity' : fields.float("Quantity", required=True),
         'product_uom': fields.many2one('product.uom', 'Unit of Measure', required=True, ondelete='CASCADE'),
         'prodlot_id' : fields.many2one('stock.production.lot', 'Production Lot', ondelete='CASCADE'),
@@ -38,6 +51,7 @@
         'update_cost': fields.boolean('Need cost update'),
         'cost' : fields.float("Cost", help="Unit Cost for this product line"),
         'currency' : fields.many2one('res.currency', string="Currency", help="Currency in which Unit cost is expressed", ondelete='CASCADE'),
+        'tracking': fields.function(_tracking, method=True, string='Tracking', type='boolean'), 
     }
 
 class stock_partial_picking(osv.osv_memory):
@@ -103,13 +117,33 @@
         assert len(ids) == 1, 'Partial picking processing may only be done one at a time'
         stock_picking = self.pool.get('stock.picking')
         stock_move = self.pool.get('stock.move')
+        uom_obj = self.pool.get('product.uom')
         partial = self.browse(cr, uid, ids[0], context=context)
         partial_data = {
             'delivery_date' : partial.date
         }
         picking_type = partial.picking_id.type
         for move in partial.move_ids:
+            move_uom = move.move_id.product_uom
+            process_uom = move.product_uom
             move_id = move.move_id.id
+
+            #Quantiny must be Positive
+            if move.quantity < 0:
+                raise osv.except_osv(_('Warning!'), _('Please provide Proper Quantity !'))
+
+            #Compute the wizard Quantity for respective move. 
+            toprocess = uom_obj._compute_qty(cr, uid, process_uom.id, move.quantity, move_uom.id)
+
+            #Check rounding Quantity.ex.
+            #picking: 1kg, uom kg rounding = 0.01 (rounding to 10g), 
+            #partial delivery: 253g
+            #=> result= refused, as the qty left on picking would be 0.747kg and only 0.75 is accepted by the uom.
+            if process_uom.factor and process_uom.factor <> 0 and move_uom.factor:
+                without_rounding_qty = (move.quantity / process_uom.factor) * move_uom.factor
+                if toprocess <> without_rounding_qty:
+                    raise osv.except_osv(_('Warning'), _('Quantity left on picking would be "%s %s" but "%s %s" is accepted by the uom.') % (without_rounding_qty, process_uom.name, toprocess, process_uom.name))
+
             if not move_id:
                 seq_obj_name =  'stock.picking.' + picking_type
                 move_id = stock_move.create(cr,uid,{'name' : self.pool.get('ir.sequence').get(cr, uid, seq_obj_name),

=== modified file 'stock/wizard/stock_partial_picking_view.xml'
--- stock/wizard/stock_partial_picking_view.xml	2011-10-16 01:28:00 +0000
+++ stock/wizard/stock_partial_picking_view.xml	2011-11-16 12:38:29 +0000
@@ -38,7 +38,8 @@
                     <field name="product_uom" />
                     <field name="location_id" />
                     <field name="location_dest_id" />
-                    <field name="prodlot_id" domain="[('product_id', '=', product_id)]" groups="base.group_extended" />
+                    <field name="tracking" invisible="1"/>
+                    <field name="prodlot_id" domain="[('product_id', '=', product_id)]" attrs="{'required':[('tracking','=',True)]}" groups="base.group_extended" />
                     <field name="update_cost" invisible="1"/>
                     <field name="cost" attrs="{'invisible': [('update_cost','=', False)]}"/>
                     <field name="currency" attrs="{'invisible': [('update_cost','=', False)]}"/>
@@ -56,7 +57,8 @@
                     <field name="product_uom" />
                     <field name="location_id" />
                     <field name="location_dest_id" />
-                    <field name="prodlot_id" domain="[('product_id', '=', product_id)]" groups="base.group_extended" />
+                    <field name="tracking" invisible="1"/>
+                    <field name="prodlot_id" domain="[('product_id', '=', product_id)]" attrs="{'required':[('tracking','=',True)]}" groups="base.group_extended" />
                     <field name="update_cost" invisible="1"/>
                     <field name="cost" attrs="{'invisible': [('update_cost','=', False)]}"/>
                     <field name="currency" attrs="{'invisible': [('update_cost','=', False)]}"/>

_______________________________________________
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