[FIX] stock: origin and partner_id when procurement group is set

We chose to erase the partner_id and ref field on a picking when its
content may refer to multile records. Note that the partner_id field was
already hidden in the view of internal picking.
This commit is contained in:
Simon Lejeune
2017-11-07 08:23:16 +01:00
parent 82a90bc094
commit 4a5f07654f
2 changed files with 86 additions and 2 deletions
+9 -1
View File
@@ -651,7 +651,15 @@ class StockMove(models.Model):
('picking_type_id', '=', move.picking_type_id.id),
('printed', '=', False),
('state', 'in', ['draft', 'confirmed', 'waiting', 'partially_available', 'assigned'])], limit=1)
if not picking:
if picking:
# If a picking is found, we'll append `move` to its move list and thus its
# `partner_id` and `ref` field will refer to multiple records. In this
# case, we chose to wipe them.
picking.write({
'partner_id': False,
'origin': False,
})
else:
recompute = True
picking = Picking.create(move._get_new_picking_values())
move.write({'picking_id': picking.id})
+77 -1
View File
@@ -4,6 +4,7 @@
from odoo.addons.stock.tests.common import TestStockCommon
from odoo.exceptions import UserError
from odoo import api, registry
from odoo.tests.common import TransactionCase
class TestPickShip(TestStockCommon):
@@ -530,6 +531,7 @@ class TestPickShip(TestStockCommon):
picking_client.action_confirm()
self.assertEqual(len(picking_client.move_lines), 2, 'Moves should not be merged')
class TestSinglePicking(TestStockCommon):
def test_backorder_1(self):
""" Check the good behavior of creating a backorder for an available stock move.
@@ -1464,7 +1466,6 @@ class TestSinglePicking(TestStockCommon):
class TestStockUOM(TestStockCommon):
def setUp(self):
with registry().cursor() as cr:
env = api.Environment(cr, 1, {})
@@ -1541,3 +1542,78 @@ class TestStockUOM(TestStockCommon):
self.assertEqual(len(back_order_in), 1.00, 'There should be one back order created')
self.assertEqual(back_order_in.move_lines.product_qty, 91640.00, 'There should be one back order created')
class TestRoutes(TransactionCase):
def test_pick_ship_1(self):
""" Enable the pick ship route, force a procurement group on the
pick. When a second move is added, make sure the `partner_id` and
`origin` fields are erased.
"""
product1 = self.env['product.product'].create({
'name': 'product a',
'type': 'product',
'categ_id': self.env.ref('product.product_category_all').id,
})
uom_unit = self.env.ref('product.product_uom_unit')
wh = self.env['stock.warehouse'].search([('company_id', '=', self.env.user.id)], limit=1)
# create and get back the pick ship route
wh.write({'delivery_steps': 'pick_ship'})
pick_ship_route = wh.route_ids.filtered(lambda r: 'Pick + Ship' in r.name)
# create a procurement group and set in on the pick procurement rule
procurement_group0 = self.env['procurement.group'].create({})
pick_rule = pick_ship_route.pull_ids.filtered(lambda rule: 'Stock -> Output' in rule.name)
push_rule = pick_ship_route.pull_ids - pick_rule
pick_rule.write({
'group_propagation_option': 'fixed',
'group_id': procurement_group0.id,
})
stock_location = pick_rule.location_src_id
ship_location = pick_rule.location_id
customer_location = push_rule.location_id
partners = self.env['res.partner'].search([], limit=2)
partner0 = partners[0]
partner1 = partners[1]
procurement_group1 = self.env['procurement.group'].create({'partner_id': partner0.id})
procurement_group2 = self.env['procurement.group'].create({'partner_id': partner1.id})
move1 = self.env['stock.move'].create({
'name': 'first out move',
'procure_method': 'make_to_order',
'location_id': ship_location.id,
'location_dest_id': customer_location.id,
'product_id': product1.id,
'product_uom': uom_unit.id,
'product_uom_qty': 1.0,
'warehouse_id': wh.id,
'group_id': procurement_group1.id,
'origin': 'origin1',
})
move2 = self.env['stock.move'].create({
'name': 'second out move',
'procure_method': 'make_to_order',
'location_id': ship_location.id,
'location_dest_id': customer_location.id,
'product_id': product1.id,
'product_uom': uom_unit.id,
'product_uom_qty': 1.0,
'warehouse_id': wh.id,
'group_id': procurement_group2.id,
'origin': 'origin2',
})
# first out move, the "pick" picking should have a partner and an origin
move1._action_confirm()
picking_pick = move1.move_orig_ids.picking_id
self.assertEqual(picking_pick.partner_id.id, procurement_group1.partner_id.id)
self.assertEqual(picking_pick.origin, move1.group_id.name)
# second out move, the "pick" picking should have lost its partner and origin
move2._action_confirm()
self.assertEqual(picking_pick.partner_id.id, False)
self.assertEqual(picking_pick.origin, False)