[FIX] stock: assign partner on return outgoing stock moves

Issue:
When printing delivery slip report the warehouse address is shown instead of the delivery address.

Steps to Reproduce:
1. Install Purchase App.
2. Install Inventory App.
3. Create Purchase Order.
4. Receive Purchase Order.
5. Return the transfer.
6. print delivery slip

Solution:
Issue was that upon creating the return stock moves that will be outgoing
we copy the attributes from the original incoming stock move which does not
have a partner assigned, So the solution was to assign the partner on the outgoing
stock moves right away from the stock picking.

opw-3623451

closes odoo/odoo#148398

X-original-commit: 5c9b8cea1a08d310363cd93bc27662f2b848ef84
Signed-off-by: Adrien Widart (awt) <awt@odoo.com>
Signed-off-by: Omar Abosamaha (abom) <abom@odoo.com>
This commit is contained in:
OmarAbosamaha
2024-01-10 05:04:37 +00:00
parent 640af08cad
commit 190382e665
2 changed files with 34 additions and 0 deletions
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from odoo.addons.stock.tests.common import TestStockCommon
from odoo.tests.common import Form
class TestReturnPicking(TestStockCommon):
@@ -143,3 +144,34 @@ class TestReturnPicking(TestStockCommon):
res = return_wizard.create_returns()
return_picking = self.PickingObj.browse(res["res_id"])
self.assertEqual(return_picking.location_dest_id, return_location)
def test_return_incoming_picking(self):
"""
Test returns of incoming pickings have the same partner assigned to them
"""
partner = self.env['res.partner'].create({'name': 'Jean'})
receipt = self.env['stock.picking'].create({
'picking_type_id': self.picking_type_in,
'location_id': self.supplier_location,
'location_dest_id': self.stock_location,
'partner_id': partner.id,
'move_ids': [(0, 0, {
'name': self.UnitA.name,
'product_id': self.UnitA.id,
'product_uom_qty': 1,
'product_uom': self.uom_unit.id,
'location_id': self.stock_location,
'location_dest_id': self.customer_location,
})],
})
receipt.button_validate()
# create a return picking
stock_return_picking_form = Form(self.env['stock.return.picking']
.with_context(active_ids=receipt.ids, active_id=receipt.ids[0],
active_model='stock.picking'))
stock_return_picking = stock_return_picking_form.save()
stock_return_picking.product_return_moves.quantity = 1.0
stock_return_picking_action = stock_return_picking.create_returns()
return_picking = self.env['stock.picking'].browse(stock_return_picking_action['res_id'])
return_picking.button_validate()
self.assertEqual(return_picking.move_ids[0].partner_id.id, receipt.partner_id.id)
@@ -109,6 +109,8 @@ class ReturnPicking(models.TransientModel):
'origin_returned_move_id': return_line.move_id.id,
'procure_method': 'make_to_stock',
}
if new_picking.picking_type_id.code == 'outgoing':
vals['partner_id'] = new_picking.partner_id.id
return vals
def _prepare_picking_default_values(self):