[FIX] stock: update description_picking with picking type

This commit updates the description_picking on stock moves once the
picking type is changed. This is needed to merge stock moves at
confirmation. The description_picking field chosen on the merged move is
the 'minimum one'. Empty string will always be chosen that way, so we
lose the information.

closes odoo/odoo#60762

X-original-commit: a3dad0f892b5394124763ceb13305fca745c95b9
Signed-off-by: William Henrotin <Whenrow@users.noreply.github.com>
This commit is contained in:
William Henrotin
2020-10-26 16:14:52 +00:00
parent 58857ebb1d
commit 1f4d7ba7ba
2 changed files with 30 additions and 1 deletions
+5
View File
@@ -640,6 +640,10 @@ class Picking(models.Model):
if vals.get('partner_id'):
for picking in res.filtered(lambda p: p.location_id.usage == 'supplier' or p.location_dest_id.usage == 'customer'):
picking.message_subscribe([vals.get('partner_id')])
if vals.get('picking_type_id'):
for move in res.move_lines:
if not move.description_picking:
move.description_picking = move.product_id._get_description(move.picking_id.picking_type_id)
return res
@@ -667,6 +671,7 @@ class Picking(models.Model):
self.mapped('move_lines').filtered(lambda move: not move.scrapped).write(after_vals)
if vals.get('move_lines'):
self._autoconfirm_picking()
return res
def unlink(self):
+25 -1
View File
@@ -5,8 +5,8 @@ from datetime import timedelta
from odoo.addons.stock.tests.common import TestStockCommon
from odoo.exceptions import UserError
from odoo.tests import Form
from odoo.tests.common import Form
class TestPickShip(TestStockCommon):
def create_pick_ship(self):
@@ -2829,3 +2829,27 @@ class TestAutoAssign(TestStockCommon):
move.lot_ids = [(4, lot2.id)]
move.lot_ids = [(4, lot3.id)]
self.assertEqual(move.quantity_done, 3.0/12.0)
def test_update_description(self):
""" Create an empty picking. Adds a move on product1, select the picking type, add
again a move on product1. Confirm the picking. The two stock moves should be merged. """
product1 = self.env['product.product'].create({
'name': 'product',
'type':'product',
})
picking_form = Form(self.env['stock.picking'])
with picking_form.move_ids_without_package.new() as move:
move.product_id = product1
move.product_uom_qty = 10
move.location_id = self.env.ref('stock.stock_location_suppliers')
move.location_dest_id = self.env.ref('stock.stock_location_stock')
picking_form.picking_type_id = self.env.ref('stock.picking_type_in')
with picking_form.move_ids_without_package.new() as move:
move.product_id = product1
move.product_uom_qty = 15
picking = picking_form.save()
picking.action_confirm()
self.assertEqual(len(picking.move_lines), 1)
self.assertEqual(picking.move_lines.product_uom_qty, 25)