Skip to Content

How to force the user to complete the "Loss reason" when marking a task as Lost in Odoo

Show your users custom forms in pop-up windows within Odoo to collect key data at the right moment, without programming.
July 3, 2025 by
How to force the user to complete the "Loss reason" when marking a task as Lost in Odoo
Wilfredo Fernando Pastor Avila
| No comments yet

🎯 How to force the user to complete the "Loss reason" when marking a task as Lost in Odoo

In many Odoo implementations, especially in sales or after-sales workflows, there are stages where it is crucial for the user to state why an opportunity or task was lost. However, Odoo does not force this field to be filled in, which can leave data incomplete.

In this article I will show you how, when moving a task to the "Lost" stage, a pop-up window can automatically open asking the user to complete the Loss reason field. We achieve this without developing modules, using only:

  • Odoo Studio
  • A custom view
  • A server action
  • A button to control the flow

🧩 The problem

Your team is marking tasks as "Lost" but not completing the Loss reason field. Someone forgets, another leaves it for later... and in the end the reports are empty.

We want that when the task is moved to "Lost", Odoo opens a window that requires the field to be completed before continuing.

🔧 Step 1: Create the custom view with the required field

  1. Activate developer mode
  2. Go to Settings > Technical > Views
  3. Create a new view of type form
  4. Associate the view with the project.task model
  5. Paste the following XML content:
<form string="Loss reason">
    <sheet>
        <group>
            <field name="x_studio_motivo_perdida"/>
        </group>
    </sheet>
</form>

💡 Save it and note the internal ID of the view (for example, 2230).

🖱️ Step 2: Create a button with Odoo Studio

  • Open the task form
  • Activate Odoo Studio
  • Add a new button (for example: “Mark as Lost”)
  • Link it to a server action that we will create next

⚙️ Step 3: Create the server action that opens the modal

From Settings > Technical > Actions > Server Actions, create a new action on the project.task model with the following code:

if not record.x_studio_motivo_perdida:
    action = {
        'type': 'ir.actions.act_window',
        'name': 'Complete the Loss Reason',
        'res_model': 'project.task',
        'res_id': record.id,
        'view_mode': 'form',
        'views': [(2230, 'form')],
        'target': 'new',
        'context': {
            'force_edit': True
        }
    }

record.write({
    'stage_id': env.ref('name_of_lost_stage_xml_id').id,
    'state': '1_done'
})

✔️ Replace name_of_lost_stage_xml_id with the actual External ID of the "Lost" stage.

🛑 Be careful!

  • If you use recurring tasks, make sure the Loss reason field has copy=False so it is not inherited
  • This flow should be used through a button, not by changing the stage directly from the kanban

✅ Result

Now, when the user clicks the "Mark as Lost" button, Odoo will check whether the field is empty. If it is, it will open the pop-up window with your custom form. Once completed, the task will be updated to the "Lost" stage and to the state 1_done.

💡 Conclusion

This type of micro-interaction raises the quality of the sales workflow in Odoo. Requiring users to complete key data without interrupting the process too much is possible thanks to the combined use of custom views, server actions and Odoo Studio.

🔗 Want to see how this type of pop-up window is built from scratch?

Read our article: “How to Open a Custom Form in a Modal Window in Odoo” to learn the general reusable pattern.

How to force the user to complete the "Loss reason" when marking a task as Lost in Odoo
Wilfredo Fernando Pastor Avila July 3, 2025
Share this post
Archive
Sign in to leave a comment
Odoo Hacks: 4 keyboard shortcuts to manage tasks
Manage projects like a true professional