From db978e36092c5a3ea0cd4f868ed0a2a82462a4bf Mon Sep 17 00:00:00 2001 From: Arnold Moyaux Date: Wed, 18 Mar 2020 09:48:02 +0000 Subject: [PATCH] [IMP] stock: product view usability Route diagram directly open with a single warehouse and variant. Move fields and group to have a cleaner view. Task: 2161378 --- addons/stock/models/product.py | 17 +++++++++++++++++ addons/stock/views/product_views.xml | 27 ++++++++++++++++++++------- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/addons/stock/models/product.py b/addons/stock/models/product.py index 42f9aff225b..e80aa0e6aea 100644 --- a/addons/stock/models/product.py +++ b/addons/stock/models/product.py @@ -785,6 +785,23 @@ class ProductTemplate(models.Model): }) return action + def action_open_routes_diagram(self): + products = False + if self.env.context.get('default_product_id'): + products = self.env['product.product'].browse(self.env.context['default_product_id']) + if not products and self.env.context.get('default_product_tmpl_id'): + products = self.env['product.template'].browse(self.env.context['default_product_tmpl_id']).product_variant_ids + if not self.user_has_groups('stock.group_stock_multi_warehouses') and len(products) == 1: + company = products.company_id or self.env.company + warehouse = self.env['stock.warehouse'].search([('company_id', '=', company.id)], limit=1) + return self.env.ref('stock.action_report_stock_rule').report_action(None, data={ + 'product_id': products.id, + 'warehouse_ids': warehouse.ids, + }) + action = self.env.ref('stock.action_stock_rules_report').read()[0] + action['context'] = self.env.context + return action + def action_product_tmpl_forecast_report(self): action = self.env.ref('stock.report_stock_quantity_action_product').read()[0] product_ids = self.with_context(active_test=False).product_variant_ids.filtered(lambda p: p.virtual_available != 0) diff --git a/addons/stock/views/product_views.xml b/addons/stock/views/product_views.xml index 97d9df3b7da..58d41d245a8 100644 --- a/addons/stock/views/product_views.xml +++ b/addons/stock/views/product_views.xml @@ -23,6 +23,15 @@ + + Routes + + code + + action = model.action_open_routes_diagram() + + + product.stock.tree.inherit product.product @@ -94,21 +103,25 @@ product.template + + + + @@ -270,7 +283,7 @@ attrs="{'invisible': [('type', '=', 'service')]}" context="{'invisible_handle': True, 'single_product': True}"/> - + {'default_product_id': id} @@ -369,7 +382,7 @@ {'invisible': [('type', 'not in', ['product', 'consu'])]} - +