[IMP] - Improve UX, open contract form if the sale order is related to one (same for contract)

This commit is contained in:
sbejaoui
2020-02-25 15:13:23 +01:00
committed by Denis Roussel
parent ad7434ad13
commit 09a2429633
2 changed files with 16 additions and 1 deletions

View File

@@ -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

View File

@@ -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