diff --git a/addons/mrp/models/stock_move.py b/addons/mrp/models/stock_move.py index b236c62652f..a9227cc041a 100644 --- a/addons/mrp/models/stock_move.py +++ b/addons/mrp/models/stock_move.py @@ -551,3 +551,15 @@ class StockMove(models.Model): if 'manufacture' in self.product_id._get_rules_from_location(self.location_id).mapped('action'): date -= relativedelta(days=self.company_id.manufacturing_lead) return date + + def action_open_reference(self): + res = super().action_open_reference() + source = self.production_id or self.raw_material_production_id + if source and source.check_access_rights('read', raise_exception=False): + return { + 'res_model': source._name, + 'type': 'ir.actions.act_window', + 'views': [[False, "form"]], + 'res_id': source.id, + } + return res diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index 430c3cb1669..4b6f8d80499 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -2122,3 +2122,22 @@ class StockMove(models.Model): result[out] = (-remaining, False) return result + + def action_open_reference(self): + """ Open the form view of the move's reference document, if one exists, otherwise open form view of self + """ + self.ensure_one() + source = self.picking_id + if source and source.check_access_rights('read', raise_exception=False): + return { + 'res_model': source._name, + 'type': 'ir.actions.act_window', + 'views': [[False, "form"]], + 'res_id': source.id, + } + return { + 'res_model': self._name, + 'type': 'ir.actions.act_window', + 'views': [[False, "form"]], + 'res_id': self.id, + } diff --git a/addons/stock/models/stock_move_line.py b/addons/stock/models/stock_move_line.py index 94022f89352..f617d529493 100644 --- a/addons/stock/models/stock_move_line.py +++ b/addons/stock/models/stock_move_line.py @@ -847,3 +847,16 @@ class StockMoveLine(models.Model): 'restrict_partner_id': self.picking_id.owner_id.id, 'company_id': self.picking_id.company_id.id, } + + def action_open_reference(self): + self.ensure_one() + if self.move_id: + action = self.move_id.action_open_reference() + if action['res_model'] != 'stock.move': + return action + return { + 'res_model': self._name, + 'type': 'ir.actions.act_window', + 'views': [[False, "form"]], + 'res_id': self.id, + } diff --git a/addons/stock/views/stock_move_line_views.xml b/addons/stock/views/stock_move_line_views.xml index e3ef1618344..98d653f6181 100644 --- a/addons/stock/views/stock_move_line_views.xml +++ b/addons/stock/views/stock_move_line_views.xml @@ -4,7 +4,7 @@ stock.move.line.tree stock.move.line - + diff --git a/addons/stock_account/models/stock_valuation_layer.py b/addons/stock_account/models/stock_valuation_layer.py index 3a1f11b25fe..6bbf9d2bfa6 100644 --- a/addons/stock_account/models/stock_valuation_layer.py +++ b/addons/stock_account/models/stock_valuation_layer.py @@ -62,3 +62,16 @@ class StockValuationLayer(models.Model): if 'unit_cost' in fields: fields.remove('unit_cost') return super().read_group(domain, fields, groupby, offset, limit, orderby, lazy) + + def action_open_reference(self): + self.ensure_one() + if self.stock_move_id: + action = self.move_id.action_open_reference() + if action['res_model'] != 'stock.move': + return action + return { + 'res_model': self._name, + 'type': 'ir.actions.act_window', + 'views': [[False, "form"]], + 'res_id': self.id, + } diff --git a/addons/stock_account/views/stock_valuation_layer_views.xml b/addons/stock_account/views/stock_valuation_layer_views.xml index e7b5ac77496..4e6697e8427 100644 --- a/addons/stock_account/views/stock_valuation_layer_views.xml +++ b/addons/stock_account/views/stock_valuation_layer_views.xml @@ -42,7 +42,8 @@ stock.valuation.layer + import="0" js_class="inventory_report_list" + action="action_open_reference" type="object">