diff --git a/hr_payroll_account_operating_unit/README.rst b/hr_payroll_account_operating_unit/README.rst new file mode 100644 index 0000000000..6955aa1bf3 --- /dev/null +++ b/hr_payroll_account_operating_unit/README.rst @@ -0,0 +1,56 @@ +.. image:: https://img.shields.io/badge/license-LGPLv3-blue.svg + :target: https://www.gnu.org/licenses/lgpl.html + :alt: License: LGPL-3 + +======================================= +HR Payroll Account with Operating Units +======================================= + +This module introduces the following features: + +* Adds Operating Unit (OU) to the account moves and its lines created by the +payslip, based on the Operating Unit (OU) defined in the Employee's Contract. + +Usage +===== + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/213/9.0 + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues +`_. In case of trouble, please +check there if your issue has already been reported. If you spotted it first, +help us smashing it by providing a detailed and welcomed feedback. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* Eficent Business and IT Consulting Services S.L. +* Serpent Consulting Services Pvt. Ltd. + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +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 https://odoo-community.org. diff --git a/hr_payroll_account_operating_unit/__init__.py b/hr_payroll_account_operating_unit/__init__.py new file mode 100644 index 0000000000..ef6733f80d --- /dev/null +++ b/hr_payroll_account_operating_unit/__init__.py @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +# © 2015 Eficent Business and IT Consulting Services S.L. - +# Jordi Ballester Alomar +# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +from . import models +from . import tests diff --git a/hr_payroll_account_operating_unit/__openerp__.py b/hr_payroll_account_operating_unit/__openerp__.py new file mode 100644 index 0000000000..7641bb95a9 --- /dev/null +++ b/hr_payroll_account_operating_unit/__openerp__.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# © 2015 Eficent Business and IT Consulting Services S.L. - +# Jordi Ballester Alomar +# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +{ + "name": "HR Payroll Account Operating Unit", + "version": "9.0.1.0.0", + "license": 'LGPL-3', + "author": "Eficent Business and IT Consulting Services S.L., " + "Serpent Consulting Services Pvt. Ltd.," + "Odoo Community Association (OCA)", + "category": "Generic Modules/Human Resources", + "website": "http://www.eficent.com", + "depends": ["hr_payroll_account", "hr_contract_operating_unit", + "account_operating_unit"], + 'installable': True, +} diff --git a/hr_payroll_account_operating_unit/models/__init__.py b/hr_payroll_account_operating_unit/models/__init__.py new file mode 100644 index 0000000000..fa7dae1272 --- /dev/null +++ b/hr_payroll_account_operating_unit/models/__init__.py @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +# © 2015 Eficent Business and IT Consulting Services S.L. - +# Jordi Ballester Alomar +# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +from . import hr_payslip +from . import account_move diff --git a/hr_payroll_account_operating_unit/models/account_move.py b/hr_payroll_account_operating_unit/models/account_move.py new file mode 100644 index 0000000000..aca32c93b2 --- /dev/null +++ b/hr_payroll_account_operating_unit/models/account_move.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# © 2015 Eficent Business and IT Consulting Services S.L. - +# Jordi Ballester Alomar +# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +from openerp import api, models + + +class AccountMove(models.Model): + + _inherit = 'account.move' + + @api.model + def create(self, vals): + if 'force_operating_unit' in self._context: + for line in vals['line_ids']: + line[2].update({'operating_unit_id': + self._context['force_operating_unit']}) + return super(AccountMove, self).create(vals) diff --git a/hr_payroll_account_operating_unit/models/hr_payslip.py b/hr_payroll_account_operating_unit/models/hr_payslip.py new file mode 100644 index 0000000000..e950afefcb --- /dev/null +++ b/hr_payroll_account_operating_unit/models/hr_payslip.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +# © 2015 Eficent Business and IT Consulting Services S.L. - +# Jordi Ballester Alomar +# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +from openerp.tools.translate import _ +from openerp import models, api +from openerp.exceptions import Warning as UserError + + +class HrPayslip(models.Model): + + _inherit = 'hr.payslip' + + @api.multi + def write(self, vals): + res = super(HrPayslip, self).write(vals) + if 'move_id' in vals and vals['move_id']: + for slip in self: + if slip.contract_id and slip.contract_id.operating_unit_id: + slip.move_id.write({'operating_unit_id': + slip.contract_id.operating_unit_id.id}) + return res + + @api.cr_uid_ids_context + def process_sheet(self, cr, uid, ids, context=None): + OU = None + payslip = self.browse(cr, uid, ids, context=context) + for slip in payslip: + # Check that all slips are related to contracts + # that belong to the same OU. + if OU: + if slip.contract_id.operating_unit_id.id != OU: + raise UserError(_('Configuration error!\nThe Contracts must\ + refer the same Operating Unit.')) + OU = slip.contract_id.operating_unit_id.id + # Add to context the OU of the employee contract + new_context = context.copy() + new_context.update(force_operating_unit=OU) + return super(HrPayslip, self).process_sheet(cr, uid, payslip.ids, + new_context) diff --git a/hr_payroll_account_operating_unit/static/description/icon.png b/hr_payroll_account_operating_unit/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/hr_payroll_account_operating_unit/static/description/icon.png differ diff --git a/hr_payroll_account_operating_unit/tests/__init__.py b/hr_payroll_account_operating_unit/tests/__init__.py new file mode 100644 index 0000000000..eaca10e74b --- /dev/null +++ b/hr_payroll_account_operating_unit/tests/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# © 2015 Eficent Business and IT Consulting Services S.L. +# - Jordi Ballester Alomar +# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +from . import test_payroll_account_operating_unit diff --git a/hr_payroll_account_operating_unit/tests/test_payroll_account_operating_unit.py b/hr_payroll_account_operating_unit/tests/test_payroll_account_operating_unit.py new file mode 100644 index 0000000000..f8fb49f622 --- /dev/null +++ b/hr_payroll_account_operating_unit/tests/test_payroll_account_operating_unit.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# © 2015 Eficent Business and IT Consulting Services S.L. +# - Jordi Ballester Alomar +# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +from openerp.addons.hr_contract_operating_unit.tests\ + import test_hr_contract_operating_unit + + +class TestPayrollAccountOperatingUnit(test_hr_contract_operating_unit. + TestHrContractOperatingUnit): + + def setUp(self): + super(TestPayrollAccountOperatingUnit, self).setUp() + self.hr_payslip_model = self.env['hr.payslip'] + self.acc_move_model = self.env['account.move'] + self.acc_journal_model = self.env['account.journal'] + + self.hr_payroll_struct = self.env.ref('hr_payroll.structure_base') + # Add Payroll Salary Structure to Contract + contracts = self.hr_contract1 + self.hr_contract2 + contracts.write({'struct_id': self.hr_payroll_struct.id}) + # Salary Journal + self.journal = self.acc_journal_model.search([('type', '=', 'bank'), + ('name', '=', 'Bank')]) + # Create Payslip 1 + self.payslip1 = self._create_payslip(self.hr_contract1.id) + # Create Payslip 2 + self.payslip2 = self._create_payslip(self.hr_contract2.id) + + def _create_payslip(self, contract): + """Create a Pay-slip.""" + payslip = self.hr_payslip_model.create({ + 'employee_id': self.emp.id, + 'contract_id': contract, + 'struct_id': self.hr_payroll_struct.id, + 'journal_id': self.journal.id + }) + payslip.hr_verify_sheet() + payslip.process_sheet() + return payslip + + def test_hr_payroll_account_ou(self): + """Test Payroll Account Operating Unit""" + # Operating Unit (OU) of contract in Payslip should + # match with OU of Accounting Entries of that Payslip + self.assertEqual(self.payslip1.move_id.operating_unit_id, + self.payslip1.contract_id.operating_unit_id, + 'Operating Unit (OU) of contract in Payslip should ' + 'match with Accounting Entries OU') + self.assertEqual(self.payslip2.move_id.operating_unit_id, + self.payslip2.contract_id.operating_unit_id, + 'Operating Unit (OU) of contract in Payslip should ' + 'match with Accounting Entries OU')