Kirti Savalia(OpenERP) has proposed merging 
lp:~openerp-dev/openobject-addons/trunk-bug-904170-ksa into 
lp:openobject-addons.

Requested reviews:
  Kirti Savalia(OpenERP) (ksa-openerp)
  Rucha (Open ERP) (rpa-openerp)
  Raphael Collet (OpenERP) (rco-openerp)
Related bugs:
  Bug #904170 in OpenERP Addons: "change qty on production order ignores 
quantity type of subproduct"
  https://bugs.launchpad.net/openobject-addons/+bug/904170

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-bug-904170-ksa/+merge/85817
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-bug-904170-ksa/+merge/85817
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-addons/trunk-bug-904170-ksa.
=== modified file 'mrp/wizard/change_production_qty.py'
--- mrp/wizard/change_production_qty.py	2011-10-31 11:38:30 +0000
+++ mrp/wizard/change_production_qty.py	2012-01-05 08:54:36 +0000
@@ -48,10 +48,10 @@
         if 'product_qty' in fields:
             res.update({'product_qty': prod.product_qty})  
         return res
-        
-    def change_prod_qty(self, cr, uid, ids, context=None):
+
+    def production_consume_produce_line_data(self, cr, uid, ids, context=None):
         """ 
-        Changes the Quantity of Product.
+        Changes the Quantity for consume and Finish product line.
         @param self: The object pointer.
         @param cr: A database cursor
         @param uid: ID of the user currently logged in
@@ -72,21 +72,29 @@
             for move in prod.move_lines:
                 bom_point = prod.bom_id
                 bom_id = prod.bom_id.id
-                if not bom_point:
-                    bom_id = bom_obj._bom_find(cr, uid, prod.product_id.id, prod.product_uom.id)
-                    if not bom_id:
-                        raise osv.except_osv(_('Error'), _("Couldn't find bill of material for product"))
-                    prod_obj.write(cr, uid, [prod.id], {'bom_id': bom_id})
-                    bom_point = bom_obj.browse(cr, uid, [bom_id])[0]
-        
-                if not bom_id:
-                    raise osv.except_osv(_('Error'), _("Couldn't find bill of material for product"))
-        
                 factor = prod.product_qty * prod.product_uom.factor / bom_point.product_uom.factor
                 res = bom_obj._bom_explode(cr, uid, bom_point, factor / bom_point.product_qty, [])
                 for r in res[0]:
                     if r['product_id'] == move.product_id.id:
-                        move_lines_obj.write(cr, uid, [move.id], {'product_qty' :  r['product_qty']})
+                        move_lines_obj.write(cr, uid, [move.id], {'product_qty' :  r['product_qty']})    
+        
+    def change_prod_qty(self, cr, uid, ids, context=None):
+        """
+        Changes the Quantity of Product.
+        @param self: The object pointer.
+        @param cr: A database cursor
+        @param uid: ID of the user currently logged in
+        @param ids: List of IDs selected
+        @param context: A standard dictionary
+        @return:
+        """
+        record_id = context and context.get('active_id',False)
+        assert record_id, _('Active Id is not found')
+        move_lines_obj = self.pool.get('stock.move')
+        prod_obj = self.pool.get('mrp.production')
+        self.production_consume_produce_line_data(cr, uid, ids, context=context)
+        prod = prod_obj.browse(cr, uid, record_id, context=context)
+        for wiz_qty in self.browse(cr, uid, ids, context=context):
             for m in prod.move_created_ids:
                 move_lines_obj.write(cr, uid, [m.id], {'product_qty': wiz_qty.product_qty})
     

=== modified file 'mrp_subproduct/mrp_subproduct.py'
--- mrp_subproduct/mrp_subproduct.py	2011-11-11 13:59:06 +0000
+++ mrp_subproduct/mrp_subproduct.py	2012-01-05 08:54:36 +0000
@@ -124,4 +124,40 @@
         return super(mrp_production, self)._get_subproduct_factor(cr, uid, production_id, move_id, context=context)
 
 mrp_production()
+
+class change_production_qty(osv.osv_memory):
+    _inherit = 'change.production.qty'
+
+    def change_prod_qty(self, cr, uid, ids, context=None):
+        """
+        Changes the Quantity of Product.
+        @param self: The object pointer.
+        @param cr: A database cursor
+        @param uid: ID of the user currently logged in
+        @param ids: List of IDs selected
+        @param context: A standard dictionary
+        @return:
+        """
+        record_id = context and context.get('active_id',False)
+        assert record_id, _('Active Id is not found')
+        prod_obj = self.pool.get('mrp.production')
+        move_lines_obj = self.pool.get('stock.move')
+        self.production_consume_produce_line_data(cr, uid, ids, context=context)
+        prod = prod_obj.browse(cr, uid, record_id, context=context)
+        for wiz_qty in self.browse(cr, uid, ids, context=context):
+            for m in prod.move_created_ids:
+                for sub_product in prod.bom_id.sub_products:
+                    if sub_product.product_id.id == m.product_id.id:
+                        if sub_product.subproduct_type == 'fixed':
+                            move_lines_obj.write(cr, uid, [m.id], {'product_qty': sub_product.product_qty})
+                            break
+                        else:
+                            move_lines_obj.write(cr, uid, [m.id], {'product_qty': sub_product.product_qty * wiz_qty.product_qty})
+                            break
+                    else:
+                        move_lines_obj.write(cr, uid, [m.id], {'product_qty': wiz_qty.product_qty})
+
+        return {}
+
+change_production_qty()
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

_______________________________________________
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