diff --git a/stock_picking_line_sequence/README.rst b/stock_picking_line_sequence/README.rst index 3fd49d4a8c0b..d2fe07201d62 100644 --- a/stock_picking_line_sequence/README.rst +++ b/stock_picking_line_sequence/README.rst @@ -23,7 +23,7 @@ Stock picking lines with sequence number :target: https://runbot.odoo-community.org/runbot/154/12.0 :alt: Try me on Runbot -|badge1| |badge2| |badge3| |badge4| |badge5| +|badge1| |badge2| |badge3| |badge4| |badge5| Provide a new field sequence on stock moves, which allows to manage the order of moves in a picking. @@ -53,6 +53,7 @@ Credits Authors ~~~~~~~ +* ArcheTI * Camptocamp * Eficent * Serpent CS @@ -60,7 +61,7 @@ Authors Contributors ~~~~~~~~~~~~ - +* Cécile Jallais * Alexandre Fayolle * Damien Crier * Eficent Business and IT Consulting Services S.L. diff --git a/stock_picking_line_sequence/__manifest__.py b/stock_picking_line_sequence/__manifest__.py index 707529cb6660..94a73442be96 100644 --- a/stock_picking_line_sequence/__manifest__.py +++ b/stock_picking_line_sequence/__manifest__.py @@ -11,7 +11,8 @@ "author": "Camptocamp, " "Eficent, " "Serpent CS, " - "Odoo Community Association (OCA)", + "Odoo Community Association (OCA), " + "ArcheTI", "website": "https://github.com/OCA/stock-logistics-workflow", "depends": ["stock", "sale", "sale_stock"], "data": [ diff --git a/stock_picking_line_sequence/models/stock.py b/stock_picking_line_sequence/models/stock.py index 82d544ab4c8b..9ea843d26fa4 100644 --- a/stock_picking_line_sequence/models/stock.py +++ b/stock_picking_line_sequence/models/stock.py @@ -31,10 +31,37 @@ def create(self, values): return move +class StockMoveLine(models.Model): + _inherit = "stock.move.line" + + def _get_aggregated_product_quantities(self, **kwargs): + aggregated_move_lines = super( + StockMoveLine, self + )._get_aggregated_product_quantities(**kwargs) + for move_line in self: + name = move_line.product_id.display_name + description = move_line.move_id.description_picking + if description == name or description == move_line.product_id.name: + description = False + uom = move_line.product_uom_id + line_key = ( + str(move_line.product_id.id) + + "_" + + name + + (description or "") + + "uom " + + str(uom.id) + ) + sequence2 = move_line.move_id.sequence2 + if line_key in aggregated_move_lines: + aggregated_move_lines[line_key]["sequence2"] = sequence2 + + return aggregated_move_lines + + class StockPicking(models.Model): _inherit = "stock.picking" - @api.multi @api.depends("move_ids_without_package") def _compute_max_line_sequence(self): """Allow to know the highest sequence entered in move lines. @@ -52,7 +79,6 @@ def _compute_max_line_sequence(self): string="Max sequence in lines", compute="_compute_max_line_sequence" ) - @api.multi def _reset_sequence(self): for rec in self: current_sequence = 1 @@ -60,13 +86,11 @@ def _reset_sequence(self): line.sequence = current_sequence current_sequence += 1 - @api.multi def copy(self, default=None): return super(StockPicking, self.with_context(keep_line_sequence=True)).copy( default ) - @api.multi def button_validate(self): return super( StockPicking, self.with_context(keep_line_sequence=True) diff --git a/stock_picking_line_sequence/readme/CONTRIBUTORS.rst b/stock_picking_line_sequence/readme/CONTRIBUTORS.rst index 7ca326971960..7f0c3d7e23d1 100644 --- a/stock_picking_line_sequence/readme/CONTRIBUTORS.rst +++ b/stock_picking_line_sequence/readme/CONTRIBUTORS.rst @@ -1,4 +1,5 @@ +* Cécile Jallais * Alexandre Fayolle * Damien Crier * Eficent Business and IT Consulting Services S.L. diff --git a/stock_picking_line_sequence/report/report_deliveryslip.xml b/stock_picking_line_sequence/report/report_deliveryslip.xml index 6b0279a06e91..f70a7c932842 100644 --- a/stock_picking_line_sequence/report/report_deliveryslip.xml +++ b/stock_picking_line_sequence/report/report_deliveryslip.xml @@ -2,18 +2,33 @@ + + + + diff --git a/stock_picking_line_sequence/tests/test_move_lines_sequence.py b/stock_picking_line_sequence/tests/test_move_lines_sequence.py index bd8ef8d7c3b8..b1cd6f18c69e 100644 --- a/stock_picking_line_sequence/tests/test_move_lines_sequence.py +++ b/stock_picking_line_sequence/tests/test_move_lines_sequence.py @@ -95,9 +95,12 @@ def test_backorder(self): picking.action_confirm() picking.action_assign() picking.move_line_ids[1].write({"qty_done": 5}) - backorder_wiz_id = picking.button_validate()["res_id"] - backorder_wiz = self.env["stock.backorder.confirmation"].browse( - [backorder_wiz_id] + res_dict = picking.button_validate() + self.assertEqual(res_dict["res_model"], "stock.backorder.confirmation") + backorder_wiz = ( + self.env["stock.backorder.confirmation"] + .browse(res_dict.get("res_id")) + .with_context(res_dict["context"]) ) backorder_wiz.process() picking_backorder = self.Picking.search([("backorder_id", "=", picking.id)]) @@ -107,3 +110,21 @@ def test_backorder(self): self.assertEqual( picking_backorder[0].move_lines[0].sequence, 1, "Backorder wrong sequence" ) + + def test_move_lines_aggregated(self): + picking = self._create_picking() + picking._compute_max_line_sequence() + picking.action_confirm() + agg_mls = picking.move_line_ids[0]._get_aggregated_product_quantities() + for key in agg_mls: + self.assertNotEqual( + agg_mls[key].get("sequence2", "NA"), + "NA", + "The field sequence2 is not added in dictionary", + ) + self.assertEqual( + picking.move_line_ids[0].move_id.sequence2, + agg_mls[key]["sequence2"], + "The Sequence is not copied properly in the aggregated move lines", + ) + break