Odoo Help


3 Answers

Muhammad Anees Saudi Arabia

--Muhammad Anees--

| 7 3 8
Riyadh, Saudi Arabia
--Muhammad Anees--

Odoo, Dynamics AX and Web Developer.

Muhammad Anees Saudi Arabia
7/8/19, 2:17 PM

Thanks @Niyas and @Mihran,

How to add new value in state field which is in hr.leave model? 
Here is code state = fields.Selection(selection_add=[('validate_substitute', 'Substitute Approval')]) but it is adding at the end of statusbar but need after draft value.

Here is my view code


Muhammad Anees Saudi Arabia
7/8/19, 3:34 PM


<record id="hr_leave_form_inherit" model="ir.ui.view">

<field name="name">Leave Form Custom</field>

<field name="model">hr.leave</field>

<field name="inherit_id" ref="hr_holidays.hr_leave_view_form"/>

<field name="arch" type="xml">

<field name="name" position="before">

<field name="substitute_employee_id" />


<!-- Statusbar widget with the new status -->

<xpath expr="//field[@name='state']" position="replace">

<field name="state" widget="statusbar" statusbar_visible="confirm,validate_substitute,validate"/>


<!-- Add New Button -->

<xpath expr="/form/header/button[@name='action_confirm']" position="after">

<button name="action_validate_substitute" states="confirm" string="Substitute Approval" class="oe_highlight" type="object"/>

<button string="Approve" name="action_approve" type="object" class="oe_highlight" attrs="{'invisible': ['|', ('can_approve', '=', False), ('state', '!=', 'validate_substitute')]}"/>





But it is not appearing in order.. What is want

1) Draft

2) After Confirm

3) Substitute Approval

4) Then rest as standard

Mihran Thalhath India
7/9/19, 3:56 AM


Instead of using selection_add try using selection and replace all the states

Muhammad Anees Saudi Arabia
7/9/19, 9:10 AM


How to know that only the substitute employee should approve this leave?

Means the new Substitute Approval button in the header should be visible to Substitute Employee only.


Muhammad Anees Saudi Arabia
7/9/19, 11:40 AM


One more question along with the above one.

Now the workflow state is validate_substitute (the new state I added) and when I click the Approve button, its giving me following odoo error "Leave request must be confirmed ("To Approve") in order to approve it."

While state validate_substitute comes after confirm.

What could be the reason?


Muhammad Anees Saudi Arabia
7/15/19, 7:55 AM

Hii @Niyas Raphy and @Mihran Thalhath

How to handel above two questions.



Mihran Thalhath India

--Mihran Thalhath--
| 3 2 7
Calicut, India
--Mihran Thalhath--

LinkedIn - https://www.linkedin.com/in/mihran-thalhath-020157170 GitHub - https://github.com/mihranz7

Mihran Thalhath India
7/8/19, 12:41 PM

Hi Anees,

1. Inherit 'hr.leave' and add new substitute_employee_id field which is many2one field to hr.employee.
2. When a user selects a substitute employee and saves the request, send an email notification to the substitute employee.
3. The state of the leave request should now move to new one, which preferably should be a new one you added. The create function should help you with this state change.
4. Now add a new button in the header which is visible for the substitute employee. This button should change the state to confirm. From there on it should be your default Odoo workflow.

You can get the format for sending emails and adding buttons from Niyas' answer. If you have any doubt feel free to ask.


Niyas Raphy India

--Niyas Raphy--
| 7 7 11
Wayanad, Kerala, India
--Niyas Raphy--

Odoo Techno Functionalist

Feel free to connect :  niyasraphyk@gmail.com

LinkedIn: https://www.linkedin.com/in/niyasraphy/
Whatsapp : +917736136763
Happy to help :)

Niyas Raphy India
7/8/19, 11:02 AM


For this first of all you have to add a new field for adding/specifying the substitute employee in the leave request form. For inheriting and adding new field to an existing view, please read this blog:  How to Add Custom Fields to Existing Views in Odoo v12

Regarding the approval from the substitute employee you have to alter the current work flow and add a new button for that purpose, to see the working of the workflow, see :  How to Define Header, Statusbar, and Buttons

And for sending the Email from code: Finding and sending e-mail templates


Ask a Question
Keep Informed
1 follower(s)
About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now