From 5c682c0fb834bcaa9e969467c0c494dfc3ecf8bb Mon Sep 17 00:00:00 2001 From: "Andrea Grazioso (agr-odoo)" Date: Wed, 20 Mar 2024 11:25:11 +0100 Subject: [PATCH] [FIX] stock: No backorder for tracked products In Settings>Inventory>Operations enable "Batch Transfers" Create a [NonTrackedProd] product: - Product Type: Storable Product - Tracking: No tracking Create a [TrackedProd] product: - Product Type: Storable Product - Tracking: By Lots Make two POs with: - Prod [NonTrackedProd] qty 1 - Prod [TrackedProd] qty 1 Open Barcode Scanning app Select "Batch Transfers" Create a new batch with the incoming transfers from the POs Set only the [NonTrackedProd] lines as done and validate Issue: Error will block validation "You need to supply a Lot/Serial number for products" The system should let the user validate the operation and create a backorder instead of blocking the user opw-3777701 closes odoo/odoo#158330 Signed-off-by: Quentin Wolfs (quwo) --- addons/stock/models/stock_picking.py | 2 +- addons/stock/tests/test_stock_flow.py | 34 +++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/addons/stock/models/stock_picking.py b/addons/stock/models/stock_picking.py index 9d3361100ac..40fa5c03f0e 100644 --- a/addons/stock/models/stock_picking.py +++ b/addons/stock/models/stock_picking.py @@ -1058,7 +1058,7 @@ class Picking(models.Model): def get_line_with_done_qty_ids(move_lines): # Get only move_lines that has some quantity set. - return move_lines.filtered(lambda ml: ml.product_id and ml.product_id.tracking != 'none' and float_compare(ml.quantity, 0, precision_rounding=ml.product_uom_id.rounding)).ids + return move_lines.filtered(lambda ml: ml.product_id and ml.product_id.tracking != 'none' and ml.picked and float_compare(ml.quantity, 0, precision_rounding=ml.product_uom_id.rounding)).ids if separate_pickings: # If pickings are checked independently, get full/partial move_lines depending if each picking has no quantity set. diff --git a/addons/stock/tests/test_stock_flow.py b/addons/stock/tests/test_stock_flow.py index 954a6504c56..87458e953ef 100644 --- a/addons/stock/tests/test_stock_flow.py +++ b/addons/stock/tests/test_stock_flow.py @@ -2542,6 +2542,40 @@ class TestStockFlow(TestStockCommon): backorder.button_validate() self.assertEqual(backorder.state, 'done') + def test_picking_mixed_tracking_with_backorder(self): + self.productB.tracking = 'lot' + picking = self.env['stock.picking'].create({ + 'location_id': self.supplier_location, + 'location_dest_id': self.stock_location, + 'picking_type_id': self.picking_type_in, + 'company_id': self.env.company.id, + }) + no_tracking_move = self.env['stock.move'].create({ + 'name': self.productA.name, + 'product_id': self.productA.id, + 'product_uom_qty': 1, + 'product_uom': self.productA.uom_id.id, + 'picking_id': picking.id, + 'location_id': self.supplier_location, + 'location_dest_id': self.stock_location, + }) + self.env['stock.move'].create({ + 'name': self.productB.name, + 'product_id': self.productB.id, + 'product_uom_qty': 1, + 'product_uom': self.productB.uom_id.id, + 'picking_id': picking.id, + 'location_id': self.supplier_location, + 'location_dest_id': self.stock_location, + }) + picking.action_confirm() + + no_tracking_move.picked = True + action_dict = picking.button_validate() + backorder_wizard = Form(self.env['stock.backorder.confirmation'].with_context(action_dict['context'])).save() + backorder_wizard.process() + bo = self.env['stock.picking'].search([('backorder_id', '=', picking.id)]) + self.assertEqual(bo.state, 'assigned') @tagged('-at_install', 'post_install') class TestStockFlowPostInstall(TestStockCommon):