Skip to content

Commit

Permalink
[FIX] stock: wrong address on delivery slip when using packages
Browse files Browse the repository at this point in the history
The delivery slip of a picking with a package doesn't print the delivery address of the partner.

Steps to reproduce:
1. Go to Settings > Inventory > Operations and enable 'Packages'
2. Go to Inventory > Configuration > Warehouse Management > Operations Types
3. Open operation type 'Delivery Orders' and enable 'Show Detailed Operations' and 'Move Entire Packages'
4. Create a package: in Purchase, new RFQ, select products, confirm order, receive products, click on 'Put in Pack' and validate
5. In Inventory create a new Delivery Order, select a Delivery Address and the package you just created
6. Mark it as Done, validate and print the delivery slip
7. The delivery address is not the right one (the one selected on step 5)

Cause:
When creating the moves for the items in the package the partner_id is not given. So the moves don't have the field partner_id. When the method should_print_delivery_address() of stock_picking is called it returns False as self.move_ids[0].partner_id is undefined and the delivery address is not printed.

Solution:
Add the partner_id in _generate_moves() of stock_package_level to create the moves with the selected partner_id.

opw-3901104
  • Loading branch information
mathcoutant committed May 15, 2024
1 parent 2b2d3b7 commit fa2636c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions addons/stock/models/stock_package_level.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ def _generate_moves(self):
'location_dest_id': package_level.location_dest_id.id,
'package_level_id': package_level.id,
'company_id': package_level.company_id.id,
'partner_id': self.picking_id.partner_id.id,
})

@api.model_create_multi
Expand Down
24 changes: 24 additions & 0 deletions addons/stock/tests/test_packing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1585,6 +1585,30 @@ def test_expected_package_move_lines(self):
move_lines_to_pack = (internal_picking_1 | internal_picking_2)._package_move_lines()
self.assertEqual(len(move_lines_to_pack), 2, "all move lines in pickings should have been selected to pack")

def test_should_print_delivery_address_with_package(self):
"""Test that should_print_delivery_address in stock_picking returns true if a picking has only a package."""
pack = self.env['stock.quant.package'].create({'name': 'New Package'})
self.env['stock.quant']._update_available_quantity(self.productA, self.stock_location, 5, package_id=pack)

picking = self.env['stock.picking'].create({
'location_id': self.stock_location.id,
'location_dest_id': self.ref('stock.stock_location_customers'),
'picking_type_id': self.ref('stock.picking_type_out'),
'partner_id': self.env['res.partner'].create({'name': 'Test Partner'}).id,
})

package_level = self.env['stock.package_level'].create({
'package_id': pack.id,
'picking_id': picking.id,
'company_id': picking.company_id.id,
})

picking.action_confirm()
package_level.is_done = True
picking.button_validate()

self.assertTrue(picking.should_print_delivery_address())


@odoo.tests.tagged('post_install', '-at_install')
class TestPackagePropagation(TestPackingCommon):
Expand Down

0 comments on commit fa2636c

Please sign in to comment.