mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
Merge branch 'mig/13.0/hr_payroll_attendance' into '13.0'
mig/13.0/hr_payroll_attendance into 13.0 See merge request hibou-io/hibou-odoo/suite!405
This commit is contained in:
15
hr_attendance_work_entry/__init__.py
Normal file
15
hr_attendance_work_entry/__init__.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from . import models
|
||||
|
||||
|
||||
def attn_payroll_pre_init_hook(cr):
|
||||
"""
|
||||
This module installs a Work Entry Type with code "ATTN"
|
||||
If you have undergone a migration (either for this module
|
||||
or even your own Payslip Work Entry lines with code "ATTN")
|
||||
then the uniqueness constraint will prevent this module
|
||||
from installing.
|
||||
"""
|
||||
cr.execute("UPDATE hr_work_entry_type "
|
||||
"SET code = 'ATTN-PRE-INSTALL' "
|
||||
"WHERE code = 'ATTN';"
|
||||
)
|
||||
27
hr_attendance_work_entry/__manifest__.py
Executable file
27
hr_attendance_work_entry/__manifest__.py
Executable file
@@ -0,0 +1,27 @@
|
||||
{
|
||||
'name': 'Attendance Work Entry Type',
|
||||
'description': 'Set work types on attendance records.',
|
||||
'version': '13.0.1.0.0',
|
||||
'website': 'https://hibou.io/',
|
||||
'author': 'Hibou Corp. <hello@hibou.io>',
|
||||
'license': 'AGPL-3',
|
||||
'category': 'Human Resources',
|
||||
'depends': [
|
||||
'hr_attendance',
|
||||
'hr_work_entry',
|
||||
],
|
||||
'data': [
|
||||
'data/hr_attendance_work_entry_data.xml',
|
||||
'views/attendance_views.xml',
|
||||
'views/employee_views.xml',
|
||||
'views/web_assets.xml',
|
||||
'views/work_entry_views.xml',
|
||||
],
|
||||
'demo': [
|
||||
'data/hr_attendance_work_entry_demo.xml',
|
||||
],
|
||||
'qweb': [
|
||||
'static/src/xml/hr_attendance.xml',
|
||||
],
|
||||
'pre_init_hook': 'attn_payroll_pre_init_hook',
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
|
||||
<record id="work_input_attendance" model="hr.work.entry.type">
|
||||
<field name="name">Attendance</field>
|
||||
<field name="code">ATTN</field>
|
||||
<field name="allow_attendance" eval="True"/>
|
||||
<field name="attendance_state">checked_in</field>
|
||||
<field name="attendance_icon">fa-sign-in</field>
|
||||
</record>
|
||||
|
||||
<!-- Rename Stock "Attendance" type -->
|
||||
<record id="hr_work_entry.work_entry_type_attendance" model="hr.work.entry.type">
|
||||
<field name="name">Work Calendar</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
|
||||
<record id="work_input_attendance_break" model="hr.work.entry.type">
|
||||
<field name="name">Break</field>
|
||||
<field name="code">ATTN_BREAK</field>
|
||||
<field name="allow_attendance" eval="True"/>
|
||||
<field name="attendance_state">break</field>
|
||||
<field name="attendance_icon">fa-hourglass-1</field>
|
||||
</record>
|
||||
|
||||
<record id="work_input_attendance_lunch" model="hr.work.entry.type">
|
||||
<field name="name">Lunch</field>
|
||||
<field name="code">ATTN_LUNCH</field>
|
||||
<field name="allow_attendance" eval="True"/>
|
||||
<field name="attendance_state">lunch</field>
|
||||
<field name="attendance_icon">fa-coffee</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
3
hr_attendance_work_entry/models/__init__.py
Normal file
3
hr_attendance_work_entry/models/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from . import attendance
|
||||
from . import employee
|
||||
from . import work_entry
|
||||
14
hr_attendance_work_entry/models/attendance.py
Normal file
14
hr_attendance_work_entry/models/attendance.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class HrAttendance(models.Model):
|
||||
_inherit = 'hr.attendance'
|
||||
|
||||
work_type_id = fields.Many2one('hr.work.entry.type', string='Work Type',
|
||||
default=lambda self: self.env.ref('hr_attendance_work_entry.work_input_attendance',
|
||||
raise_if_not_found=False))
|
||||
|
||||
@api.model
|
||||
def gather_attendance_work_types(self):
|
||||
work_types = self.env['hr.work.entry.type'].sudo().search([('allow_attendance', '=', True)])
|
||||
return work_types.read(['id', 'name', 'attendance_icon'])
|
||||
61
hr_attendance_work_entry/models/employee.py
Normal file
61
hr_attendance_work_entry/models/employee.py
Normal file
@@ -0,0 +1,61 @@
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
|
||||
class HrEmployee(models.Model):
|
||||
_inherit = 'hr.employee'
|
||||
|
||||
attendance_state = fields.Selection(selection_add=[('break', 'Break'), ('lunch', 'Lunch')])
|
||||
|
||||
@api.depends('last_attendance_id.work_type_id')
|
||||
def _compute_attendance_state(self):
|
||||
for employee in self:
|
||||
att = employee.last_attendance_id.sudo()
|
||||
if not att or att.check_out:
|
||||
employee.attendance_state = 'checked_out'
|
||||
elif employee.last_attendance_id.work_type_id.attendance_state:
|
||||
employee.attendance_state = employee.last_attendance_id.work_type_id.attendance_state
|
||||
else:
|
||||
employee.attendance_state = 'checked_in'
|
||||
|
||||
def attendance_manual(self, next_action, entered_pin=None, work_type_id=None):
|
||||
self = self.with_context(work_type_id=work_type_id)
|
||||
if not entered_pin:
|
||||
# fix for pin mode with specific argument order for work_type_id
|
||||
entered_pin = None
|
||||
return super(HrEmployee, self).attendance_manual(next_action, entered_pin=entered_pin)
|
||||
|
||||
def _attendance_action_change(self):
|
||||
""" Check In/Check Out action
|
||||
Check In: create a new attendance record
|
||||
Check Out: modify check_out field of appropriate attendance record
|
||||
"""
|
||||
self.ensure_one()
|
||||
action_date = fields.Datetime.now()
|
||||
work_type_id = self._context.get('work_type_id', False)
|
||||
|
||||
if self.attendance_state == 'checked_out':
|
||||
vals = {
|
||||
'employee_id': self.id,
|
||||
'check_in': action_date,
|
||||
}
|
||||
if work_type_id:
|
||||
# if we don't have a work_type_id, we want the default
|
||||
vals['work_type_id'] = work_type_id
|
||||
return self.env['hr.attendance'].create(vals)
|
||||
attendance = self.env['hr.attendance'].search([('employee_id', '=', self.id), ('check_out', '=', False)], limit=1)
|
||||
if attendance and work_type_id:
|
||||
# work_type_id is the "next" attendance type
|
||||
attendance.check_out = action_date
|
||||
vals = {
|
||||
'employee_id': self.id,
|
||||
'check_in': action_date,
|
||||
'work_type_id': work_type_id,
|
||||
}
|
||||
return self.env['hr.attendance'].create(vals)
|
||||
if attendance:
|
||||
attendance.check_out = action_date
|
||||
else:
|
||||
raise UserError(_('Cannot perform check out on %(empl_name)s, could not find corresponding check in. '
|
||||
'Your attendances have probably been modified manually by human resources.') % {'empl_name': self.sudo().name, })
|
||||
return attendance
|
||||
15
hr_attendance_work_entry/models/work_entry.py
Normal file
15
hr_attendance_work_entry/models/work_entry.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class HrWorkEntryType(models.Model):
|
||||
_inherit = 'hr.work.entry.type'
|
||||
_order = 'sequence, id'
|
||||
|
||||
allow_attendance = fields.Boolean(string='Allow in Attendance')
|
||||
attendance_icon = fields.Char(string='Attendance Icon', default='fa-sign-in')
|
||||
attendance_state = fields.Selection([
|
||||
# ('checked_out', "Checked out"), # reserved for detecting new punch in
|
||||
('checked_in', "Checked in"),
|
||||
('break', 'Break'),
|
||||
('lunch', 'Lunch'),
|
||||
], string='Attendance State', default='checked_in')
|
||||
71
hr_attendance_work_entry/static/src/js/kiosk_confirm.js
Normal file
71
hr_attendance_work_entry/static/src/js/kiosk_confirm.js
Normal file
@@ -0,0 +1,71 @@
|
||||
odoo.define('hr_attendance_work_entry.kiosk_confirm', function (require) {
|
||||
"use strict";
|
||||
|
||||
var core = require('web.core');
|
||||
var KioskConfirm = require('hr_attendance.kiosk_confirm');
|
||||
var KioskConfirmTyped = KioskConfirm.extend({
|
||||
events: _.extend({}, KioskConfirm.prototype.events, {
|
||||
"click .o_hr_attendance_punch_type": _.debounce(function(e) {
|
||||
var work_entry_type = $(e.target).data('work-entry-type');
|
||||
this.update_attendance(work_entry_type);
|
||||
}, 200, true),
|
||||
"click .o_hr_attendance_pin_pad_button_work": _.debounce(function(e) {
|
||||
var work_entry_type = $(e.target).data('work-entry-type');
|
||||
this.update_attendance_pin(work_entry_type);
|
||||
}, 200, true),
|
||||
}),
|
||||
willStart: function () {
|
||||
var self = this;
|
||||
|
||||
var def = this._rpc({
|
||||
model: 'hr.attendance',
|
||||
method: 'gather_attendance_work_types',
|
||||
args: []})
|
||||
.then(function (res) {
|
||||
self.work_types = res;
|
||||
});
|
||||
|
||||
return Promise.all([def, this._super.apply(this, arguments)]);
|
||||
},
|
||||
update_attendance: function (type) {
|
||||
var self = this;
|
||||
this._rpc({
|
||||
model: 'hr.employee',
|
||||
method: 'attendance_manual',
|
||||
args: [[self.employee_id], this.next_action, false, type],
|
||||
})
|
||||
.then(function(result) {
|
||||
if (result.action) {
|
||||
self.do_action(result.action);
|
||||
} else if (result.warning) {
|
||||
self.do_warn(result.warning);
|
||||
}
|
||||
});
|
||||
},
|
||||
update_attendance_pin: function (type) {
|
||||
var self = this;
|
||||
this.$('.o_hr_attendance_pin_pad_button_ok').attr("disabled", "disabled");
|
||||
this.$('.o_hr_attendance_pin_pad_button_work').attr("disabled", "disabled");
|
||||
this._rpc({
|
||||
model: 'hr.employee',
|
||||
method: 'attendance_manual',
|
||||
args: [[this.employee_id], this.next_action, this.$('.o_hr_attendance_PINbox').val(), type],
|
||||
})
|
||||
.then(function(result) {
|
||||
if (result.action) {
|
||||
self.do_action(result.action);
|
||||
} else if (result.warning) {
|
||||
self.do_warn(result.warning);
|
||||
self.$('.o_hr_attendance_PINbox').val('');
|
||||
setTimeout( function() {
|
||||
self.$('.o_hr_attendance_pin_pad_button_ok').removeAttr("disabled");
|
||||
self.$('.o_hr_attendance_pin_pad_button_work').removeAttr("disabled");
|
||||
}, 500);
|
||||
}
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
core.action_registry.add('hr_attendance_kiosk_confirm', KioskConfirmTyped);
|
||||
return KioskConfirmTyped;
|
||||
});
|
||||
50
hr_attendance_work_entry/static/src/js/my_attendances.js
Normal file
50
hr_attendance_work_entry/static/src/js/my_attendances.js
Normal file
@@ -0,0 +1,50 @@
|
||||
odoo.define('hr_attendance_work_entry.my_attendances', function (require) {
|
||||
"use strict";
|
||||
|
||||
var core = require('web.core');
|
||||
var MyAttendances = require('hr_attendance.my_attendances');
|
||||
|
||||
var MyTypedAttendances = MyAttendances.extend({
|
||||
events: _.extend({}, MyAttendances.prototype.events, {
|
||||
"click .o_hr_attendance_punch_type": _.debounce(function(e) {
|
||||
var work_entry_type = $(e.target).data('work-entry-type');
|
||||
this.update_attendance(work_entry_type);
|
||||
}, 200, true),
|
||||
}),
|
||||
|
||||
willStart: function () {
|
||||
var self = this;
|
||||
|
||||
var def = this._rpc({
|
||||
model: 'hr.attendance',
|
||||
method: 'gather_attendance_work_types',
|
||||
args: []})
|
||||
.then(function (res) {
|
||||
self.work_types = res;
|
||||
});
|
||||
|
||||
return Promise.all([def, this._super.apply(this, arguments)]);
|
||||
},
|
||||
|
||||
update_attendance: function (type) {
|
||||
var self = this;
|
||||
this._rpc({
|
||||
model: 'hr.employee',
|
||||
method: 'attendance_manual',
|
||||
args: [[self.employee.id], 'hr_attendance.hr_attendance_action_my_attendances', false, type],
|
||||
})
|
||||
.then(function(result) {
|
||||
if (result.action) {
|
||||
self.do_action(result.action);
|
||||
} else if (result.warning) {
|
||||
self.do_warn(result.warning);
|
||||
}
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
core.action_registry.add('hr_attendance_my_attendances', MyTypedAttendances);
|
||||
|
||||
return MyTypedAttendances;
|
||||
|
||||
});
|
||||
31
hr_attendance_work_entry/static/src/scss/hr_attendances.scss
Normal file
31
hr_attendance_work_entry/static/src/scss/hr_attendances.scss
Normal file
@@ -0,0 +1,31 @@
|
||||
.o_hr_attendance_sign_in_out_icon {
|
||||
cursor: pointer;
|
||||
border-radius: .1em;
|
||||
box-shadow: inset 0 -3px 0 fade-out(black, 0.7);
|
||||
|
||||
&.btn-secondary:hover {
|
||||
color: $o-brand-primary;
|
||||
}
|
||||
}
|
||||
|
||||
#oe_hr_attendance_status {
|
||||
color: $o-brand-secondary;
|
||||
|
||||
&.oe_hr_attendance_status_blue {
|
||||
color: theme-color('info');
|
||||
}
|
||||
|
||||
&.oe_hr_attendance_status_orange {
|
||||
color: theme-color('warning');
|
||||
}
|
||||
}
|
||||
|
||||
.o_hr_attendance_kiosk_mode p.o_hr_attendance_continue {
|
||||
margin-bottom: 0;
|
||||
text-align: center;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.o_hr_attendance_pin_pad_button_work {
|
||||
font-size: 0.9em;
|
||||
}
|
||||
134
hr_attendance_work_entry/static/src/xml/hr_attendance.xml
Normal file
134
hr_attendance_work_entry/static/src/xml/hr_attendance.xml
Normal file
@@ -0,0 +1,134 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<templates xml:space="preserve">
|
||||
<t t-extend="HrAttendanceMyMainMenu">
|
||||
<t t-jquery=".o_hr_attendance_kiosk_mode" t-operation="replace">
|
||||
|
||||
<div class="o_hr_attendance_kiosk_mode">
|
||||
<t t-set="checked_in" t-value="widget.employee.attendance_state=='checked_in'"/>
|
||||
<t t-set="checked_out" t-value="widget.employee.attendance_state=='checked_out'"/>
|
||||
<t t-if="widget.employee">
|
||||
<div class="o_hr_attendance_user_badge o_home_menu_background">
|
||||
<img class="img rounded-circle"
|
||||
t-attf-src="/web/image?model=hr.employee&field=image_128&id=#{widget.employee.id}"
|
||||
t-att-title="widget.employee.name" t-att-alt="widget.employee.name"/>
|
||||
</div>
|
||||
<h1 class="mb8"><t t-esc="widget.employee.name"/></h1>
|
||||
<h3 class="mt8 mb24"><t t-if="!checked_in">Welcome!</t>
|
||||
<t t-else="">Want to check out?</t></h3>
|
||||
<h4 class="mt0 mb0 text-muted" t-if="checked_in">Today's work hours: <span
|
||||
t-esc="widget.hours_today"/></h4>
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
|
||||
<div id="kiosk_action_container" class="col-md-12 kiosk_action_container">
|
||||
<!-- SIGN OUT OF CURRENT PUNCH TYPES -->
|
||||
<a t-if="!checked_out" class="btn btn-secondary btn-block btn-warning o_hr_attendance_sign_in_out_icon"
|
||||
aria-label="Sign out" title="Sign out">
|
||||
<i class="fa fa-1x fa-sign-out mr-1 mt-3 mb-3"></i>
|
||||
<span>
|
||||
<b>Stop</b>
|
||||
</span>
|
||||
</a>
|
||||
|
||||
<p t-if="!checked_out" class="o_hr_attendance_continue">
|
||||
Or, continue working as:
|
||||
</p>
|
||||
|
||||
<t t-foreach="widget.work_types" t-as="work_type">
|
||||
<a class="btn btn-block btn-secondary o_hr_attendance_punch_type mt-2 mb-2"
|
||||
aria-label="Sign in" title="Sign in" t-attf-data-work-entry-type="#{work_type.id}">
|
||||
<i t-attf-class="fa #{work_type.attendance_icon} fa-1x mr-1 mt-3 mb-3"> </i>
|
||||
<span t-esc="work_type.name"/>
|
||||
</a>
|
||||
</t>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</t>
|
||||
<t t-else="">
|
||||
Warning : Your user should be linked to an employee to use attendance. Please contact your administrator.
|
||||
</t>
|
||||
</div>
|
||||
|
||||
</t>
|
||||
</t>
|
||||
|
||||
<t t-extend="HrAttendanceKioskConfirm">
|
||||
<t t-jquery=".o_hr_attendance_kiosk_mode" t-operation="replace">
|
||||
<div class="o_hr_attendance_kiosk_mode">
|
||||
<t t-set="checked_in" t-value="widget.employee_state=='checked_in'"/>
|
||||
<t t-set="checked_out" t-value="widget.employee_state=='checked_out'"/>
|
||||
<div class="o_hr_attendance_back_button">
|
||||
<span class="btn btn-secondary btn-lg d-block d-md-none"><i class="fa fa-chevron-left mr8"/> Go back</span>
|
||||
<span class="btn btn-secondary d-none d-md-inline-block"><i class="fa fa-chevron-left" role="img" aria-label="Go back" title="Go back"/></span>
|
||||
</div>
|
||||
<t t-if="widget.employee_id">
|
||||
<div class="o_hr_attendance_user_badge o_home_menu_background">
|
||||
<img class="img rounded-circle" t-attf-src="/web/image?model=hr.employee&field=image_128&id=#{widget.employee_id}" t-att-title="widget.employee_name" t-att-alt="widget.employee_name"/>
|
||||
</div>
|
||||
<h1 class="mb8"><t t-esc="widget.employee_name"/></h1>
|
||||
<h3 class="mt8 mb24"><t t-if="!checked_in">Welcome! </t><t t-else="">Want to check out?</t></h3>
|
||||
<h4 class="mt0 mb0 text-muted" t-if="checked_in">Today's work hours: <span t-esc="widget.employee_hours_today"/></h4>
|
||||
<t t-if="!widget.use_pin">
|
||||
<div id="kiosk_action_container" class="col-md-12 kiosk_action_container">
|
||||
<!-- SIGN OUT OF CURRENT PUNCH TYPES -->
|
||||
<a t-if="!checked_out" class="btn btn-secondary btn-block btn-warning o_hr_attendance_sign_in_out_icon"
|
||||
aria-label="Sign out" title="Sign out">
|
||||
<i class="fa fa-1x fa-sign-out mr-1 mt-3 mb-3"></i>
|
||||
<span>
|
||||
<b>Stop</b>
|
||||
</span>
|
||||
</a>
|
||||
|
||||
<p t-if="!checked_out" class="o_hr_attendance_continue">
|
||||
Or, continue working as:
|
||||
</p>
|
||||
|
||||
<t t-foreach="widget.work_types" t-as="work_type">
|
||||
<a class="btn btn-block btn-secondary o_hr_attendance_punch_type mt-2 mb-2"
|
||||
aria-label="Sign in" title="Sign in" t-attf-data-work-entry-type="#{work_type.id}">
|
||||
<i t-attf-class="fa #{work_type.attendance_icon} fa-1x mr-1 mt-3 mb-3"> </i>
|
||||
<span t-esc="work_type.name"/>
|
||||
</a>
|
||||
</t>
|
||||
</div>
|
||||
</t>
|
||||
<t t-else="">
|
||||
<h3 class="mt0 mb0 text-muted">Please enter your PIN to <b t-if="checked_in">check out</b><b t-else="">check in</b></h3>
|
||||
<div class="row">
|
||||
<div class="col-md-8 offset-md-2 o_hr_attendance_pin_pad">
|
||||
<div class="row" >
|
||||
<div class="col-12 mb8 mt8"><input class="o_hr_attendance_PINbox text-center" type="password" disabled="true"/></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<t t-foreach="['1', '2', '3', '4', '5', '6', '7', '8', '9', ['C', 'btn-warning'], '0', ['ok', 'btn-primary']]" t-as="btn_name">
|
||||
<div class="col-4 mb4" t-if="btn_name[0] != 'ok'">
|
||||
<a t-attf-class="btn {{btn_name[1]? btn_name[1] : 'btn-secondary'}} btn-block btn-lg {{ 'o_hr_attendance_pin_pad_button_' + btn_name[0] }}"><t t-esc="btn_name[0]"/></a>
|
||||
</div>
|
||||
<t t-else="">
|
||||
<div class="col-4 mb4" t-if="!checked_out">
|
||||
<a class="btn btn-primary btn-block btn-lg o_hr_attendance_pin_pad_button_ok">Sign Out</a>
|
||||
</div>
|
||||
<div class="col-4 mb4" t-else=""/>
|
||||
<!-- ok button -->
|
||||
<div class="col-4 mb4" t-foreach="widget.work_types" t-as="work_type">
|
||||
<a href="#" class="btn btn-primary btn-block btn-lg o_hr_attendance_pin_pad_button_work small" t-attf-data-work-entry-type="#{work_type.id}"><i t-attf-class="fa fa-1x #{work_type.attendance_icon} mr-1 mt-3 mb-3"></i> <t t-esc="work_type.name"/></a>
|
||||
</div>
|
||||
</t>
|
||||
|
||||
</t>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</t>
|
||||
</t>
|
||||
<div t-else="" class="alert alert-danger" role="alert">
|
||||
<b>Error: could not find corresponding employee.</b><br/>Please return to the main menu.
|
||||
</div>
|
||||
<a role="button" class="oe_attendance_sign_in_out" aria-label="Sign out" title="Sign out"/>
|
||||
</div>
|
||||
</t>
|
||||
</t>
|
||||
|
||||
</templates>
|
||||
1
hr_attendance_work_entry/tests/__init__.py
Normal file
1
hr_attendance_work_entry/tests/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import test_attendance_work_type
|
||||
47
hr_attendance_work_entry/tests/test_attendance_work_type.py
Normal file
47
hr_attendance_work_entry/tests/test_attendance_work_type.py
Normal file
@@ -0,0 +1,47 @@
|
||||
from odoo.tests import common
|
||||
|
||||
|
||||
class TestAttendanceWorkType(common.TransactionCase):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.employee = self.env.ref('hr.employee_hne')
|
||||
self.default_work_type = self.env.ref('hr_attendance_work_entry.work_input_attendance')
|
||||
|
||||
def test_01_work_type(self):
|
||||
attendance = self.env['hr.attendance'].create({
|
||||
'employee_id': self.employee.id,
|
||||
'check_in': '2020-01-06 10:00:00', # Monday
|
||||
'check_out': '2020-01-06 19:00:00',
|
||||
})
|
||||
self.assertTrue(attendance.work_type_id)
|
||||
self.assertEqual(attendance.work_type_id, self.default_work_type)
|
||||
|
||||
def test_11_employee_clock_in(self):
|
||||
self.assertEqual(self.employee.attendance_state, 'checked_out')
|
||||
attendance = self.employee._attendance_action_change()
|
||||
self.assertEqual(attendance.work_type_id, self.default_work_type)
|
||||
self.assertEqual(self.employee.attendance_state, 'checked_in')
|
||||
|
||||
# check out
|
||||
self.employee._attendance_action_change()
|
||||
self.assertEqual(self.employee.attendance_state, 'checked_out')
|
||||
|
||||
def test_12_employee_clock_in_break(self):
|
||||
# check in with non-standard work type
|
||||
break_type = self.env['hr.work.entry.type'].create({
|
||||
'name': 'Test Break',
|
||||
'code': 'TESTBREAK',
|
||||
'allow_attendance': True,
|
||||
'attendance_state': 'break',
|
||||
})
|
||||
self.employee = self.employee.with_context(work_type_id=break_type.id)
|
||||
attendance = self.employee._attendance_action_change()
|
||||
self.assertEqual(attendance.work_type_id, break_type)
|
||||
self.assertEqual(self.employee.attendance_state, 'break')
|
||||
|
||||
# check back in immediately with default
|
||||
self.employee = self.employee.with_context(work_type_id=self.default_work_type.id)
|
||||
attendance = self.employee._attendance_action_change()
|
||||
self.assertEqual(attendance.work_type_id, self.default_work_type)
|
||||
self.assertEqual(attendance.work_type_id.attendance_state, 'checked_in')
|
||||
self.assertEqual(self.employee.attendance_state, 'checked_in')
|
||||
15
hr_attendance_work_entry/views/attendance_views.xml
Normal file
15
hr_attendance_work_entry/views/attendance_views.xml
Normal file
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
|
||||
<record id="hr_attendance_tree_inherit" model="ir.ui.view">
|
||||
<field name="name">hr.attendance.tree.inherit</field>
|
||||
<field name="model">hr.attendance</field>
|
||||
<field name="inherit_id" ref="hr_attendance.view_attendance_tree"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//tree/field[@name='worked_hours']" position="before">
|
||||
<field name="work_type_id" />
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
58
hr_attendance_work_entry/views/employee_views.xml
Normal file
58
hr_attendance_work_entry/views/employee_views.xml
Normal file
@@ -0,0 +1,58 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
|
||||
<record id="hr_kanban_view_employees_inherit" model="ir.ui.view">
|
||||
<field name="name">hr.employee.kanban.inherit</field>
|
||||
<field name="model">hr.employee</field>
|
||||
<field name="inherit_id" ref="hr.hr_kanban_view_employees"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//kanban/field[@name='hr_presence_state']" position="after">
|
||||
<field name="attendance_state"/>
|
||||
</xpath>
|
||||
<xpath expr="//strong[@class='o_kanban_record_title']/div[1]" position="before">
|
||||
<div class="float-right" t-if="record.attendance_state.raw_value == 'checked_in'">
|
||||
<span id="oe_hr_attendance_status" class="fa fa-circle oe_hr_attendance_status_green" role="img" aria-label="Available" title="Available"></span>
|
||||
</div>
|
||||
<div class="float-right" t-if="record.attendance_state.raw_value == 'checked_out'">
|
||||
<span id="oe_hr_attendance_status" class="fa fa-circle oe_hr_attendance_status_red" role="img" aria-label="Not available" title="Not available"></span>
|
||||
</div>
|
||||
<div class="float-right" t-if="record.attendance_state.raw_value == 'lunch'">
|
||||
<span id="oe_hr_attendance_status" class="fa fa-circle oe_hr_attendance_status_orange" role="img" aria-label="At Lunch" title="At Lunch"></span>
|
||||
</div>
|
||||
<div class="float-right" t-if="record.attendance_state.raw_value == 'break'">
|
||||
<span id="oe_hr_attendance_status" class="fa fa-circle oe_hr_attendance_status_blue" role="img" aria-label="On Break" title="On Break"></span>
|
||||
</div>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
<!-- employee kanban view specifically for hr_attendance (to check in/out) -->
|
||||
<record id="hr_employees_view_kanban_inherit" model="ir.ui.view">
|
||||
<field name="name">hr.employee.kanban.inherit</field>
|
||||
<field name="model">hr.employee</field>
|
||||
<field name="inherit_id" ref="hr_attendance.hr_employees_view_kanban"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//div[@id='textbox']" position="replace">
|
||||
<div id="textbox">
|
||||
<div class="float-right" t-if="record.attendance_state.raw_value == 'checked_in'">
|
||||
<span id="oe_hr_attendance_status" class="fa fa-circle oe_hr_attendance_status_green" role="img" aria-label="Available" title="Available"></span>
|
||||
</div>
|
||||
<div class="float-right" t-if="record.attendance_state.raw_value == 'checked_out'">
|
||||
<span id="oe_hr_attendance_status" class="fa fa-circle oe_hr_attendance_status_red" role="img" aria-label="Not available" title="Not available"></span>
|
||||
</div>
|
||||
<div class="float-right" t-if="record.attendance_state.raw_value == 'lunch'">
|
||||
<span id="oe_hr_attendance_status" class="fa fa-circle oe_hr_attendance_status_orange" role="img" aria-label="At Lunch" title="At Lunch"></span>
|
||||
</div>
|
||||
<div class="float-right" t-if="record.attendance_state.raw_value == 'break'">
|
||||
<span id="oe_hr_attendance_status" class="fa fa-circle oe_hr_attendance_status_blue" role="img" aria-label="On Break" title="On Break"></span>
|
||||
</div>
|
||||
<strong>
|
||||
<field name="name"/>
|
||||
</strong>
|
||||
</div>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
14
hr_attendance_work_entry/views/web_assets.xml
Normal file
14
hr_attendance_work_entry/views/web_assets.xml
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
|
||||
<template id="assets_backend" name="hr_attendance_work_entry_assets" inherit_id="web.assets_backend">
|
||||
<xpath expr="//script[last()]" position="after">
|
||||
<script type="text/javascript" src="/hr_attendance_work_entry/static/src/js/kiosk_confirm.js"/>
|
||||
<script type="text/javascript" src="/hr_attendance_work_entry/static/src/js/my_attendances.js"/>
|
||||
</xpath>
|
||||
<xpath expr="//link[last()]" position="after">
|
||||
<link rel="stylesheet" type="text/scss" href="/hr_attendance_work_entry/static/src/scss/hr_attendances.scss"/>
|
||||
</xpath>
|
||||
</template>
|
||||
|
||||
</odoo>
|
||||
36
hr_attendance_work_entry/views/work_entry_views.xml
Normal file
36
hr_attendance_work_entry/views/work_entry_views.xml
Normal file
@@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
|
||||
<record id="hr_work_entry_type_view_form_inherit" model="ir.ui.view">
|
||||
<field name="name">hr.work.type.view.form.inherit</field>
|
||||
<field name="model">hr.work.entry.type</field>
|
||||
<field name="inherit_id" ref="hr_work_entry.hr_work_entry_type_view_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//group/group" position="after">
|
||||
<group name="attendance" string="Attendance">
|
||||
<field name="allow_attendance"/>
|
||||
<field name="attendance_icon" attrs="{'invisible': [('allow_attendance', '=', False)]}" />
|
||||
<field name="attendance_state" attrs="{'invisible': [('allow_attendance', '=', False)]}" />
|
||||
</group>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="hr_work_entry_type_view_tree_inherit" model="ir.ui.view">
|
||||
<field name="name">hr.work.type.view.tree.inherit</field>
|
||||
<field name="model">hr.work.entry.type</field>
|
||||
<field name="inherit_id" ref="hr_work_entry.hr_work_entry_type_view_tree"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//tree/field[1]" position="before">
|
||||
<field name="sequence" widget="handle"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<menuitem
|
||||
id="hr_work_entry_type_menu"
|
||||
name="Work Entry Types"
|
||||
parent="hr_attendance.menu_hr_attendance_manage_attendances"
|
||||
action="hr_work_entry.hr_work_entry_type_action"/>
|
||||
|
||||
</odoo>
|
||||
15
hr_payroll_attendance/__init__.py
Executable file
15
hr_payroll_attendance/__init__.py
Executable file
@@ -0,0 +1,15 @@
|
||||
from . import models
|
||||
|
||||
|
||||
def attn_payroll_pre_init_hook(cr):
|
||||
"""
|
||||
This module installs a Work Entry Type with code "ATTN_OT"
|
||||
If you have undergone a migration (either for this module
|
||||
or even your own Payslip Work Entry lines with code "ATTN_OT")
|
||||
then the uniqueness constraint will prevent this module
|
||||
from installing.
|
||||
"""
|
||||
cr.execute("UPDATE hr_work_entry_type "
|
||||
"SET code = 'ATTN_OT-PRE-INSTALL' "
|
||||
"WHERE code = 'ATTN_OT';"
|
||||
)
|
||||
22
hr_payroll_attendance/__manifest__.py
Executable file
22
hr_payroll_attendance/__manifest__.py
Executable file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
'name': 'Attendance on Payslips',
|
||||
'description': 'Get Attendence numbers onto Employee Payslips.',
|
||||
'version': '13.0.1.0.0',
|
||||
'website': 'https://hibou.io/',
|
||||
'author': 'Hibou Corp. <hello@hibou.io>',
|
||||
'license': 'AGPL-3',
|
||||
'category': 'Human Resources',
|
||||
'data': [
|
||||
'data/hr_payroll_attendance_data.xml',
|
||||
'views/hr_attendance_views.xml',
|
||||
'views/hr_contract_views.xml',
|
||||
'views/hr_payslip_views.xml',
|
||||
],
|
||||
'depends': [
|
||||
'hr_payroll',
|
||||
'hr_attendance',
|
||||
'hr_attendance_work_entry',
|
||||
'hr_payroll_overtime',
|
||||
],
|
||||
'pre_init_hook': 'attn_payroll_pre_init_hook',
|
||||
}
|
||||
15
hr_payroll_attendance/data/hr_payroll_attendance_data.xml
Normal file
15
hr_payroll_attendance/data/hr_payroll_attendance_data.xml
Normal file
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
|
||||
<!-- Work Entry Type -->
|
||||
<record id="work_input_attendance_overtime" model="hr.work.entry.type">
|
||||
<field name="name">Attendance Overtime</field>
|
||||
<field name="code">ATTN_OT</field>
|
||||
</record>
|
||||
|
||||
<record id="hr_attendance_work_entry.work_input_attendance" model="hr.work.entry.type">
|
||||
<field name="overtime_type_id" ref="hr_payroll_overtime.work_entry_overtime_type"/>
|
||||
<field name="overtime_work_type_id" ref="work_input_attendance_overtime"/>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
@@ -0,0 +1,6 @@
|
||||
|
||||
def migrate(cr, version):
|
||||
# pre_init_hook script only runs on install,
|
||||
# if you're coming from 12.0 we need the same change
|
||||
from odoo.addons.hr_payroll_timesheet import attn_payroll_pre_init_hook
|
||||
attn_payroll_pre_init_hook(cr)
|
||||
3
hr_payroll_attendance/models/__init__.py
Normal file
3
hr_payroll_attendance/models/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from . import hr_attendance
|
||||
from . import hr_contract
|
||||
from . import hr_payslip
|
||||
12
hr_payroll_attendance/models/hr_attendance.py
Normal file
12
hr_payroll_attendance/models/hr_attendance.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class HrAttendance(models.Model):
|
||||
_inherit = 'hr.attendance'
|
||||
|
||||
payslip_id = fields.Many2one('hr.payslip', string="Payslip", readonly=True, ondelete='set null')
|
||||
|
||||
def unlink(self):
|
||||
attn_with_payslip = self.filtered(lambda a: a.payslip_id)
|
||||
attn_with_payslip.write({'payslip_id': False})
|
||||
return super(HrAttendance, self - attn_with_payslip).unlink()
|
||||
7
hr_payroll_attendance/models/hr_contract.py
Executable file
7
hr_payroll_attendance/models/hr_contract.py
Executable file
@@ -0,0 +1,7 @@
|
||||
from odoo import models, fields
|
||||
|
||||
|
||||
class HrContract(models.Model):
|
||||
_inherit = 'hr.contract'
|
||||
|
||||
paid_hourly_attendance = fields.Boolean(string="Paid Hourly Attendance")
|
||||
95
hr_payroll_attendance/models/hr_payslip.py
Executable file
95
hr_payroll_attendance/models/hr_payslip.py
Executable file
@@ -0,0 +1,95 @@
|
||||
from collections import defaultdict
|
||||
from odoo import api, fields, models, _
|
||||
|
||||
|
||||
class HrPayslip(models.Model):
|
||||
_inherit = 'hr.payslip'
|
||||
|
||||
attendance_ids = fields.One2many('hr.attendance', 'payslip_id', string='Attendances',
|
||||
help='Attendances represented by payslip.', readonly=True,
|
||||
states={'draft': [('readonly', False)], 'verify': [('readonly', False)]})
|
||||
attendance_count = fields.Integer(compute='_compute_attendance_count')
|
||||
|
||||
@api.depends('attendance_ids', 'attendance_ids.payslip_id')
|
||||
def _compute_attendance_count(self):
|
||||
for payslip in self:
|
||||
payslip.attendance_count = len(payslip.attendance_ids)
|
||||
|
||||
def _get_worked_day_lines(self):
|
||||
# Called at the end of _onchange_employee()
|
||||
worked_day_lines = super()._get_worked_day_lines()
|
||||
return self._attendance_get_worked_day_lines(worked_day_lines)
|
||||
|
||||
def _attendance_get_worked_day_lines(self, worked_day_lines):
|
||||
"""
|
||||
Filters out basic "Attendance"/"Work Calendar" entries as they would add to salary.
|
||||
Note that this is during an onchange (probably).
|
||||
:returns: a list of dict containing the worked days values that should be applied for the given payslip
|
||||
"""
|
||||
if not self.contract_id.paid_hourly_attendance:
|
||||
return worked_day_lines
|
||||
if not self.state in ('draft', 'verify'):
|
||||
return worked_day_lines
|
||||
|
||||
attendance_to_keep = self.attendance_ids.filtered(lambda a: a.employee_id == self.employee_id
|
||||
and a.check_out.date() <= self.date_to)
|
||||
attendance_to_keep |= self.env['hr.attendance'].search([
|
||||
('employee_id', '=', self.employee_id.id),
|
||||
('check_out', '<=', self.date_to),
|
||||
('payslip_id', '=', False),
|
||||
])
|
||||
self.update({'attendance_ids': [(6, 0, attendance_to_keep.ids)]})
|
||||
|
||||
attendance_type = self.env.ref('hr_attendance_work_entry.work_input_attendance', raise_if_not_found=False)
|
||||
if not attendance_type:
|
||||
# different default type
|
||||
attendance_type = self.struct_id.type_id.default_work_entry_type_id
|
||||
if not attendance_type:
|
||||
# return early, include the "work calendar lines"
|
||||
return worked_day_lines
|
||||
|
||||
original_work_type = self.env.ref('hr_work_entry.work_entry_type_attendance', raise_if_not_found=False)
|
||||
if original_work_type:
|
||||
# filter out "work calendar lines"
|
||||
worked_day_lines = [w for w in worked_day_lines if w['work_entry_type_id'] != original_work_type.id]
|
||||
|
||||
work_data = self._pre_aggregate_attendance_data(attendance_type)
|
||||
processed_data = self.aggregate_overtime(work_data)
|
||||
|
||||
worked_day_lines += [{
|
||||
'number_of_days': data[0],
|
||||
'number_of_hours': data[1],
|
||||
'amount': data[1] * data[2] * self._wage_for_work_type(work_type),
|
||||
'contract_id': self.contract_id.id,
|
||||
'work_entry_type_id': work_type.id,
|
||||
} for work_type, data in processed_data.items()]
|
||||
|
||||
return worked_day_lines
|
||||
|
||||
def _wage_for_work_type(self, work_type):
|
||||
# Override if you pay differently for different work types
|
||||
return self.contract_id.wage
|
||||
|
||||
def _pre_aggregate_attendance_data(self, default_workentrytype):
|
||||
worked_attn = defaultdict(list)
|
||||
for attn in self.attendance_ids:
|
||||
if attn.worked_hours:
|
||||
# Avoid in/outs
|
||||
attn_iso = attn.check_in.isocalendar()
|
||||
attendance_type = attn.work_type_id or default_workentrytype
|
||||
if attendance_type in self.struct_id.unpaid_work_entry_type_ids:
|
||||
# this is unpaid, so we have to skip it from aggregation
|
||||
continue
|
||||
worked_attn[attn_iso].append((attendance_type, attn.worked_hours, attn))
|
||||
res = [(k, worked_attn[k]) for k in sorted(worked_attn.keys())]
|
||||
return res
|
||||
|
||||
def action_open_attendances(self):
|
||||
self.ensure_one()
|
||||
return {
|
||||
'type': 'ir.actions.act_window',
|
||||
'name': _('Paid Attendances'),
|
||||
'res_model': 'hr.attendance',
|
||||
'view_mode': 'tree,form',
|
||||
'domain': [('id', 'in', self.attendance_ids.ids)],
|
||||
}
|
||||
1
hr_payroll_attendance/tests/__init__.py
Normal file
1
hr_payroll_attendance/tests/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import test_payroll_attendance
|
||||
139
hr_payroll_attendance/tests/test_payroll_attendance.py
Normal file
139
hr_payroll_attendance/tests/test_payroll_attendance.py
Normal file
@@ -0,0 +1,139 @@
|
||||
from collections import defaultdict
|
||||
from odoo.tests import common
|
||||
|
||||
|
||||
class TestUsPayslip(common.TransactionCase):
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.test_hourly_wage = 21.5
|
||||
self.employee = self.env.ref('hr.employee_hne')
|
||||
self.contract = self.env['hr.contract'].create({
|
||||
'name': 'Test',
|
||||
'employee_id': self.employee.id,
|
||||
'structure_type_id': self.env.ref('hr_payroll.structure_type_employee').id,
|
||||
'date_start': '2020-01-01',
|
||||
'resource_calendar_id': self.employee.resource_calendar_id.id,
|
||||
'wage': self.test_hourly_wage,
|
||||
'paid_hourly_attendance': True,
|
||||
'state': 'open',
|
||||
})
|
||||
self._setup_attendance(self.employee)
|
||||
self.payslip = self.env['hr.payslip'].create({
|
||||
'name': 'test slip',
|
||||
'employee_id': self.employee.id,
|
||||
'date_from': '2020-01-06',
|
||||
'date_to': '2020-01-19',
|
||||
})
|
||||
|
||||
def _setup_attendance(self, employee):
|
||||
# Total 127.37 hours in 2 weeks.
|
||||
# Six 9-hour days in one week (plus a little). 58.97 hours in that week.
|
||||
attendances = self.env['hr.attendance']
|
||||
attendances += self.env['hr.attendance'].create({
|
||||
'employee_id': employee.id,
|
||||
'check_in': '2020-01-06 10:00:00', # Monday
|
||||
'check_out': '2020-01-06 19:00:00',
|
||||
})
|
||||
attendances += self.env['hr.attendance'].create({
|
||||
'employee_id': employee.id,
|
||||
'check_in': '2020-01-07 10:00:00',
|
||||
'check_out': '2020-01-07 19:00:00',
|
||||
})
|
||||
attendances += self.env['hr.attendance'].create({
|
||||
'employee_id': employee.id,
|
||||
'check_in': '2020-01-08 10:00:00',
|
||||
'check_out': '2020-01-08 19:00:00',
|
||||
})
|
||||
attendances += self.env['hr.attendance'].create({
|
||||
'employee_id': employee.id,
|
||||
'check_in': '2020-01-09 10:00:00',
|
||||
'check_out': '2020-01-09 19:00:00',
|
||||
})
|
||||
attendances += self.env['hr.attendance'].create({
|
||||
'employee_id': employee.id,
|
||||
'check_in': '2020-01-10 10:00:00',
|
||||
'check_out': '2020-01-10 19:00:00',
|
||||
})
|
||||
attendances += self.env['hr.attendance'].create({
|
||||
'employee_id': employee.id,
|
||||
'check_in': '2020-01-11 06:00:00',
|
||||
'check_out': '2020-01-11 19:58:12',
|
||||
})
|
||||
|
||||
# Five 10-hour days, Two 9-hour days (plus a little) in one week. 68.4 hours in that week
|
||||
attendances += self.env['hr.attendance'].create({
|
||||
'employee_id': employee.id,
|
||||
'check_in': '2020-01-13 08:00:00', # Monday
|
||||
'check_out': '2020-01-13 18:00:00',
|
||||
})
|
||||
attendances += self.env['hr.attendance'].create({
|
||||
'employee_id': employee.id,
|
||||
'check_in': '2020-01-14 08:00:00',
|
||||
'check_out': '2020-01-14 18:00:00',
|
||||
})
|
||||
attendances += self.env['hr.attendance'].create({
|
||||
'employee_id': employee.id,
|
||||
'check_in': '2020-01-15 08:00:00',
|
||||
'check_out': '2020-01-15 18:00:00',
|
||||
})
|
||||
attendances += self.env['hr.attendance'].create({
|
||||
'employee_id': employee.id,
|
||||
'check_in': '2020-01-16 08:00:00',
|
||||
'check_out': '2020-01-16 18:00:00',
|
||||
})
|
||||
attendances += self.env['hr.attendance'].create({
|
||||
'employee_id': employee.id,
|
||||
'check_in': '2020-01-17 08:00:00',
|
||||
'check_out': '2020-01-17 18:00:00',
|
||||
})
|
||||
attendances += self.env['hr.attendance'].create({
|
||||
'employee_id': employee.id,
|
||||
'check_in': '2020-01-18 09:00:00',
|
||||
'check_out': '2020-01-18 18:00:00',
|
||||
})
|
||||
last = self.env['hr.attendance'].create({
|
||||
'employee_id': employee.id,
|
||||
'check_in': '2020-01-19 09:00:00',
|
||||
'check_out': '2020-01-19 18:24:00',
|
||||
})
|
||||
attendances += last
|
||||
return last
|
||||
|
||||
def _getCategories(self):
|
||||
categories = defaultdict(float)
|
||||
for line in self.payslip.line_ids:
|
||||
category_id = line.category_id
|
||||
category_code = line.category_id.code
|
||||
while category_code:
|
||||
categories[category_code] += line.total
|
||||
category_id = category_id.parent_id
|
||||
category_code = category_id.code
|
||||
return categories
|
||||
|
||||
def test_attendance_hourly(self):
|
||||
self.payslip._onchange_employee()
|
||||
self.assertTrue(self.payslip.contract_id, 'No auto-discovered contract!')
|
||||
self.payslip.compute_sheet()
|
||||
# 58.97 => 40hr regular, 18.97hr OT
|
||||
# 68.4 => 40hr regular, 28.4hr OT
|
||||
# (80 * 21.50) + (47.37 * 21.50 * 1.5) = 3247.6825
|
||||
cats = self._getCategories()
|
||||
self.assertAlmostEqual(cats['BASIC'], 3247.68, 2)
|
||||
|
||||
# ensure unlink behavior.
|
||||
self.payslip.attendance_ids = self.env['hr.attendance'].browse()
|
||||
self.payslip.state = 'draft'
|
||||
self.payslip.flush()
|
||||
self.payslip._onchange_employee()
|
||||
self.payslip.compute_sheet()
|
||||
cats = self._getCategories()
|
||||
self.assertAlmostEqual(cats['BASIC'], 3247.68, 2)
|
||||
|
||||
self.payslip.write({'attendance_ids': [(5, 0, 0)]})
|
||||
self.payslip.state = 'draft'
|
||||
self.payslip.flush()
|
||||
self.payslip._onchange_employee()
|
||||
self.payslip.compute_sheet()
|
||||
cats = self._getCategories()
|
||||
self.assertAlmostEqual(cats['BASIC'], 3247.68, 2)
|
||||
17
hr_payroll_attendance/views/hr_attendance_views.xml
Normal file
17
hr_payroll_attendance/views/hr_attendance_views.xml
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
|
||||
<record id="view_attendance_tree_inherit" model="ir.ui.view">
|
||||
<field name="name">hr.attendance.tree.inherit</field>
|
||||
<field name="model">hr.attendance</field>
|
||||
<field name="inherit_id" ref="hr_attendance.view_attendance_tree"/>
|
||||
<field name="arch" type="xml">
|
||||
<data>
|
||||
<xpath expr="//field[@name='worked_hours']" position="after">
|
||||
<field name="payslip_id"/>
|
||||
</xpath>
|
||||
</data>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
22
hr_payroll_attendance/views/hr_contract_views.xml
Executable file
22
hr_payroll_attendance/views/hr_contract_views.xml
Executable file
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
|
||||
<record id="hr_contract_form_inherit" model="ir.ui.view">
|
||||
<field name="name">hr.contract.form.inherit</field>
|
||||
<field name="model">hr.contract</field>
|
||||
<field name="priority">20</field>
|
||||
<field name="inherit_id" ref="hr_contract.hr_contract_view_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<data>
|
||||
<xpath expr="//field[@name='advantages']" position="after">
|
||||
<field name="paid_hourly_attendance"/>
|
||||
</xpath>
|
||||
<xpath expr="//div[@name='wage']/span" position="replace">
|
||||
<span attrs="{'invisible': [('paid_hourly_attendance', '=', True)]}">/ pay period</span>
|
||||
<span attrs="{'invisible': [('paid_hourly_attendance', '=', False)]}">/ hour</span>
|
||||
</xpath>
|
||||
</data>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
20
hr_payroll_attendance/views/hr_payslip_views.xml
Normal file
20
hr_payroll_attendance/views/hr_payslip_views.xml
Normal file
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
|
||||
<record id="hr_payslip_view_form_inherit" model="ir.ui.view">
|
||||
<field name="name">hr.payslip.view.form.inherit</field>
|
||||
<field name="model">hr.payslip</field>
|
||||
<field name="inherit_id" ref="hr_payroll.view_hr_payslip_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//div[@name='button_box']" position="inside">
|
||||
<button class="oe_stat_button" name="action_open_attendances" type="object" icon="fa-calendar" attrs="{'invisible': [('attendance_count', '=', 0)]}">
|
||||
<field string="Attendances" name="attendance_count" widget="statinfo"/>
|
||||
</button>
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='number']" position="after">
|
||||
<field name="attendance_ids" invisible="1" widget="many2many"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user