Skip to Content
Menu
This question has been flagged

​I have check in and check out button in portal header , my need is that, default hide the check out button, after  clicking the check in button it will show the check out button and hide the check in . Based on my code i get that when i click the check in button the page will reload again and the check in button remain the same . How i solve this, am using odoo 16 Community.Here is my code.

XML:




XML code in the comment box







Js:


odoo.define('check_in_out.checked', function (require) {
"use strict";

var ajax = require('web.ajax');

$(document).ready(function() {
$('.check-in-btn').click(function() {
$(this).hide();
$('.check-out-btn').show();
});

$('.check-out-btn').click(function() {
$(this).hide();
$('.check-in-btn').show();
});
});
});


Thanks

Avatar
Discard
Author

<template id="portal_layout" inherit_id="website.template_header_default"
name="Attendance Button">
<xpath expr="//t[@t-call='portal.user_dropdown']" position="after">
<a class="btn btn-primary check-in-btn" href="/attendance/checkin"
id="check_in">Check In
</a>
<a class="btn btn-primary check-out-btn" href="/attendance/checkout"
id="check_out" style="display: none;">Check Out
</a>
</xpath>
</template>

Best Answer

You can achieve this without using js , please update your code like this, this may help you,

<template id="portal_layout" inherit_id="website.template_header_default"
          name="Attendance Button">
    <xpath expr="//t[@t-call='portal.user_dropdown']" position="after">
        <a class="btn btn-primary check-in-btn" href="/attendance/checkin"
           id="check_in" t-if="request.env['hr.employee'].search([('user_id', '=', request.env.user.id)]).attendance_state == 'checked_out'">Check In
        </a>
        <a class="btn btn-primary check-out-btn" href="/attendance/checkout"
           id="check_out" t-if="request.env['hr.employee'].search([('user_id', '=', request.env.user.id)]).attendance_state == 'checked_in'">Check Out
        </a>
    </xpath>
</template>


Hope it helps

Avatar
Discard
Related Posts Replies Views Activity
2
Apr 24
1388
0
Feb 23
1911
1
May 25
1343
2
Jun 24
1740
0
Dec 23
1832