From 09a24296339e0c7609459be5ed180e8f22bb730b Mon Sep 17 00:00:00 2001 From: sbejaoui Date: Tue, 25 Feb 2020 15:13:23 +0100 Subject: [PATCH] [IMP] - Improve UX, open contract form if the sale order is related to one (same for contract) --- product_contract/models/contract.py | 6 +++++- product_contract/models/sale_order.py | 11 +++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/product_contract/models/contract.py b/product_contract/models/contract.py index e7aeb5b3d..df5d87601 100644 --- a/product_contract/models/contract.py +++ b/product_contract/models/contract.py @@ -30,10 +30,14 @@ class ContractContract(models.Model): orders = self.contract_line_ids.mapped( 'sale_order_line_id.order_id' ) - return { + action = { "name": _("Sales Orders"), "view_mode": "tree,form", "res_model": "sale.order", "type": "ir.actions.act_window", "domain": [("id", "in", orders.ids)], } + if len(orders) == 1: + # If there is only one order, open it directly + action.update({'view_mode': "form", "res_id": orders.id}) + return action diff --git a/product_contract/models/sale_order.py b/product_contract/models/sale_order.py index 949c45e36..4331d8079 100644 --- a/product_contract/models/sale_order.py +++ b/product_contract/models/sale_order.py @@ -119,4 +119,15 @@ class SaleOrder(models.Model): .mapped('contract_id') ) action["domain"] = [("id", "in", contracts.ids)] + if len(contracts) == 1: + # If there is only one contract, open it directly + action.update( + { + "res_id": contracts.id, + "view_mode": "form", + "views": filter( + lambda view: view[1] == 'form', action['views'] + ), + } + ) return action