From e4988b70ab859539d01d907b029bfaf50845625a Mon Sep 17 00:00:00 2001 From: "Tiffany Chang (tic)" Date: Thu, 18 Aug 2022 13:07:14 +0000 Subject: [PATCH] [IMP] stock{_account}: add reference opening magic in list view The move line form view is too technical for the average user so instead we can to auto-magically open the reference document instead (picking or MO only for now). We do the same with stock valuation layers as well, but this feature will not be available until its custom JS is converted to OWL "product moves" part of b2b task: 2882539 closes odoo/odoo#97109 Related: odoo/enterprise#29974 Related: odoo/upgrade#3819 Signed-off-by: Arnold Moyaux (arm) --- addons/mrp/models/stock_move.py | 12 ++++++++++++ addons/stock/models/stock_move.py | 19 +++++++++++++++++++ addons/stock/models/stock_move_line.py | 13 +++++++++++++ addons/stock/views/stock_move_line_views.xml | 2 +- .../models/stock_valuation_layer.py | 13 +++++++++++++ .../views/stock_valuation_layer_views.xml | 3 ++- 6 files changed, 60 insertions(+), 2 deletions(-) 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">