From fc183e7fca8fad050ab9abc6fe82bf9823f30c65 Mon Sep 17 00:00:00 2001 From: BernatPForgeFlow Date: Tue, 21 Nov 2023 08:30:53 +0100 Subject: [PATCH] [IMP] ddmrp: Add customized Stock Moves view When checking incoming quantities or qualified demand moves, we will use a customized view that allows to redirect to the source document of that move. --- ddmrp/models/stock_move.py | 46 +++++++++++++++++++++++++ ddmrp/views/stock_move_views.xml | 58 ++++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+) diff --git a/ddmrp/models/stock_move.py b/ddmrp/models/stock_move.py index 29106999a..588aeb5e0 100644 --- a/ddmrp/models/stock_move.py +++ b/ddmrp/models/stock_move.py @@ -84,3 +84,49 @@ def _update_ddmrp_nfp(self): buffer.cron_actions(only_nfp="out") for buffer in in_buffers.with_context(no_ddmrp_history=True): buffer.cron_actions(only_nfp="in") + + def action_open_ddmrp_source(self): + moves = self + if self.move_orig_ids: + moves = self.move_orig_ids + while moves.mapped("move_orig_ids"): + moves = moves.mapped("move_orig_ids") + if self.move_dest_ids: + moves = self.move_dest_ids + while moves.mapped("move_dest_ids"): + moves = moves.mapped("move_dest_ids") + if moves.mapped("purchase_line_id").filtered(lambda x: x.state != "cancel"): + result = self.env["ir.actions.actions"]._for_xml_id("purchase.purchase_rfq") + result["domain"] = [ + ( + "id", + "in", + moves.filtered(lambda x: x.state != "cancel").mapped( + "purchase_line_id.order_id.id" + ), + ) + ] + elif moves.mapped("sale_line_id"): + result = self.env["ir.actions.actions"]._for_xml_id( + "sale.action_quotations" + ) + result["domain"] = [("id", "in", moves.mapped("sale_line_id.order_id.id"))] + elif moves.mapped("production_id"): + result = self.env["ir.actions.actions"]._for_xml_id( + "mrp.mrp_production_action" + ) + result["domain"] = [("id", "in", moves.mapped("production_id.id"))] + elif moves.mapped("raw_material_production_id"): + result = self.env["ir.actions.actions"]._for_xml_id( + "mrp.mrp_production_action" + ) + result["domain"] = [ + ("id", "in", moves.mapped("raw_material_production_id.id")) + ] + else: + result = self.env["ir.actions.actions"]._for_xml_id( + "stock.action_picking_tree_all" + ) + result["domain"] = [("id", "in", moves.mapped("picking_id.id"))] + result["context"] = {} + return result diff --git a/ddmrp/views/stock_move_views.xml b/ddmrp/views/stock_move_views.xml index f5fd2c904..0962697b3 100644 --- a/ddmrp/views/stock_move_views.xml +++ b/ddmrp/views/stock_move_views.xml @@ -4,6 +4,45 @@ + + stock.move.tree.ddmrp + stock.move + + + + + + + + + + +