[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.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user