[IMP] Phantom BoMs only out of services products should work
authorJosse Colpaert <jco@odoo.com>
Wed, 20 Aug 2014 08:03:23 +0000 (10:03 +0200)
committerJosse Colpaert <jco@odoo.com>
Wed, 3 Sep 2014 17:18:16 +0000 (19:18 +0200)
addons/mrp/stock.py
addons/sale_mrp/sale_mrp.py
addons/stock/procurement.py

index fb5a3bf..270ccc7 100644 (file)
@@ -115,7 +115,7 @@ class StockMove(osv.osv):
                             proc = proc_obj.copy(cr, uid, move.procurement_id.id, default=valdef, context=context)
                         else:
                             proc = proc_obj.create(cr, uid, valdef, context=context)
-                        proc_obj.run(cr, uid, [proc], context=context)
+                        proc_obj.run(cr, uid, [proc], context=context) #could be omitted
 
             
             #check if new moves needs to be exploded
index 1852326..52f9f01 100644 (file)
@@ -69,19 +69,6 @@ class mrp_production(osv.osv):
                         res[production.id] = move.procurement_id and move.procurement_id.sale_line_id and move.procurement_id.sale_line_id.order_id.client_order_ref or False
         return res
 
-    def _hook_create_post_procurement(self, cr, uid, production, procurement_id, context=None):
-        def get_parent_move(move):
-            if move.move_dest_id:
-                return get_parent_move(move.move_dest_id)
-            return move
-
-        res = super(mrp_production, self)._hook_create_post_procurement(cr, uid, production, procurement_id, context)
-        if production.move_prod_id:
-            parent_move_line = get_parent_move(production.move_prod_id)
-            if parent_move_line and parent_move_line.sale_line_id:
-                self.pool.get('procurement.order').write(cr, uid, procurement_id, {'sale_line_id': parent_move_line.sale_line_id.id})
-        return res
-
     _columns = {
         'sale_name': fields.function(_ref_calc, multi='sale_name', type='char', string='Sale Name', help='Indicate the name of sales order.'),
         'sale_ref': fields.function(_ref_calc, multi='sale_name', type='char', string='Sale Reference', help='Indicate the Customer Reference from sales order.'),
index 2e596a7..1b13af8 100644 (file)
@@ -206,11 +206,13 @@ class procurement_order(osv.osv):
         return super(procurement_order, self)._run(cr, uid, procurement, context=context)
 
     def run(self, cr, uid, ids, autocommit=False, context=None):
-        res = super(procurement_order, self).run(cr, uid, ids, autocommit=autocommit, context=context)
+        new_ids = [x.id for x in self.browse(cr, uid, ids, context=context) if x.state not in ('running', 'done', 'cancel')]
+        res = super(procurement_order, self).run(cr, uid, new_ids, autocommit=autocommit, context=context)
+
         #after all the procurements are run, check if some created a draft stock move that needs to be confirmed
         #(we do that in batch because it fasts the picking assignation and the picking state computation)
         move_to_confirm_ids = []
-        for procurement in self.browse(cr, uid, ids, context=context):
+        for procurement in self.browse(cr, uid, new_ids, context=context):
             if procurement.state == "running" and procurement.rule_id and procurement.rule_id.action == "move":
                 move_to_confirm_ids += [m.id for m in procurement.move_ids if m.state == 'draft']
         if move_to_confirm_ids:
@@ -223,8 +225,8 @@ class procurement_order(osv.osv):
         '''
         if procurement.rule_id and procurement.rule_id.action == 'move':
             uom_obj = self.pool.get('product.uom')
+            # In case Phantom BoM splits only into procurements
             if not procurement.move_ids:
-                import pdb; pdb.set_trace()
                 return True
             cancel_test_list = [x.state == 'cancel' for x in procurement.move_ids]
             done_cancel_test_list = [x.state in ('done', 'cancel') for x in procurement.move_ids]
@@ -237,8 +239,6 @@ class procurement_order(osv.osv):
                 return True
             elif all_cancel:
                 self.message_post(cr, uid, [procurement.id], body=_('All stock moves have been cancelled for this procurement.'), context=context)
-            elif not cancel_test_list:
-                self.write(cr, uid, [procurement.id], {'state': 'done'}, context=context)
             self.write(cr, uid, [procurement.id], {'state': 'cancel'}, context=context)
             return False