diff --git a/addons/delivery/stock.py b/addons/delivery/stock.py
index b62ecf58f09..c8781244fe0 100644
--- a/addons/delivery/stock.py
+++ b/addons/delivery/stock.py
@@ -172,11 +172,20 @@ class stock_move(osv.osv):
}
def action_confirm(self, cr, uid, ids, context=None):
+ """
+ Pass the carrier to the picking from the sales order
+ (Should also work in case of Phantom BoMs when on explosion the original move is deleted)
+ """
+ procs_to_check = []
+ for move in self.browse(cr, uid, ids, context=context):
+ if move.procurement_id and move.procurement_id.sale_line_id and move.procurement_id.sale_line_id.order_id.carrier_id:
+ procs_to_check += [move.procurement_id]
res = super(stock_move, self).action_confirm(cr, uid, ids, context=context)
pick_obj = self.pool.get("stock.picking")
- for move in self.browse(cr, uid, ids, context=context):
- if move.picking_id and move.procurement_id and move.procurement_id.sale_line_id and not move.picking_id.carrier_id :
- pick_obj.write(cr, uid, [move.picking_id.id], {'carrier_id': move.procurement_id.sale_line_id.order_id.carrier_id.id}, context=context)
+ for proc in procs_to_check:
+ pickings = list(set([x.picking_id.id for x in proc.move_ids if x.picking_id and not x.picking_id.carrier_id]))
+ if pickings:
+ pick_obj.write(cr, uid, pickings, {'carrier_id': proc.sale_line_id.order_id.carrier_id.id}, context=context)
return res
diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py
index bec11639a86..f08c16943b6 100644
--- a/addons/purchase/purchase.py
+++ b/addons/purchase/purchase.py
@@ -149,7 +149,6 @@ class purchase_order(osv.osv):
return res and res[0] or False
def _get_picking_in(self, cr, uid, context=None):
-
obj_data = self.pool.get('ir.model.data')
type_obj = self.pool.get('stock.picking.type')
user_obj = self.pool.get('res.users')
@@ -159,9 +158,11 @@ class purchase_order(osv.osv):
type = type_obj.browse(cr, uid, pick_type, context=context)
if type and type.warehouse_id and type.warehouse_id.company_id.id == company_id:
return pick_type
- types = type_obj.search(cr, uid, [('code', '=', 'incoming')], context=context)
+ types = type_obj.search(cr, uid, [('code', '=', 'incoming'), ('warehouse_id.company_id', '=', company_id)], context=context)
if not types:
- raise osv.except_osv(_('Error!'), _("Make sure you have at least an incoming picking type defined"))
+ types = type_obj.search(cr, uid, [('code', '=', 'incoming'), ('warehouse_id', '=', False)], context=context)
+ if not types:
+ raise osv.except_osv(_('Error!'), _("Make sure you have at least an incoming picking type defined"))
return types[0]
def _get_picking_ids(self, cr, uid, ids, field_names, args, context=None):
diff --git a/addons/stock/procurement.py b/addons/stock/procurement.py
index 07024a2529e..c105ed6c017 100644
--- a/addons/stock/procurement.py
+++ b/addons/stock/procurement.py
@@ -273,7 +273,7 @@ class procurement_order(osv.osv):
@param context: A standard dictionary for contextual values
@return: Dictionary of values
'''
- super(procurement_order, self).run_scheduler(cr, uid, use_new_cursor=use_new_cursor, context=context)
+ super(procurement_order, self).run_scheduler(cr, uid, use_new_cursor=use_new_cursor, company_id=company_id, context=context)
if context is None:
context = {}
try:
@@ -283,7 +283,7 @@ class procurement_order(osv.osv):
move_obj = self.pool.get('stock.move')
#Minimum stock rules
- self._procure_orderpoint_confirm(cr, SUPERUSER_ID, use_new_cursor=False, company_id=company_id, context=context)
+ self._procure_orderpoint_confirm(cr, SUPERUSER_ID, use_new_cursor=use_new_cursor, company_id=company_id, context=context)
#Search all confirmed stock_moves and try to assign them
confirmed_ids = move_obj.search(cr, uid, [('state', '=', 'confirmed')], limit=None, order='priority desc, date_expected asc', context=context)
diff --git a/addons/stock/stock_view.xml b/addons/stock/stock_view.xml
index 7e45cb20a8d..d6a6dcf01f8 100644
--- a/addons/stock/stock_view.xml
+++ b/addons/stock/stock_view.xml
@@ -1093,7 +1093,7 @@
-
+
@@ -1662,7 +1662,7 @@
stock.quant
-