diff --git a/hr_payroll_timesheet/__init__.py b/hr_payroll_timesheet/__init__.py new file mode 100755 index 00000000..4d15389f --- /dev/null +++ b/hr_payroll_timesheet/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- +from . import hr_payslip +from . import hr_contract diff --git a/hr_payroll_timesheet/__manifest__.py b/hr_payroll_timesheet/__manifest__.py new file mode 100755 index 00000000..c3a9eae3 --- /dev/null +++ b/hr_payroll_timesheet/__manifest__.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- + +{ + 'name': 'Timesheets on Payslips', + 'description': 'Get Timesheet and Attendence numbers onto Employee Payslips.', + 'version': '11.0.0.0.0', + 'website': 'https://hibou.io/', + 'author': 'Hibou Corp. ', + 'license': 'AGPL-3', + 'category': 'Human Resources', + 'data': [ + 'hr_contract_view.xml', + ], + 'depends': [ + 'hr_payroll', + 'hr_timesheet_attendance', + ], +} diff --git a/hr_payroll_timesheet/hr_contract.py b/hr_payroll_timesheet/hr_contract.py new file mode 100755 index 00000000..f2be76d4 --- /dev/null +++ b/hr_payroll_timesheet/hr_contract.py @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- +from odoo import models, fields + + +class HrContract(models.Model): + _inherit = 'hr.contract' + + paid_hourly = fields.Boolean(string="Paid Hourly", default=False) diff --git a/hr_payroll_timesheet/hr_contract_view.xml b/hr_payroll_timesheet/hr_contract_view.xml new file mode 100755 index 00000000..abd831f5 --- /dev/null +++ b/hr_payroll_timesheet/hr_contract_view.xml @@ -0,0 +1,18 @@ + + + + + hr.contract.form.inherit + hr.contract + 20 + + + + + + + + + + + diff --git a/hr_payroll_timesheet/hr_payslip.py b/hr_payroll_timesheet/hr_payslip.py new file mode 100755 index 00000000..5d09c267 --- /dev/null +++ b/hr_payroll_timesheet/hr_payslip.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +from odoo import api, models + + +class HrPayslip(models.Model): + _inherit = 'hr.payslip' + + @api.model + def get_worked_day_lines(self, contracts, date_from, date_to): + def create_empty_worked_lines(employee_id, contract_id, date_from, date_to): + attendance = { + 'name': 'Timesheet Attendance', + 'sequence': 10, + 'code': 'ATTN', + 'number_of_days': 0.0, + 'number_of_hours': 0.0, + 'contract_id': contract_id, + } + + valid_days = [ + ('sheet_id.employee_id', '=', employee_id), + ('sheet_id.state', '=', 'done'), + ('sheet_id.date_from', '>=', date_from), + ('sheet_id.date_to', '<=', date_to), + ] + return attendance, valid_days + + attendances = [] + + for contract in contracts: + attendance, valid_days = create_empty_worked_lines( + contract.employee_id.id, + contract.id, + date_from, + date_to + ) + + for day in self.env['hr_timesheet_sheet.sheet.day'].search(valid_days): + if day.total_attendance >= 0.0: + attendance['number_of_days'] += 1 + attendance['number_of_hours'] += day.total_attendance + + # needed so that the shown hours matches any calculations you use them for + attendance['number_of_hours'] = round(attendance['number_of_hours'], 2) + attendances.append(attendance) + + res = super(HrPayslip, self).get_worked_day_lines(contracts, date_from, date_to) + res.extend(attendances) + return res +