From 4689f59a25008246eadff5c93b68a08e9b8a7749 Mon Sep 17 00:00:00 2001 From: Pierre Masereel Date: Wed, 26 Oct 2016 17:21:15 +0200 Subject: [PATCH] [FIX] delivery: set carrier on all picking created by SO When our warehouse is configured to work as 'pick -> pack -> ship' only the last picking (ship) has the information of which carrier is set for this delivery. This is a problem, because we also need the information in the packing zone, to put in a pack with the correct package type. To fix this problem, instead of overriding the function 'action_confirm' which put the 'carrier_id' only on the 'ship' location. We set the 'sale_order_id' on the procurement groups created from the sales order, and propagate it to the picking through the stock moves from the procurement group. --- addons/delivery/models/stock_move.py | 22 ++++------------------ addons/sale_stock/models/procurement.py | 6 +++++- addons/sale_stock/models/sale_order.py | 2 +- 3 files changed, 10 insertions(+), 20 deletions(-) diff --git a/addons/delivery/models/stock_move.py b/addons/delivery/models/stock_move.py index 92fb62d7dc3..cae1b7cd751 100644 --- a/addons/delivery/models/stock_move.py +++ b/addons/delivery/models/stock_move.py @@ -21,21 +21,7 @@ class StockMove(models.Model): for move in self.filtered(lambda moves: moves.product_id.weight > 0.00): move.weight = (move.product_qty * move.product_id.weight) - @api.multi - def action_confirm(self): - """ - 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: - 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(StockMove, self).action_confirm() - for proc in procs_to_check: - pickings = (proc.move_ids.mapped('picking_id')).filtered(lambda record: not record.carrier_id) - if pickings: - pickings.write({ - 'carrier_id': proc.sale_line_id.order_id.carrier_id.id, - }) - return res + def _get_new_picking_values(self): + vals = super(StockMove, self)._get_new_picking_values() + vals['carrier_id'] = self.group_id.sale_order_id.carrier_id.id + return vals diff --git a/addons/sale_stock/models/procurement.py b/addons/sale_stock/models/procurement.py index 93c07aaf7c0..5710bff5af6 100644 --- a/addons/sale_stock/models/procurement.py +++ b/addons/sale_stock/models/procurement.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from odoo import models +from odoo import models, fields class ProcurementOrder(models.Model): @@ -12,3 +12,7 @@ class ProcurementOrder(models.Model): if self.sale_line_id: vals.update({'sequence': self.sale_line_id.sequence}) return vals + +class ProcurementGroup(models.Model): + _inherit = 'procurement.group' + sale_order_id = fields.Many2one('sale.order', string='Sale Order') diff --git a/addons/sale_stock/models/sale_order.py b/addons/sale_stock/models/sale_order.py index 3715190ad54..3e5a757ef6e 100644 --- a/addons/sale_stock/models/sale_order.py +++ b/addons/sale_stock/models/sale_order.py @@ -75,7 +75,7 @@ class SaleOrder(models.Model): @api.model def _prepare_procurement_group(self): res = super(SaleOrder, self)._prepare_procurement_group() - res.update({'move_type': self.picking_policy, 'partner_id': self.partner_shipping_id.id}) + res.update({'move_type': self.picking_policy, 'partner_id': self.partner_shipping_id.id, 'sale_order_id': self.id}) return res @api.model