diff --git a/hr_worked_days_from_timesheet/README.rst b/hr_worked_days_from_timesheet/README.rst index 3a630a43876..2171ce53e66 100644 --- a/hr_worked_days_from_timesheet/README.rst +++ b/hr_worked_days_from_timesheet/README.rst @@ -53,13 +53,14 @@ Contributors * David Dufresne * Pierre Lamarche * Ignacio Ibeas +* OpenSynergy Indonesia Maintainer ---------- -.. image:: http://odoo-community.org/logo.png +.. image:: https://odoo-community.org/logo.png :alt: Odoo Community Association - :target: http://odoo-community.org + :target: https://odoo-community.org This module is maintained by the OCA. @@ -67,4 +68,4 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. -To contribute to this module, please visit http://odoo-community.org. \ No newline at end of file +To contribute to this module, please visit https://odoo-community.org. diff --git a/hr_worked_days_from_timesheet/__init__.py b/hr_worked_days_from_timesheet/__init__.py index 5d23b9797ad..14cd47bd6a1 100644 --- a/hr_worked_days_from_timesheet/__init__.py +++ b/hr_worked_days_from_timesheet/__init__.py @@ -1,21 +1,6 @@ -# -*- coding:utf-8 -*- -############################################################################## -# -# Copyright (C) 2012 - 2014 Odoo Canada. All Rights Reserved. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published -# by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# -*- coding: utf-8 -*- +# © 2012 - 2014 Odoo Canada +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) + from . import models +from . import tests diff --git a/hr_worked_days_from_timesheet/__openerp__.py b/hr_worked_days_from_timesheet/__openerp__.py index f1ce6fd33aa..64ead514828 100644 --- a/hr_worked_days_from_timesheet/__openerp__.py +++ b/hr_worked_days_from_timesheet/__openerp__.py @@ -1,32 +1,14 @@ -# -*- coding:utf-8 -*- -############################################################################## -# -# Copyright (C) 2014 Odoo Canada. All Rights Reserved. -# Copyright (C) 2015 Acysos S.L. All Rights Reserved. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## - +# -*- coding: utf-8 -*- +# © 2012 - 2014 Odoo Canada +# © 2015 Acysos S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) { 'name': 'Worked Days From Timesheet', 'version': '8.0.1.0.0', 'license': 'AGPL-3', 'category': 'Generic Modules/Human Resources', - 'author': "Savoir-faire Linux, Acysos SL, \ - Acysos S.L., \ - Odoo Community Association (OCA)", + 'author': "Savoir-faire Linux, Acysos SL,Acysos S.L.," + "Odoo Community Association (OCA)", 'website': 'https://www.savoirfairelinux.com/', 'depends': [ 'hr_payroll', @@ -35,8 +17,5 @@ 'data': [ 'views/hr_payslip_view.xml' ], - 'test': [ - 'test/worked_days_from_timesheet_test.yml' - ], 'installable': True, } diff --git a/hr_worked_days_from_timesheet/models/__init__.py b/hr_worked_days_from_timesheet/models/__init__.py index 9e01fec1976..688911c818b 100644 --- a/hr_worked_days_from_timesheet/models/__init__.py +++ b/hr_worked_days_from_timesheet/models/__init__.py @@ -1,22 +1,6 @@ -# -*- coding:utf-8 -*- -############################################################################## -# -# Copyright (C) 2012 - 2014 Odoo Canada. All Rights Reserved. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published -# by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# -*- coding: utf-8 -*- +# © 2012 - 2014 Odoo Canada +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) + from . import hr_payslip_worked_days from . import hr_payslip diff --git a/hr_worked_days_from_timesheet/models/hr_payslip.py b/hr_worked_days_from_timesheet/models/hr_payslip.py index 04f7d6b9a4e..6e5b119a789 100644 --- a/hr_worked_days_from_timesheet/models/hr_payslip.py +++ b/hr_worked_days_from_timesheet/models/hr_payslip.py @@ -1,27 +1,11 @@ -# -*- coding:utf-8 -*- -############################################################################## -# -# Copyright (C) 2012 - 2014 Odoo Canada. All Rights Reserved. -# Copyright (C) 2015 Acysos S.L. All Rights Reserved. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published -# by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# -*- coding: utf-8 -*- +# © 2012 - 2014 Odoo Canada +# © 2015 Acysos S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) + from openerp import models, fields, api from openerp.tools.translate import _ -from openerp.exceptions import Warning +from openerp.exceptions import Warning as UserError class HrPayslip(models.Model): @@ -83,7 +67,7 @@ def import_worked_days(self): ) if not timesheet_sheets: - raise Warning( + raise UserError( _("Sorry, but there is no approved Timesheets for the \ entire Payslip period"), ) diff --git a/hr_worked_days_from_timesheet/models/hr_payslip_worked_days.py b/hr_worked_days_from_timesheet/models/hr_payslip_worked_days.py index 64f50391954..4db010c87fd 100644 --- a/hr_worked_days_from_timesheet/models/hr_payslip_worked_days.py +++ b/hr_worked_days_from_timesheet/models/hr_payslip_worked_days.py @@ -1,24 +1,8 @@ -# -*- coding:utf-8 -*- -############################################################################## -# -# Copyright (C) 2012 - 2014 Odoo Canada. All Rights Reserved. -# Copyright (C) 2015 Acysos S.L. All Rights Reserved. -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published -# by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# -*- coding: utf-8 -*- +# © 2012 - 2014 Odoo Canada +# © 2015 Acysos S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) + from openerp import models, fields diff --git a/hr_worked_days_from_timesheet/test/worked_days_from_timesheet_test.yml b/hr_worked_days_from_timesheet/test/worked_days_from_timesheet_test.yml deleted file mode 100644 index 8b6a21e6f6e..00000000000 --- a/hr_worked_days_from_timesheet/test/worked_days_from_timesheet_test.yml +++ /dev/null @@ -1,137 +0,0 @@ -- - First we create a user -- - !record {model: res.users, id: test_wd_user_1}: - company_id: base.main_company - name: 'User 1' - login: 'tua@example.com' - password: 'base-test-passwd' - active: True -- - Create an employee -- - !record {model: hr.employee, id: employee_1}: - name: Employee 1 - user_id: test_wd_user_1 -- - Create a contract -- - !record {model: hr.contract, id: contract_1}: - name: Contract 1 - employee_id: employee_1 - wage: 0 -- - Create an account -- - !record {model: account.analytic.account, id: account_1}: - name: Account 1 - type: normal - use_timesheets: True -- - Create timesheet sheet 1 -- - !record {model: hr_timesheet_sheet.sheet, id: sheet_1}: - employee_id: employee_1 - date_from: 2014-01-01 - date_to: 2014-01-01 -- - Create timesheet sheet 2 -- - !record {model: hr_timesheet_sheet.sheet, id: sheet_2}: - employee_id: employee_1 - date_from: 2014-01-02 - date_to: 2014-01-04 -- - Create timesheet sheet 3 -- - !record {model: hr_timesheet_sheet.sheet,id: sheet_3}: - employee_id: employee_1 - date_from: 2014-01-05 - date_to: 2014-01-15 -- - Create timesheet sheet 4 -- - !record {model: hr_timesheet_sheet.sheet, id: sheet_4}: - employee_id: employee_1 - date_from: 2014-01-16 - date_to: 2014-01-16 -- - Create timesheet 1 -- - !record {model: hr.analytic.timesheet, id: ts_not_taken_1}: - date: 2014-01-01 - user_id: test_wd_user_1 - name: ddd - account_id: account_1 - unit_amount: 3 -- - Create timesheet 2 -- - !record {model: hr.analytic.timesheet, id: ts_taken_1}: - date: 2014-01-02 - user_id: test_wd_user_1 - name: ddd - account_id: account_1 - unit_amount: 5 -- - Create timesheet 3 -- - !record {model: hr.analytic.timesheet, id: ts_taken_2}: - date: 2014-01-04 - user_id: test_wd_user_1 - name: ddd - account_id: account_1 - unit_amount: 7 - sheet_id: sheet_2 -- - Create timesheet 4 -- - !record {model: hr.analytic.timesheet, id: ts_taken_3}: - date: 2014-01-15 - user_id: test_wd_user_1 - name: ddd - account_id: account_1 - unit_amount: 11.5 -- - Create timesheet 5 -- - !record {model: hr.analytic.timesheet, id: ts_not_taken_2}: - date: 2014-01-16 - user_id: test_wd_user_1 - name: ddd - account_id: account_1 - unit_amount: 13 -- - Confirm Sheets -- - !python {model: hr_timesheet_sheet.sheet}: | - self.write(cr, uid, [ref("sheet_1"), ref("sheet_2"), ref("sheet_3"), ref("sheet_4")], {'state': 'done'}) -- - Create a payslip -- - !record {model: hr.payslip, id: payslip_1}: - employee_id: employee_1 - contract_id: contract_1 - date_from: '2014-01-02' - date_to: '2014-01-15' -- - Test the worked days from timesheet function -- - !python {model: hr.payslip}: | - self.import_worked_days(cr, uid, [ref("payslip_1")]) - payslip = self.browse(cr, uid, ref('payslip_1')) - for wd in payslip.worked_days_line_ids: - # 2 worked days - # one for timesheet 4 (11.5 hours) - # one for timesheet 2 and timesheet 3 (5 hours + 7 hours = 12) - # the order is not important - assert(wd.number_of_hours in [11.5, 12]) -- - Test again to verify that old records get erased - as the function is called a second time -- - !python {model: hr.payslip}: | - self.import_worked_days(cr, uid, [ref("payslip_1")]) - payslip = self.browse(cr, uid, ref('payslip_1')) - # we should still have only 2 timesheets - assert(len(payslip.worked_days_line_ids) == 2) \ No newline at end of file diff --git a/hr_worked_days_from_timesheet/tests/__init__.py b/hr_worked_days_from_timesheet/tests/__init__.py new file mode 100644 index 00000000000..755a4b21aa9 --- /dev/null +++ b/hr_worked_days_from_timesheet/tests/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# © 2016 OpenSynergy Indonesia +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import test_worked_days_from_timesheet diff --git a/hr_worked_days_from_timesheet/tests/test_worked_days_from_timesheet.py b/hr_worked_days_from_timesheet/tests/test_worked_days_from_timesheet.py new file mode 100644 index 00000000000..979a47361c3 --- /dev/null +++ b/hr_worked_days_from_timesheet/tests/test_worked_days_from_timesheet.py @@ -0,0 +1,159 @@ +# -*- coding: utf-8 -*- +# © 2016 OpenSynergy Indonesia +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp.tests.common import TransactionCase + + +class TestComputeWorkdays(TransactionCase): + + def setUp(self): + super(TestComputeWorkdays, self).setUp() + + self.company = self.env.ref('base.main_company') + self.analytic_journal = self.env.ref('hr_timesheet.analytic_journal') + self.user_admin = self.env.ref('base.partner_root') + + user_dict = { + 'name': 'User 1', + 'login': 'tua@example.com', + 'password': 'base-test-passwd', + } + self.user_test = self.env['res.users'].create(user_dict) + + employee_dict = { + 'name': 'Employee 1', + 'user_id': self.user_test.id, + 'journal_id': self.analytic_journal.id, + } + self.employee = self.env['hr.employee'].create(employee_dict) + + contract_dict = { + 'name': 'Contract 1', + 'employee_id': self.employee.id, + 'wage': 0.0, + } + self.contract = self.env['hr.contract'].create(contract_dict) + + analytic_dict = { + 'name': 'Account 1', + 'type': 'normal', + 'use_timesheets': True, + } + + self.analytic = self.env['account.analytic.account'].create( + analytic_dict) + + ts1_dict = { + 'employee_id': self.employee.id, + 'date_from': '2014-01-01', + 'date_to': '2014-01-01', + } + self.ts1 = self.env['hr_timesheet_sheet.sheet'].create(ts1_dict) + + ts2_dict = { + 'employee_id': self.employee.id, + 'date_from': '2014-01-02', + 'date_to': '2014-01-04', + } + self.ts2 = self.env['hr_timesheet_sheet.sheet'].create(ts2_dict) + + ts3_dict = { + 'employee_id': self.employee.id, + 'date_from': '2014-01-05', + 'date_to': '2014-01-15', + } + self.ts3 = self.env['hr_timesheet_sheet.sheet'].create(ts3_dict) + + ts4_dict = { + 'employee_id': self.employee.id, + 'date_from': '2014-01-16', + 'date_to': '2014-01-16', + } + self.ts4 = self.env['hr_timesheet_sheet.sheet'].create(ts4_dict) + + analytic_ts1_dict = { + 'date': '2014-01-01', + 'user_id': self.user_test.id, + 'employee_id': self.employee.id, + 'name': 'ddd', + 'account_id': self.analytic.id, + 'unit_amount': 3.0, + 'journal_id': self.analytic_journal.id, + } + self.analytic_ts1 = self.env['hr.analytic.timesheet'].with_context( + user_id=self.user_test.id).create( + analytic_ts1_dict) + + analytic_ts2_dict = { + 'date': '2014-01-02', + 'user_id': self.user_test.id, + 'employee_id': self.employee.id, + 'name': 'ddd', + 'account_id': self.analytic.id, + 'unit_amount': 5.0, + 'journal_id': self.analytic_journal.id, + 'sheet_id': self.ts2.id, + } + self.analytic_ts2 = self.env['hr.analytic.timesheet'].with_context( + user_id=self.user_test.id).create( + analytic_ts2_dict) + + analytic_ts3_dict = { + 'date': '2014-01-04', + 'user_id': self.user_test.id, + 'sheet_id': self.ts2.id, + 'name': 'ddd', + 'account_id': self.analytic.id, + 'unit_amount': 7.0, + 'journal_id': self.analytic_journal.id, + } + self.analytic_ts3 = self.env['hr.analytic.timesheet'].with_context( + user_id=self.user_test.id).create( + analytic_ts3_dict) + + analytic_ts4_dict = { + 'date': '2014-01-15', + 'user_id': self.user_test.id, + 'sheet_id': self.ts4.id, + 'name': 'ddd', + 'account_id': self.analytic.id, + 'unit_amount': 11.5, + 'journal_id': self.analytic_journal.id, + } + self.analytic_ts4 = self.env['hr.analytic.timesheet'].with_context( + user_id=self.user_test.id).create( + analytic_ts4_dict) + + analytic_ts5_dict = { + 'date': '2014-01-16', + 'user_id': self.user_test.id, + 'sheet_id': self.ts1.id, + 'name': 'ddd', + 'account_id': self.analytic.id, + 'unit_amount': 13, + 'journal_id': self.analytic_journal.id, + } + self.analytic_ts5 = self.env['hr.analytic.timesheet'].with_context( + user_id=self.user_test.id).create( + analytic_ts5_dict) + + ts = self.ts1 + self.ts2 + self.ts3 + self.ts4 + ts.button_confirm() + ts.signal_workflow('done') + + def test_timesheet_import(self): + payslip_dict = { + 'employee_id': self.employee.id, + 'contract_id': self.contract.id, + 'date_from': '2014-01-02', + 'date_to': '2014-01-15', + } + payslip = self.env['hr.payslip'].create( + payslip_dict) + payslip.import_worked_days() + for wd in payslip.worked_days_line_ids: + self.assertIn(wd.number_of_hours, [11.5, 12]) + + payslip.import_worked_days() + self.assertEqual(len(payslip.worked_days_line_ids), 2)