From b3d21cc404d08226778c5497620438fbdd1bb2a2 Mon Sep 17 00:00:00 2001 From: SerpentCS Date: Wed, 24 Aug 2016 11:49:44 +0530 Subject: [PATCH 01/39] migrated hr-expense-operating-unit to 9.0 --- hr_expense_operating_unit/__init__.py | 6 +++ hr_expense_operating_unit/__openerp__.py | 24 ++++++++++++ hr_expense_operating_unit/models/__init__.py | 7 ++++ .../models/hr_expense.py | 17 ++++++++ .../security/hr_expense_security.xml | 18 +++++++++ .../views/hr_expense_view.xml | 39 +++++++++++++++++++ 6 files changed, 111 insertions(+) create mode 100644 hr_expense_operating_unit/__init__.py create mode 100644 hr_expense_operating_unit/__openerp__.py create mode 100644 hr_expense_operating_unit/models/__init__.py create mode 100644 hr_expense_operating_unit/models/hr_expense.py create mode 100644 hr_expense_operating_unit/security/hr_expense_security.xml create mode 100644 hr_expense_operating_unit/views/hr_expense_view.xml diff --git a/hr_expense_operating_unit/__init__.py b/hr_expense_operating_unit/__init__.py new file mode 100644 index 0000000000..747d0698d4 --- /dev/null +++ b/hr_expense_operating_unit/__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 models diff --git a/hr_expense_operating_unit/__openerp__.py b/hr_expense_operating_unit/__openerp__.py new file mode 100644 index 0000000000..3b3c9e747a --- /dev/null +++ b/hr_expense_operating_unit/__openerp__.py @@ -0,0 +1,24 @@ +# -*- 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 Expense Operating Unit", + "version": "9.0.1.0.0", + "license": 'LGPL-3', + "author": "Eficent", + "category": "Generic Modules/Human Resources", + "depends": ["hr_expense", "account_operating_unit"], + "description": """ +HR Expense Operating Unit +========================= +Adds a the operating unit to the HR Expense. + """, + "data": [ + "views/hr_expense_view.xml", + "security/hr_expense_security.xml" + ], + 'installable': True, +} diff --git a/hr_expense_operating_unit/models/__init__.py b/hr_expense_operating_unit/models/__init__.py new file mode 100644 index 0000000000..ea048a7df8 --- /dev/null +++ b/hr_expense_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_expense diff --git a/hr_expense_operating_unit/models/hr_expense.py b/hr_expense_operating_unit/models/hr_expense.py new file mode 100644 index 0000000000..5f7dfe6a5e --- /dev/null +++ b/hr_expense_operating_unit/models/hr_expense.py @@ -0,0 +1,17 @@ +# -*- 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, fields, models + + +class HrExpenseExpense(models.Model): + + _inherit = 'hr.expense' + + operating_unit_id = fields.Many2one('operating.unit', 'Operating Unit', + default=lambda self: + self.env['res.users']. + operating_unit_default_get(self._uid)) diff --git a/hr_expense_operating_unit/security/hr_expense_security.xml b/hr_expense_operating_unit/security/hr_expense_security.xml new file mode 100644 index 0000000000..0f98a7f8a1 --- /dev/null +++ b/hr_expense_operating_unit/security/hr_expense_security.xml @@ -0,0 +1,18 @@ + + + + + + + ['|',('operating_unit_id','=',False),('operating_unit_id','in',[g.id for g in user.operating_unit_ids])] + Expenses from allowed operating units + + + + + + + + + diff --git a/hr_expense_operating_unit/views/hr_expense_view.xml b/hr_expense_operating_unit/views/hr_expense_view.xml new file mode 100644 index 0000000000..fc5e80109a --- /dev/null +++ b/hr_expense_operating_unit/views/hr_expense_view.xml @@ -0,0 +1,39 @@ + + + + + + hr.expense.tree + hr.expense + + + + + + + + + + my.hr.expense.tree + hr.expense + + + + + + + + + + hr.expense.form + hr.expense + + + + + + + + + + From b010481d29aca32e59ef4068238d00dade6be34a Mon Sep 17 00:00:00 2001 From: SerpentCS Date: Mon, 29 Aug 2016 12:44:29 +0530 Subject: [PATCH 02/39] added OU to account move --- hr_expense_operating_unit/models/hr_expense.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/hr_expense_operating_unit/models/hr_expense.py b/hr_expense_operating_unit/models/hr_expense.py index 5f7dfe6a5e..31be051c96 100644 --- a/hr_expense_operating_unit/models/hr_expense.py +++ b/hr_expense_operating_unit/models/hr_expense.py @@ -15,3 +15,10 @@ class HrExpenseExpense(models.Model): default=lambda self: self.env['res.users']. operating_unit_default_get(self._uid)) + + @api.multi + def action_move_create(self): + res = super(HrExpenseExpense, self).action_move_create() + self.account_move_id.write({'operating_unit_id': + self.operating_unit_id.id}) + return res From 97c069ce55b59701bf6e8056cdb3999d4993bf5b Mon Sep 17 00:00:00 2001 From: SerpentCS Date: Mon, 29 Aug 2016 18:19:32 +0530 Subject: [PATCH 03/39] added Readme file and minor fixes --- hr_expense_operating_unit/README.rst | 70 ++++++++++++++++++ hr_expense_operating_unit/__openerp__.py | 10 +-- .../static/description/icon.png | Bin 0 -> 9455 bytes 3 files changed, 74 insertions(+), 6 deletions(-) create mode 100644 hr_expense_operating_unit/README.rst create mode 100644 hr_expense_operating_unit/static/description/icon.png diff --git a/hr_expense_operating_unit/README.rst b/hr_expense_operating_unit/README.rst new file mode 100644 index 0000000000..4a7c18e267 --- /dev/null +++ b/hr_expense_operating_unit/README.rst @@ -0,0 +1,70 @@ +.. image:: https://img.shields.io/badge/license-LGPLv3-blue.svg + :target: https://www.gnu.org/licenses/lgpl.html + :alt: License: LGPL-3 + +=============================== +HR Expense with Operating Units +=============================== + +This module introduces the following features: + +* Adds the Operating Unit (OU) to the Expense. + +* Security rules are defined to ensure that users can only see the Expense of that Operating Units in which they are allowed access to. + +* Adds Operating Unit (OU) to the account moves while generating accounting entries from the expense. + + +Installation +============ + +No specific installation requirements. + +Configuration +============= + +No configuration is required. + +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_expense_operating_unit/__openerp__.py b/hr_expense_operating_unit/__openerp__.py index 3b3c9e747a..151341cf37 100644 --- a/hr_expense_operating_unit/__openerp__.py +++ b/hr_expense_operating_unit/__openerp__.py @@ -8,14 +8,12 @@ "name": "HR Expense Operating Unit", "version": "9.0.1.0.0", "license": 'LGPL-3', - "author": "Eficent", + "author": "Eficent Business and IT Consulting Services S.L., " + "Serpent Consulting Services Pvt. Ltd.," + "Odoo Community Association (OCA)", + "website": "http://www.eficent.com", "category": "Generic Modules/Human Resources", "depends": ["hr_expense", "account_operating_unit"], - "description": """ -HR Expense Operating Unit -========================= -Adds a the operating unit to the HR Expense. - """, "data": [ "views/hr_expense_view.xml", "security/hr_expense_security.xml" diff --git a/hr_expense_operating_unit/static/description/icon.png b/hr_expense_operating_unit/static/description/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..3a0328b516c4980e8e44cdb63fd945757ddd132d GIT binary patch literal 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w`vTB(G`PTZaDiGBo5o(tp)qli|NeV( z@H_=R8V39rt5J5YB2Ky?4eJJ#b`_iBe2ot~6%7mLt5t8Vwi^Jy7|jWXqa3amOIoRb zOr}WVFP--DsS`1WpN%~)t3R!arKF^Q$e12KEqU36AWwnCBICpH4XCsfnyrHr>$I$4 z!DpKX$OKLWarN7nv@!uIA+~RNO)l$$w}p(;b>mx8pwYvu;dD_unryX_NhT8*Tj>BTrTTL&!?O+%Rv;b?B??gSzdp?6Uug9{ zd@V08Z$BdI?fpoCS$)t4mg4rT8Q_I}h`0d-vYZ^|dOB*Q^S|xqTV*vIg?@fVFSmMpaw0qtTRbx} z({Pg?#{2`sc9)M5N$*N|4;^t$+QP?#mov zGVC@I*lBVrOU-%2y!7%)fAKjpEFsgQc4{amtiHb95KQEwvf<(3T<9-Zm$xIew#P22 zc2Ix|App^>v6(3L_MCU0d3W##AB0M~3D00EWoKZqsJYT(#@w$Y_H7G22M~ApVFTRHMI_3be)Lkn#0F*V8Pq zc}`Cjy$bE;FJ6H7p=0y#R>`}-m4(0F>%@P|?7fx{=R^uFdISRnZ2W_xQhD{YuR3t< z{6yxu=4~JkeA;|(J6_nv#>Nvs&FuLA&PW^he@t(UwFFE8)|a!R{`E`K`i^ZnyE4$k z;(749Ix|oi$c3QbEJ3b~D_kQsPz~fIUKym($a_7dJ?o+40*OLl^{=&oq$<#Q(yyrp z{J-FAniyAw9tPbe&IhQ|a`DqFTVQGQ&Gq3!C2==4x{6EJwiPZ8zub-iXoUtkJiG{} zPaR&}_fn8_z~(=;5lD-aPWD3z8PZS@AaUiomF!G8I}Mf>e~0g#BelA-5#`cj;O5>N Xviia!U7SGha1wx#SCgwmn*{w2TRX*I literal 0 HcmV?d00001 From c320e5aa33c8107cd271ba5b73146194fd51e8de Mon Sep 17 00:00:00 2001 From: SerpentCS Date: Wed, 14 Sep 2016 11:40:34 +0530 Subject: [PATCH 04/39] Added Test Cases. --- hr_expense_operating_unit/__init__.py | 1 + hr_expense_operating_unit/tests/__init__.py | 6 + .../tests/test_hr_expense_operating_unit.py | 114 ++++++++++++++++++ 3 files changed, 121 insertions(+) create mode 100644 hr_expense_operating_unit/tests/__init__.py create mode 100644 hr_expense_operating_unit/tests/test_hr_expense_operating_unit.py diff --git a/hr_expense_operating_unit/__init__.py b/hr_expense_operating_unit/__init__.py index 747d0698d4..ef6733f80d 100644 --- a/hr_expense_operating_unit/__init__.py +++ b/hr_expense_operating_unit/__init__.py @@ -4,3 +4,4 @@ # © 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_expense_operating_unit/tests/__init__.py b/hr_expense_operating_unit/tests/__init__.py new file mode 100644 index 0000000000..be99747930 --- /dev/null +++ b/hr_expense_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_hr_expense_operating_unit diff --git a/hr_expense_operating_unit/tests/test_hr_expense_operating_unit.py b/hr_expense_operating_unit/tests/test_hr_expense_operating_unit.py new file mode 100644 index 0000000000..1d10ef5195 --- /dev/null +++ b/hr_expense_operating_unit/tests/test_hr_expense_operating_unit.py @@ -0,0 +1,114 @@ +# -*- 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.tests import common + + +class TestHrExpenseOperatingUnit(common.TransactionCase): + + def setUp(self): + super(TestHrExpenseOperatingUnit, self).setUp() + self.res_users_model = self.env['res.users'] + self.hr_expense_model = self.env['hr.expense'] + self.hr_employee_model = self.env['hr.employee'] + + self.company = self.env.ref('base.main_company') + self.partner1 = self.env.ref('base.res_partner_1') + self.partner2 = self.env.ref('base.res_partner_2') + + # Expense Product + self.product1 = self.env.ref('hr_expense.air_ticket') + + self.grp_hr_user = self.env.ref('base.group_hr_user') + self.grp_accou_mng = self.env.ref('account.group_account_manager') + self.grp_account_invoice =\ + self.env.ref('account.group_account_invoice') + + # Main Operating Unit + self.ou1 = self.env.ref('operating_unit.main_operating_unit') + # B2C Operating Unit + self.b2c = self.env.ref('operating_unit.b2c_operating_unit') + + self.user1 = self._create_user('Test HR User 1', 'user_1', 'demo1', + [self.grp_hr_user, self.grp_accou_mng, + self.grp_account_invoice], + self.company, + [self.ou1, self.b2c]) + self.user2 = self._create_user('Test HR User 2', 'user_2', 'demo2', + [self.grp_hr_user, self.grp_accou_mng, + self.grp_account_invoice], + self.company, + [self.b2c]) + + self.emp = self._create_hr_employee() + + self.hr_expense1 = self._create_hr_expense( + self.ou1, self.emp) + + self.hr_expense2 = self._create_hr_expense( + self.b2c, self.emp) + + self._post_journal_entries(self.hr_expense1) + self._post_journal_entries(self.hr_expense2) + + def _create_user(self, name, login, pwd, groups, company, operating_units, + context=None): + """Creates a user.""" + group_ids = [group.id for group in groups] + user = self.res_users_model.create({ + 'name': name, + 'login': login, + 'password': pwd, + 'email': 'example@yourcompany.com', + 'company_id': company.id, + 'company_ids': [(4, company.id)], + 'operating_unit_ids': [(4, ou.id) for ou in operating_units], + 'groups_id': [(6, 0, group_ids)] + }) + return user + + def _create_hr_employee(self): + """Creates an Employee.""" + emp = self.hr_employee_model.create({ + 'name': "Test Employee", + 'address_home_id': self.partner1.id, + }) + return emp + + def _create_hr_expense(self, operating_unit, emp): + """Creates Expense for employee.""" + expense = self.hr_expense_model.create({ + 'name': " Food Expense ", + 'product_id': self.product1.id, + 'operating_unit_id': operating_unit.id, + 'unit_amount': '10.0', + 'quantity': '5', + 'employee_id': emp.id + }) + return expense + + def _post_journal_entries(self, expense): + """Approves the Expense and creates accounting entries.""" + expense.submit_expenses() + expense.approve_expenses() + expense.action_move_create() + + def test_security(self): + # User 2 is only assigned to Operating Unit B2C, and cannot + # Access Expenses of Main Operating Unit. + record = self.hr_expense_model.sudo(self.user2.id).search( + [('id', '=', self.hr_expense1.id), + ('operating_unit_id', '=', + self.ou1.id)]) + self.assertEqual(record.ids, [], 'User 2 should not have access to %s' + % self.ou1.name) + + # Expense OU should have same OU of its accounting entries + self.assertEqual(self.hr_expense1.operating_unit_id.id, + self.hr_expense1.account_move_id.operating_unit_id.id, + "Expense OU should match with accounting entries OU") + self.assertEqual(self.hr_expense2.operating_unit_id.id, + self.hr_expense2.account_move_id.operating_unit_id.id, + "Expense OU should match with accounting entries OU") From f577b7610a444e78be6df88de5959c80f933589a Mon Sep 17 00:00:00 2001 From: SerpentCS Date: Wed, 14 Sep 2016 18:38:50 +0530 Subject: [PATCH 05/39] Added Copyrights in xml files and made minor changes. --- hr_expense_operating_unit/security/hr_expense_security.xml | 3 +++ hr_expense_operating_unit/views/hr_expense_view.xml | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/hr_expense_operating_unit/security/hr_expense_security.xml b/hr_expense_operating_unit/security/hr_expense_security.xml index 0f98a7f8a1..8eb461cb55 100644 --- a/hr_expense_operating_unit/security/hr_expense_security.xml +++ b/hr_expense_operating_unit/security/hr_expense_security.xml @@ -1,4 +1,7 @@ + diff --git a/hr_expense_operating_unit/views/hr_expense_view.xml b/hr_expense_operating_unit/views/hr_expense_view.xml index fc5e80109a..2223dafd75 100644 --- a/hr_expense_operating_unit/views/hr_expense_view.xml +++ b/hr_expense_operating_unit/views/hr_expense_view.xml @@ -1,4 +1,7 @@ + @@ -30,7 +33,7 @@ - + From c4a71eaa5229c04933159f3d6917062357782a7e Mon Sep 17 00:00:00 2001 From: ahenriquez Date: Thu, 15 Sep 2016 15:14:48 +0200 Subject: [PATCH 06/39] PEP8 issues --- hr_expense_operating_unit/README.rst | 11 ----------- .../tests/test_hr_expense_operating_unit.py | 5 ++--- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/hr_expense_operating_unit/README.rst b/hr_expense_operating_unit/README.rst index 4a7c18e267..541f92293d 100644 --- a/hr_expense_operating_unit/README.rst +++ b/hr_expense_operating_unit/README.rst @@ -14,17 +14,6 @@ This module introduces the following features: * Adds Operating Unit (OU) to the account moves while generating accounting entries from the expense. - -Installation -============ - -No specific installation requirements. - -Configuration -============= - -No configuration is required. - Usage ===== diff --git a/hr_expense_operating_unit/tests/test_hr_expense_operating_unit.py b/hr_expense_operating_unit/tests/test_hr_expense_operating_unit.py index 1d10ef5195..f0b07032cb 100644 --- a/hr_expense_operating_unit/tests/test_hr_expense_operating_unit.py +++ b/hr_expense_operating_unit/tests/test_hr_expense_operating_unit.py @@ -99,9 +99,8 @@ def test_security(self): # User 2 is only assigned to Operating Unit B2C, and cannot # Access Expenses of Main Operating Unit. record = self.hr_expense_model.sudo(self.user2.id).search( - [('id', '=', self.hr_expense1.id), - ('operating_unit_id', '=', - self.ou1.id)]) + [('id', '=', self.hr_expense1.id), + ('operating_unit_id', '=', self.ou1.id)]) self.assertEqual(record.ids, [], 'User 2 should not have access to %s' % self.ou1.name) From 663ae8e92994b5a4be315b2414f679374b655cc8 Mon Sep 17 00:00:00 2001 From: ahenriquez Date: Mon, 13 Feb 2017 11:26:08 +0100 Subject: [PATCH 07/39] Add constraint --- hr_expense_operating_unit/models/hr_expense.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/hr_expense_operating_unit/models/hr_expense.py b/hr_expense_operating_unit/models/hr_expense.py index 31be051c96..f273a6bba6 100644 --- a/hr_expense_operating_unit/models/hr_expense.py +++ b/hr_expense_operating_unit/models/hr_expense.py @@ -5,10 +5,10 @@ # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from openerp import api, fields, models +from openerp.exceptions import UserError class HrExpenseExpense(models.Model): - _inherit = 'hr.expense' operating_unit_id = fields.Many2one('operating.unit', 'Operating Unit', @@ -22,3 +22,12 @@ def action_move_create(self): self.account_move_id.write({'operating_unit_id': self.operating_unit_id.id}) return res + + @api.multi + @api.constrains('operating_unit_id', 'company_id') + def _check_company_operating_unit(self): + for rec in self: + if rec.company_id and rec.operating_unit_id and \ + rec.company_id != rec.operating_unit_id.company_id: + raise UserError(_('The Company in the Expense and in ' + 'the Operating Unit must be the same.')) From 6504416c99ede1a996f8c2478de37e5af510c240 Mon Sep 17 00:00:00 2001 From: ahenriquez Date: Tue, 14 Feb 2017 10:42:55 +0100 Subject: [PATCH 08/39] travis --- hr_expense_operating_unit/models/hr_expense.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hr_expense_operating_unit/models/hr_expense.py b/hr_expense_operating_unit/models/hr_expense.py index f273a6bba6..2d99f86ba0 100644 --- a/hr_expense_operating_unit/models/hr_expense.py +++ b/hr_expense_operating_unit/models/hr_expense.py @@ -4,7 +4,7 @@ # © 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, fields, models +from openerp import _, api, fields, models from openerp.exceptions import UserError From 2e86cc6daa87dfb47c5044ef6b2bdb613fc281c7 Mon Sep 17 00:00:00 2001 From: lreficent Date: Tue, 9 May 2017 13:04:28 +0200 Subject: [PATCH 09/39] security --- hr_expense_operating_unit/security/hr_expense_security.xml | 4 ++-- .../tests/test_hr_expense_operating_unit.py | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/hr_expense_operating_unit/security/hr_expense_security.xml b/hr_expense_operating_unit/security/hr_expense_security.xml index 8eb461cb55..b3f09df2bf 100644 --- a/hr_expense_operating_unit/security/hr_expense_security.xml +++ b/hr_expense_operating_unit/security/hr_expense_security.xml @@ -11,8 +11,8 @@ ['|',('operating_unit_id','=',False),('operating_unit_id','in',[g.id for g in user.operating_unit_ids])] Expenses from allowed operating units - - + + diff --git a/hr_expense_operating_unit/tests/test_hr_expense_operating_unit.py b/hr_expense_operating_unit/tests/test_hr_expense_operating_unit.py index f0b07032cb..a28677e4ad 100644 --- a/hr_expense_operating_unit/tests/test_hr_expense_operating_unit.py +++ b/hr_expense_operating_unit/tests/test_hr_expense_operating_unit.py @@ -4,6 +4,7 @@ # © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from openerp.tests import common +from openerp.exceptions import AccessError class TestHrExpenseOperatingUnit(common.TransactionCase): @@ -103,6 +104,10 @@ def test_security(self): ('operating_unit_id', '=', self.ou1.id)]) self.assertEqual(record.ids, [], 'User 2 should not have access to %s' % self.ou1.name) + with self.assertRaises(AccessError): + self.hr_expense1.sudo(self.user2.id).unlink() + with self.assertRaises(AccessError): + self.hr_expense1.sudo(self.user2.id).write({'name': 'new name'}) # Expense OU should have same OU of its accounting entries self.assertEqual(self.hr_expense1.operating_unit_id.id, From 286d8f025cdaa08b69e0c309bb72c86c1ccfdc2e Mon Sep 17 00:00:00 2001 From: Nikul Chaudhary Date: Fri, 21 Jul 2017 15:53:34 +0530 Subject: [PATCH 10/39] [MIG] hr_expense_operating_unit v10 --- hr_expense_operating_unit/README.rst | 4 +- hr_expense_operating_unit/__init__.py | 5 +- .../{__openerp__.py => __manifest__.py} | 7 +- hr_expense_operating_unit/models/__init__.py | 5 +- .../models/hr_expense.py | 71 +++++++++++++--- .../security/hr_expense_security.xml | 24 ++++-- hr_expense_operating_unit/tests/__init__.py | 6 +- .../tests/test_hr_expense_operating_unit.py | 82 ++++++++++++++----- .../views/hr_expense_view.xml | 37 +++++---- 9 files changed, 170 insertions(+), 71 deletions(-) rename hr_expense_operating_unit/{__openerp__.py => __manifest__.py} (77%) diff --git a/hr_expense_operating_unit/README.rst b/hr_expense_operating_unit/README.rst index 541f92293d..0758b12d85 100644 --- a/hr_expense_operating_unit/README.rst +++ b/hr_expense_operating_unit/README.rst @@ -19,7 +19,7 @@ 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 + :target: https://runbot.odoo-community.org/runbot/213/10.0 Bug Tracker =========== @@ -40,7 +40,7 @@ Images Contributors ------------ -* Eficent Business and IT Consulting Services S.L. +* Jordi Ballester Alomar * Serpent Consulting Services Pvt. Ltd. Maintainer diff --git a/hr_expense_operating_unit/__init__.py b/hr_expense_operating_unit/__init__.py index ef6733f80d..d583cdfdea 100644 --- a/hr_expense_operating_unit/__init__.py +++ b/hr_expense_operating_unit/__init__.py @@ -1,7 +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 +# Copyright 2016-17 Eficent Business and IT Consulting Services S.L. +# Copyright 2016-17 Serpent Consulting Services Pvt. Ltd. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from . import models from . import tests diff --git a/hr_expense_operating_unit/__openerp__.py b/hr_expense_operating_unit/__manifest__.py similarity index 77% rename from hr_expense_operating_unit/__openerp__.py rename to hr_expense_operating_unit/__manifest__.py index 151341cf37..a617069675 100644 --- a/hr_expense_operating_unit/__openerp__.py +++ b/hr_expense_operating_unit/__manifest__.py @@ -1,12 +1,11 @@ # -*- coding: utf-8 -*- -# © 2015 Eficent Business and IT Consulting Services S.L. - -# Jordi Ballester Alomar -# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya +# Copyright 2016-17 Eficent Business and IT Consulting Services S.L. +# Copyright 2016-17 Serpent Consulting Services Pvt. Ltd. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). { "name": "HR Expense Operating Unit", - "version": "9.0.1.0.0", + "version": "10.0.1.0.0", "license": 'LGPL-3', "author": "Eficent Business and IT Consulting Services S.L., " "Serpent Consulting Services Pvt. Ltd.," diff --git a/hr_expense_operating_unit/models/__init__.py b/hr_expense_operating_unit/models/__init__.py index ea048a7df8..51c71ae6cf 100644 --- a/hr_expense_operating_unit/models/__init__.py +++ b/hr_expense_operating_unit/models/__init__.py @@ -1,7 +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 +# Copyright 2016-17 Eficent Business and IT Consulting Services S.L. +# Copyright 2016-17 Serpent Consulting Services Pvt. Ltd. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from . import hr_expense diff --git a/hr_expense_operating_unit/models/hr_expense.py b/hr_expense_operating_unit/models/hr_expense.py index 2d99f86ba0..164fe33b2b 100644 --- a/hr_expense_operating_unit/models/hr_expense.py +++ b/hr_expense_operating_unit/models/hr_expense.py @@ -1,14 +1,15 @@ # -*- coding: utf-8 -*- -# © 2015 Eficent Business and IT Consulting Services S.L. - -# Jordi Ballester Alomar -# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya +# Copyright 2016-17 Eficent Business and IT Consulting Services S.L. +# Copyright 2016-17 Serpent Consulting Services Pvt. Ltd. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). -from openerp import _, api, fields, models -from openerp.exceptions import UserError +from odoo.tools.translate import _ +from odoo import api, fields, models +from odoo.exceptions import UserError class HrExpenseExpense(models.Model): + _inherit = 'hr.expense' operating_unit_id = fields.Many2one('operating.unit', 'Operating Unit', @@ -17,17 +18,61 @@ class HrExpenseExpense(models.Model): operating_unit_default_get(self._uid)) @api.multi - def action_move_create(self): - res = super(HrExpenseExpense, self).action_move_create() - self.account_move_id.write({'operating_unit_id': - self.operating_unit_id.id}) + @api.constrains('operating_unit_id', 'company_id') + def _check_company_operating_unit(self): + for rec in self: + if (rec.company_id and rec.operating_unit_id and rec.company_id != + rec.operating_unit_id.company_id): + raise UserError(_('Configuration error. The Company in the ' + 'Expense and in the Operating Unit ' + 'must be the same.')) + + @api.multi + @api.constrains('operating_unit_id', 'sheet_id') + def _check_expense_operating_unit(self): + for rec in self: + if (rec.sheet_id and rec.sheet_id.operating_unit_id and + rec.operating_unit_id and rec.sheet_id.operating_unit_id != + rec.operating_unit_id): + raise UserError(_('Configuration error. The Operating Unit in' + ' the Expense sheet and in the Expense must ' + 'be the same.')) + + @api.multi + def submit_expenses(self): + res = super(HrExpenseExpense, self).submit_expenses() + if len(self.mapped('operating_unit_id')) != 1 or\ + any(not expense.operating_unit_id for expense in self): + raise UserError(_('You cannot submit the Expenses having' + ' different Operating Units or with' + ' no Operating Unit!')) + if res.get('context'): + res.get('context').\ + update({'default_operating_unit_id': + self[0].operating_unit_id.id}) return res + def _prepare_move_line(self, line): + res = super(HrExpenseExpense, self)._prepare_move_line(line) + res.update({'operating_unit_id': self.operating_unit_id.id}) + return res + + +class HrExpenseSheet(models.Model): + + _inherit = "hr.expense.sheet" + + operating_unit_id = fields.Many2one('operating.unit', 'Operating Unit', + default=lambda self: + self.env['res.users']. + operating_unit_default_get(self._uid)) + @api.multi @api.constrains('operating_unit_id', 'company_id') def _check_company_operating_unit(self): for rec in self: - if rec.company_id and rec.operating_unit_id and \ - rec.company_id != rec.operating_unit_id.company_id: - raise UserError(_('The Company in the Expense and in ' - 'the Operating Unit must be the same.')) + if (rec.company_id and rec.operating_unit_id and rec.company_id != + rec.operating_unit_id.company_id): + raise UserError(_('Configuration error. The Company in the ' + 'Expense sheet and in the Operating Unit ' + 'must be the same.')) diff --git a/hr_expense_operating_unit/security/hr_expense_security.xml b/hr_expense_operating_unit/security/hr_expense_security.xml index b3f09df2bf..ab79809550 100644 --- a/hr_expense_operating_unit/security/hr_expense_security.xml +++ b/hr_expense_operating_unit/security/hr_expense_security.xml @@ -1,9 +1,8 @@ - - - + @@ -11,11 +10,22 @@ ['|',('operating_unit_id','=',False),('operating_unit_id','in',[g.id for g in user.operating_unit_ids])] Expenses from allowed operating units - - + + - - + + + ['|',('operating_unit_id','=',False),('operating_unit_id','in',[g.id for g in user.operating_unit_ids])] + Expenses from allowed operating units + + + + + + + + diff --git a/hr_expense_operating_unit/tests/__init__.py b/hr_expense_operating_unit/tests/__init__.py index be99747930..e120f2d53e 100644 --- a/hr_expense_operating_unit/tests/__init__.py +++ b/hr_expense_operating_unit/tests/__init__.py @@ -1,6 +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 +# Copyright 2016-17 Eficent Business and IT Consulting Services S.L. +# Copyright 2016-17 Serpent Consulting Services Pvt. Ltd. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + from . import test_hr_expense_operating_unit diff --git a/hr_expense_operating_unit/tests/test_hr_expense_operating_unit.py b/hr_expense_operating_unit/tests/test_hr_expense_operating_unit.py index a28677e4ad..df14bb3c1e 100644 --- a/hr_expense_operating_unit/tests/test_hr_expense_operating_unit.py +++ b/hr_expense_operating_unit/tests/test_hr_expense_operating_unit.py @@ -1,10 +1,10 @@ # -*- coding: utf-8 -*- -# © 2015 Eficent Business and IT Consulting Services S.L. - -# Jordi Ballester Alomar -# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya +# Copyright 2016-17 Eficent Business and IT Consulting Services S.L. +# Copyright 2016-17 Serpent Consulting Services Pvt. Ltd. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). -from openerp.tests import common -from openerp.exceptions import AccessError + +from odoo.tests import common +from odoo.exceptions import ValidationError, UserError class TestHrExpenseOperatingUnit(common.TransactionCase): @@ -13,6 +13,7 @@ def setUp(self): super(TestHrExpenseOperatingUnit, self).setUp() self.res_users_model = self.env['res.users'] self.hr_expense_model = self.env['hr.expense'] + self.hr_expense_sheet_model = self.env['hr.expense.sheet'] self.hr_employee_model = self.env['hr.employee'] self.company = self.env.ref('base.main_company') @@ -22,7 +23,7 @@ def setUp(self): # Expense Product self.product1 = self.env.ref('hr_expense.air_ticket') - self.grp_hr_user = self.env.ref('base.group_hr_user') + self.grp_hr_user = self.env.ref('hr.group_hr_user') self.grp_accou_mng = self.env.ref('account.group_account_manager') self.grp_account_invoice =\ self.env.ref('account.group_account_invoice') @@ -80,21 +81,30 @@ def _create_hr_employee(self): def _create_hr_expense(self, operating_unit, emp): """Creates Expense for employee.""" - expense = self.hr_expense_model.create({ - 'name': " Food Expense ", + expense_sheet = self.hr_expense_sheet_model.create({ + 'name': "Traveling Expense", + 'employee_id': emp.id, + 'operating_unit_id': operating_unit.id + }) + self.hr_expense_model.create({ + 'name': "Traveling Expense", 'product_id': self.product1.id, 'operating_unit_id': operating_unit.id, 'unit_amount': '10.0', 'quantity': '5', - 'employee_id': emp.id + 'employee_id': emp.id, + 'sheet_id': expense_sheet.id }) - return expense + return expense_sheet - def _post_journal_entries(self, expense): + def _post_journal_entries(self, expense_sheet): """Approves the Expense and creates accounting entries.""" - expense.submit_expenses() - expense.approve_expenses() - expense.action_move_create() + expense_sheet.approve_expense_sheets() + expense_sheet.action_sheet_move_create() + self.assertEqual( + expense_sheet.account_move_id.line_ids[0].operating_unit_id, + expense_sheet.operating_unit_id + ) def test_security(self): # User 2 is only assigned to Operating Unit B2C, and cannot @@ -104,15 +114,43 @@ def test_security(self): ('operating_unit_id', '=', self.ou1.id)]) self.assertEqual(record.ids, [], 'User 2 should not have access to %s' % self.ou1.name) - with self.assertRaises(AccessError): - self.hr_expense1.sudo(self.user2.id).unlink() - with self.assertRaises(AccessError): - self.hr_expense1.sudo(self.user2.id).write({'name': 'new name'}) # Expense OU should have same OU of its accounting entries - self.assertEqual(self.hr_expense1.operating_unit_id.id, - self.hr_expense1.account_move_id.operating_unit_id.id, + self.assertEqual(self.hr_expense1.expense_line_ids.operating_unit_id, + self.hr_expense1.account_move_id.line_ids. + mapped('operating_unit_id'), "Expense OU should match with accounting entries OU") - self.assertEqual(self.hr_expense2.operating_unit_id.id, - self.hr_expense2.account_move_id.operating_unit_id.id, + self.assertEqual(self.hr_expense2.expense_line_ids.operating_unit_id, + self.hr_expense2.account_move_id.line_ids. + mapped('operating_unit_id'), "Expense OU should match with accounting entries OU") + + def test_constrains_error(self): + with self.assertRaises(ValidationError): + self.hr_expense1.write({'operating_unit_id': self.ou1.id}) + self.hr_expense1.expense_line_ids.write({'operating_unit_id': + self.b2c.id}) + + self.hr_expense1.expense_line_ids.write({'state': 'draft'}) + self.hr_expense1.expense_line_ids.submit_expenses() + + company_id = self.env['res.company'].create({ + 'name': 'My Company', + 'partner_id': self.partner1.id, + 'rml_header1': 'My Company', + 'currency_id': self.env.ref('base.EUR').id + }) + + with self.assertRaises(ValidationError): + self.hr_expense1.expense_line_ids.write({'company_id': + company_id.id}) + + with self.assertRaises(UserError): + self.hr_expense1.expense_line_ids.write({ + 'state': 'draft', + 'operating_unit_id': False + }) + self.hr_expense1.expense_line_ids.submit_expenses() + + with self.assertRaises(ValidationError): + self.hr_expense1.write({'company_id': company_id.id}) diff --git a/hr_expense_operating_unit/views/hr_expense_view.xml b/hr_expense_operating_unit/views/hr_expense_view.xml index 2223dafd75..c182b9cdd9 100644 --- a/hr_expense_operating_unit/views/hr_expense_view.xml +++ b/hr_expense_operating_unit/views/hr_expense_view.xml @@ -1,9 +1,8 @@ - - - + hr.expense.tree @@ -16,27 +15,37 @@ - - my.hr.expense.tree + + hr.expense.form hr.expense - + - + + + + + + + + hr.expense.sheet.tree + hr.expense.sheet + + + - - hr.expense.form - hr.expense - + + hr.expense.sheet.form + hr.expense.sheet + - + - - + From bd4a3fcf6f9161c86a79a1be8b6ec48cf7881696 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Be=C3=B1at=20Jimenez?= Date: Mon, 25 Feb 2019 10:35:24 +0100 Subject: [PATCH 11/39] [FIX] hr_expense_operating_unit test failing --- .../models/hr_expense.py | 26 +++++++++---------- .../tests/test_hr_expense_operating_unit.py | 4 +-- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/hr_expense_operating_unit/models/hr_expense.py b/hr_expense_operating_unit/models/hr_expense.py index 164fe33b2b..ec08cf5344 100644 --- a/hr_expense_operating_unit/models/hr_expense.py +++ b/hr_expense_operating_unit/models/hr_expense.py @@ -5,7 +5,7 @@ from odoo.tools.translate import _ from odoo import api, fields, models -from odoo.exceptions import UserError +from odoo.exceptions import ValidationError class HrExpenseExpense(models.Model): @@ -23,9 +23,9 @@ def _check_company_operating_unit(self): for rec in self: if (rec.company_id and rec.operating_unit_id and rec.company_id != rec.operating_unit_id.company_id): - raise UserError(_('Configuration error. The Company in the ' - 'Expense and in the Operating Unit ' - 'must be the same.')) + raise ValidationError(_('Configuration error. The Company in ' + 'the Expense and in the Operating ' + 'Unit must be the same.')) @api.multi @api.constrains('operating_unit_id', 'sheet_id') @@ -34,18 +34,18 @@ def _check_expense_operating_unit(self): if (rec.sheet_id and rec.sheet_id.operating_unit_id and rec.operating_unit_id and rec.sheet_id.operating_unit_id != rec.operating_unit_id): - raise UserError(_('Configuration error. The Operating Unit in' - ' the Expense sheet and in the Expense must ' - 'be the same.')) + raise ValidationError(_('Configuration error. The Operating ' + 'Unit in the Expense sheet and in the ' + 'Expense must be the same.')) @api.multi def submit_expenses(self): res = super(HrExpenseExpense, self).submit_expenses() if len(self.mapped('operating_unit_id')) != 1 or\ any(not expense.operating_unit_id for expense in self): - raise UserError(_('You cannot submit the Expenses having' - ' different Operating Units or with' - ' no Operating Unit!')) + raise ValidationError(_('You cannot submit the Expenses having' + ' different Operating Units or with' + ' no Operating Unit!')) if res.get('context'): res.get('context').\ update({'default_operating_unit_id': @@ -73,6 +73,6 @@ def _check_company_operating_unit(self): for rec in self: if (rec.company_id and rec.operating_unit_id and rec.company_id != rec.operating_unit_id.company_id): - raise UserError(_('Configuration error. The Company in the ' - 'Expense sheet and in the Operating Unit ' - 'must be the same.')) + raise ValidationError(_('Configuration error. The Company in ' + 'the Expense sheet and in the' + 'Operating Unit must be the same.')) diff --git a/hr_expense_operating_unit/tests/test_hr_expense_operating_unit.py b/hr_expense_operating_unit/tests/test_hr_expense_operating_unit.py index df14bb3c1e..2f8f9e2cb8 100644 --- a/hr_expense_operating_unit/tests/test_hr_expense_operating_unit.py +++ b/hr_expense_operating_unit/tests/test_hr_expense_operating_unit.py @@ -4,7 +4,7 @@ # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from odoo.tests import common -from odoo.exceptions import ValidationError, UserError +from odoo.exceptions import ValidationError class TestHrExpenseOperatingUnit(common.TransactionCase): @@ -145,7 +145,7 @@ def test_constrains_error(self): self.hr_expense1.expense_line_ids.write({'company_id': company_id.id}) - with self.assertRaises(UserError): + with self.assertRaises(ValidationError): self.hr_expense1.expense_line_ids.write({ 'state': 'draft', 'operating_unit_id': False From 7d01b6caaa09f0e54a2cadaa9d3e87a1c2423053 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Be=C3=B1at=20Jimenez?= Date: Mon, 11 Mar 2019 08:54:53 +0100 Subject: [PATCH 12/39] [MIG] hr_expense_operating_unit: Migration to version 12.0 --- hr_expense_operating_unit/README.rst | 77 +++- hr_expense_operating_unit/__init__.py | 3 - hr_expense_operating_unit/__manifest__.py | 9 +- hr_expense_operating_unit/models/__init__.py | 3 - .../models/hr_expense.py | 37 +- .../readme/CONTRIBUTORS.rst | 2 + .../readme/DESCRIPTION.rst | 7 + hr_expense_operating_unit/readme/USAGE.rst | 5 + .../security/hr_expense_security.xml | 2 +- .../static/description/index.html | 436 ++++++++++++++++++ hr_expense_operating_unit/tests/__init__.py | 3 - .../tests/test_hr_expense_operating_unit.py | 103 +++-- .../views/hr_expense_view.xml | 4 +- 13 files changed, 597 insertions(+), 94 deletions(-) create mode 100644 hr_expense_operating_unit/readme/CONTRIBUTORS.rst create mode 100644 hr_expense_operating_unit/readme/DESCRIPTION.rst create mode 100644 hr_expense_operating_unit/readme/USAGE.rst create mode 100644 hr_expense_operating_unit/static/description/index.html diff --git a/hr_expense_operating_unit/README.rst b/hr_expense_operating_unit/README.rst index 0758b12d85..aa1199f8d0 100644 --- a/hr_expense_operating_unit/README.rst +++ b/hr_expense_operating_unit/README.rst @@ -1,10 +1,29 @@ -.. image:: https://img.shields.io/badge/license-LGPLv3-blue.svg - :target: https://www.gnu.org/licenses/lgpl.html - :alt: License: LGPL-3 - -=============================== -HR Expense with Operating Units -=============================== +========================= +HR Expense Operating Unit +========================= + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png + :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html + :alt: License: LGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Foperating--unit-lightgray.png?logo=github + :target: https://github.com/OCA/operating-unit/tree/12.0/hr_expense_operating_unit + :alt: OCA/operating-unit +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/operating-unit-12-0/operating-unit-12-0-hr_expense_operating_unit + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/213/12.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| This module introduces the following features: @@ -14,46 +33,58 @@ This module introduces the following features: * Adds Operating Unit (OU) to the account moves while generating accounting entries from the expense. +**Table of contents** + +.. contents:: + :local: + 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/10.0 +To use this module create the Operating Unit or use a created one: + +#. Once you have an OU, make sure you assign it to the desired User. +#. Create the expense with the OU. +#. The selectable OU are filtered by the users OU's. 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. +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 `_. + +Do not contact contributors directly about support or help with technical issues. Credits ======= -Images ------- +Authors +~~~~~~~ -* Odoo Community Association: `Icon `_. +* Eficent Business and IT Consulting Services S.L. +* Serpent Consulting Services Pvt. Ltd. Contributors ------------- +~~~~~~~~~~~~ * Jordi Ballester Alomar * Serpent Consulting Services Pvt. Ltd. -Maintainer ----------- +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. .. 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. +This module is part of the `OCA/operating-unit `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/hr_expense_operating_unit/__init__.py b/hr_expense_operating_unit/__init__.py index d583cdfdea..d1372d008f 100644 --- a/hr_expense_operating_unit/__init__.py +++ b/hr_expense_operating_unit/__init__.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- -# Copyright 2016-17 Eficent Business and IT Consulting Services S.L. -# Copyright 2016-17 Serpent Consulting Services Pvt. Ltd. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from . import models from . import tests diff --git a/hr_expense_operating_unit/__manifest__.py b/hr_expense_operating_unit/__manifest__.py index a617069675..64bf1b0c7f 100644 --- a/hr_expense_operating_unit/__manifest__.py +++ b/hr_expense_operating_unit/__manifest__.py @@ -1,16 +1,15 @@ -# -*- coding: utf-8 -*- -# Copyright 2016-17 Eficent Business and IT Consulting Services S.L. -# Copyright 2016-17 Serpent Consulting Services Pvt. Ltd. +# Copyright 2016-19 Eficent Business and IT Consulting Services S.L. +# Copyright 2016-19 Serpent Consulting Services Pvt. Ltd. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). { "name": "HR Expense Operating Unit", - "version": "10.0.1.0.0", + "version": "12.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)", - "website": "http://www.eficent.com", + "website": "https://github.com/OCA/operating-unit", "category": "Generic Modules/Human Resources", "depends": ["hr_expense", "account_operating_unit"], "data": [ diff --git a/hr_expense_operating_unit/models/__init__.py b/hr_expense_operating_unit/models/__init__.py index 51c71ae6cf..d82b871c92 100644 --- a/hr_expense_operating_unit/models/__init__.py +++ b/hr_expense_operating_unit/models/__init__.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- -# Copyright 2016-17 Eficent Business and IT Consulting Services S.L. -# Copyright 2016-17 Serpent Consulting Services Pvt. Ltd. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from . import hr_expense diff --git a/hr_expense_operating_unit/models/hr_expense.py b/hr_expense_operating_unit/models/hr_expense.py index ec08cf5344..12241713f5 100644 --- a/hr_expense_operating_unit/models/hr_expense.py +++ b/hr_expense_operating_unit/models/hr_expense.py @@ -1,10 +1,8 @@ -# -*- coding: utf-8 -*- -# Copyright 2016-17 Eficent Business and IT Consulting Services S.L. -# Copyright 2016-17 Serpent Consulting Services Pvt. Ltd. -# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +# Copyright 2016-19 Eficent Business and IT Consulting Services S.L. +# Copyright 2016-19 Serpent Consulting Services Pvt. Ltd. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).). -from odoo.tools.translate import _ -from odoo import api, fields, models +from odoo import api, fields, models, _ from odoo.exceptions import ValidationError @@ -39,22 +37,28 @@ def _check_expense_operating_unit(self): 'Expense must be the same.')) @api.multi - def submit_expenses(self): - res = super(HrExpenseExpense, self).submit_expenses() + def action_submit_expenses(self): + res = super(HrExpenseExpense, self).action_submit_expenses() if len(self.mapped('operating_unit_id')) != 1 or\ any(not expense.operating_unit_id for expense in self): - raise ValidationError(_('You cannot submit the Expenses having' - ' different Operating Units or with' - ' no Operating Unit!')) + raise ValidationError(_('You cannot submit the Expenses having ' + 'different Operating Units or with ' + 'no Operating Unit')) if res.get('context'): res.get('context').\ update({'default_operating_unit_id': self[0].operating_unit_id.id}) return res - def _prepare_move_line(self, line): - res = super(HrExpenseExpense, self)._prepare_move_line(line) - res.update({'operating_unit_id': self.operating_unit_id.id}) + def _get_account_move_line_values(self): + res = super(HrExpenseExpense, self)._get_account_move_line_values() + for expense in self: + res[expense.id][0].update({ + 'operating_unit_id': self.operating_unit_id.id + }) + res[expense.id][1].update({ + 'operating_unit_id': self.operating_unit_id.id + }) return res @@ -73,6 +77,5 @@ def _check_company_operating_unit(self): for rec in self: if (rec.company_id and rec.operating_unit_id and rec.company_id != rec.operating_unit_id.company_id): - raise ValidationError(_('Configuration error. The Company in ' - 'the Expense sheet and in the' - 'Operating Unit must be the same.')) + raise ValidationError(_('''Configuration error. The company in + the Expense and in the Operating Unit must be the same''')) diff --git a/hr_expense_operating_unit/readme/CONTRIBUTORS.rst b/hr_expense_operating_unit/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..03b3be1734 --- /dev/null +++ b/hr_expense_operating_unit/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Jordi Ballester Alomar +* Serpent Consulting Services Pvt. Ltd. diff --git a/hr_expense_operating_unit/readme/DESCRIPTION.rst b/hr_expense_operating_unit/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..ba571ce112 --- /dev/null +++ b/hr_expense_operating_unit/readme/DESCRIPTION.rst @@ -0,0 +1,7 @@ +This module introduces the following features: + +* Adds the Operating Unit (OU) to the Expense. + +* Security rules are defined to ensure that users can only see the Expense of that Operating Units in which they are allowed access to. + +* Adds Operating Unit (OU) to the account moves while generating accounting entries from the expense. diff --git a/hr_expense_operating_unit/readme/USAGE.rst b/hr_expense_operating_unit/readme/USAGE.rst new file mode 100644 index 0000000000..6fac1fbb09 --- /dev/null +++ b/hr_expense_operating_unit/readme/USAGE.rst @@ -0,0 +1,5 @@ +To use this module create the Operating Unit or use a created one: + +#. Once you have an OU, make sure you assign it to the desired User. +#. Create the expense with the OU. +#. The selectable OU are filtered by the users OU's. diff --git a/hr_expense_operating_unit/security/hr_expense_security.xml b/hr_expense_operating_unit/security/hr_expense_security.xml index ab79809550..2baafb6a1d 100644 --- a/hr_expense_operating_unit/security/hr_expense_security.xml +++ b/hr_expense_operating_unit/security/hr_expense_security.xml @@ -1,5 +1,5 @@ - diff --git a/hr_expense_operating_unit/static/description/index.html b/hr_expense_operating_unit/static/description/index.html new file mode 100644 index 0000000000..c8068c8848 --- /dev/null +++ b/hr_expense_operating_unit/static/description/index.html @@ -0,0 +1,436 @@ + + + + + + +HR Expense Operating Unit + + + +
+

HR Expense Operating Unit

+ + +

Beta License: LGPL-3 OCA/operating-unit Translate me on Weblate Try me on Runbot

+

This module introduces the following features:

+
    +
  • Adds the Operating Unit (OU) to the Expense.
  • +
  • Security rules are defined to ensure that users can only see the Expense of that Operating Units in which they are allowed access to.
  • +
  • Adds Operating Unit (OU) to the account moves while generating accounting entries from the expense.
  • +
+

Table of contents

+ +
+

Usage

+

To use this module create the Operating Unit or use a created one:

+
    +
  1. Once you have an OU, make sure you assign it to the desired User.
  2. +
  3. Create the expense with the OU.
  4. +
  5. The selectable OU are filtered by the users OU’s.
  6. +
+
+
+

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.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Eficent Business and IT Consulting Services S.L.
  • +
  • Serpent Consulting Services Pvt. Ltd.
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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.

+

This module is part of the OCA/operating-unit project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/hr_expense_operating_unit/tests/__init__.py b/hr_expense_operating_unit/tests/__init__.py index e120f2d53e..16b7340d16 100644 --- a/hr_expense_operating_unit/tests/__init__.py +++ b/hr_expense_operating_unit/tests/__init__.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- -# Copyright 2016-17 Eficent Business and IT Consulting Services S.L. -# Copyright 2016-17 Serpent Consulting Services Pvt. Ltd. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from . import test_hr_expense_operating_unit diff --git a/hr_expense_operating_unit/tests/test_hr_expense_operating_unit.py b/hr_expense_operating_unit/tests/test_hr_expense_operating_unit.py index 2f8f9e2cb8..2b48bb3c26 100644 --- a/hr_expense_operating_unit/tests/test_hr_expense_operating_unit.py +++ b/hr_expense_operating_unit/tests/test_hr_expense_operating_unit.py @@ -1,6 +1,5 @@ -# -*- coding: utf-8 -*- -# Copyright 2016-17 Eficent Business and IT Consulting Services S.L. -# Copyright 2016-17 Serpent Consulting Services Pvt. Ltd. +# Copyright 2016-19 Eficent Business and IT Consulting Services S.L. +# Copyright 2016-19 Serpent Consulting Services Pvt. Ltd. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from odoo.tests import common @@ -52,9 +51,6 @@ def setUp(self): self.hr_expense2 = self._create_hr_expense( self.b2c, self.emp) - self._post_journal_entries(self.hr_expense1) - self._post_journal_entries(self.hr_expense2) - def _create_user(self, name, login, pwd, groups, company, operating_units, context=None): """Creates a user.""" @@ -81,21 +77,15 @@ def _create_hr_employee(self): def _create_hr_expense(self, operating_unit, emp): """Creates Expense for employee.""" - expense_sheet = self.hr_expense_sheet_model.create({ - 'name': "Traveling Expense", - 'employee_id': emp.id, - 'operating_unit_id': operating_unit.id - }) - self.hr_expense_model.create({ + hr_expense = self.hr_expense_model.create({ 'name': "Traveling Expense", 'product_id': self.product1.id, 'operating_unit_id': operating_unit.id, 'unit_amount': '10.0', 'quantity': '5', - 'employee_id': emp.id, - 'sheet_id': expense_sheet.id + 'employee_id': emp.id }) - return expense_sheet + return hr_expense def _post_journal_entries(self, expense_sheet): """Approves the Expense and creates accounting entries.""" @@ -114,25 +104,51 @@ def test_security(self): ('operating_unit_id', '=', self.ou1.id)]) self.assertEqual(record.ids, [], 'User 2 should not have access to %s' % self.ou1.name) - + # Create the expense sheet + hr_expense_dict1 = self.hr_expense1.action_submit_expenses() + self.hr_expense_sheet1 = self.hr_expense_sheet_model.create({ + 'name': hr_expense_dict1['context'] + ['default_name'], + 'employee_id': hr_expense_dict1['context'] + ['default_employee_id'], + 'expense_line_ids': [(4, + hr_expense_dict1['context'] + ['default_expense_line_ids'][0])], + 'operating_unit_id': hr_expense_dict1['context'] + ['default_operating_unit_id'] + }) + self.hr_expense1.write({ + 'sheet_id': self.hr_expense_sheet1.id + }) + self._post_journal_entries(self.hr_expense_sheet1) # Expense OU should have same OU of its accounting entries - self.assertEqual(self.hr_expense1.expense_line_ids.operating_unit_id, - self.hr_expense1.account_move_id.line_ids. - mapped('operating_unit_id'), - "Expense OU should match with accounting entries OU") - self.assertEqual(self.hr_expense2.expense_line_ids.operating_unit_id, - self.hr_expense2.account_move_id.line_ids. - mapped('operating_unit_id'), - "Expense OU should match with accounting entries OU") + self.assertEqual( + self.hr_expense_sheet1.expense_line_ids.operating_unit_id, + self.hr_expense_sheet1.account_move_id.line_ids.mapped( + 'operating_unit_id'), + "Expense OU should match with accounting entries OU") def test_constrains_error(self): with self.assertRaises(ValidationError): - self.hr_expense1.write({'operating_unit_id': self.ou1.id}) - self.hr_expense1.expense_line_ids.write({'operating_unit_id': - self.b2c.id}) + hr_expense_dict1 = self.hr_expense1.action_submit_expenses() + self.hr_expense_sheet1 = self.hr_expense_sheet_model.create({ + 'name': hr_expense_dict1['context'] + ['default_name'], + 'employee_id': hr_expense_dict1['context'] + ['default_employee_id'], + 'expense_line_ids': [(4, + hr_expense_dict1['context'] + ['default_expense_line_ids'][0])], + 'operating_unit_id': hr_expense_dict1['context'] + ['default_operating_unit_id'] - self.hr_expense1.expense_line_ids.write({'state': 'draft'}) - self.hr_expense1.expense_line_ids.submit_expenses() + }) + self.hr_expense1.write({ + 'sheet_id': self.hr_expense_sheet1.id + }) + self.hr_expense_sheet1.expense_line_ids.write({ + 'operating_unit_id': self.b2c.id + }) company_id = self.env['res.company'].create({ 'name': 'My Company', @@ -142,15 +158,28 @@ def test_constrains_error(self): }) with self.assertRaises(ValidationError): - self.hr_expense1.expense_line_ids.write({'company_id': - company_id.id}) + hr_expense_dict2 = self.hr_expense2.action_submit_expenses() + self.hr_expense_sheet2 = self.hr_expense_sheet_model.create({ + 'name': hr_expense_dict2['context']['default_name'], + 'employee_id': hr_expense_dict2['context'] + ['default_employee_id'], + 'expense_line_ids': [(4, + hr_expense_dict2['context'] + ['default_expense_line_ids'][0])], + 'operating_unit_id': hr_expense_dict2['context'] + ['default_operating_unit_id'], + }) + self.hr_expense_sheet2.expense_line_ids.write({ + 'company_id': company_id.id}) with self.assertRaises(ValidationError): - self.hr_expense1.expense_line_ids.write({ - 'state': 'draft', - 'operating_unit_id': False + self.hr_expense3 = self.hr_expense_model.create({ + 'name': "Traveling Expense", + 'product_id': self.product1.id, + 'unit_amount': '10.0', + 'quantity': '5', + 'operating_unit_id': False, + 'employee_id': self.emp.id, }) - self.hr_expense1.expense_line_ids.submit_expenses() - with self.assertRaises(ValidationError): - self.hr_expense1.write({'company_id': company_id.id}) + self.hr_expense3.action_submit_expenses() diff --git a/hr_expense_operating_unit/views/hr_expense_view.xml b/hr_expense_operating_unit/views/hr_expense_view.xml index c182b9cdd9..de5258ca54 100644 --- a/hr_expense_operating_unit/views/hr_expense_view.xml +++ b/hr_expense_operating_unit/views/hr_expense_view.xml @@ -1,5 +1,5 @@ - @@ -18,7 +18,7 @@ hr.expense.form hr.expense - + From fba501f4bce60a8365776ece87982f317b61c5ff Mon Sep 17 00:00:00 2001 From: ahenriquez Date: Mon, 14 Oct 2019 10:54:02 +0200 Subject: [PATCH 13/39] [FIX]domain operating units on expenses --- hr_expense_operating_unit/views/hr_expense_view.xml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/hr_expense_operating_unit/views/hr_expense_view.xml b/hr_expense_operating_unit/views/hr_expense_view.xml index de5258ca54..59292ccb04 100644 --- a/hr_expense_operating_unit/views/hr_expense_view.xml +++ b/hr_expense_operating_unit/views/hr_expense_view.xml @@ -21,7 +21,9 @@ - + @@ -43,7 +45,9 @@ - + From 4dab4366fb7ac8ebbf4c906aea7d96ea056e274a Mon Sep 17 00:00:00 2001 From: oca-travis Date: Mon, 14 Oct 2019 09:59:54 +0000 Subject: [PATCH 14/39] [UPD] Update hr_expense_operating_unit.pot --- .../i18n/hr_expense_operating_unit.pot | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 hr_expense_operating_unit/i18n/hr_expense_operating_unit.pot diff --git a/hr_expense_operating_unit/i18n/hr_expense_operating_unit.pot b/hr_expense_operating_unit/i18n/hr_expense_operating_unit.pot new file mode 100644 index 0000000000..2df43e2fd3 --- /dev/null +++ b/hr_expense_operating_unit/i18n/hr_expense_operating_unit.pot @@ -0,0 +1,56 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * hr_expense_operating_unit +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: hr_expense_operating_unit +#: code:addons/hr_expense_operating_unit/models/hr_expense.py:24 +#, python-format +msgid "Configuration error. The Company in the Expense and in the Operating Unit must be the same." +msgstr "" + +#. module: hr_expense_operating_unit +#: code:addons/hr_expense_operating_unit/models/hr_expense.py:35 +#, python-format +msgid "Configuration error. The Operating Unit in the Expense sheet and in the Expense must be the same." +msgstr "" + +#. module: hr_expense_operating_unit +#: code:addons/hr_expense_operating_unit/models/hr_expense.py:80 +#, python-format +msgid "Configuration error. The company in\n" +" the Expense and in the Operating Unit must be the same" +msgstr "" + +#. module: hr_expense_operating_unit +#: model:ir.model,name:hr_expense_operating_unit.model_hr_expense +msgid "Expense" +msgstr "" + +#. module: hr_expense_operating_unit +#: model:ir.model,name:hr_expense_operating_unit.model_hr_expense_sheet +msgid "Expense Report" +msgstr "" + +#. module: hr_expense_operating_unit +#: model:ir.model.fields,field_description:hr_expense_operating_unit.field_hr_expense__operating_unit_id +#: model:ir.model.fields,field_description:hr_expense_operating_unit.field_hr_expense_sheet__operating_unit_id +msgid "Operating Unit" +msgstr "" + +#. module: hr_expense_operating_unit +#: code:addons/hr_expense_operating_unit/models/hr_expense.py:44 +#, python-format +msgid "You cannot submit the Expenses having different Operating Units or with no Operating Unit" +msgstr "" + From b26a9fb180cbd73289e9329f2f246b8a3553d344 Mon Sep 17 00:00:00 2001 From: OCA-git-bot Date: Mon, 14 Oct 2019 10:14:02 +0000 Subject: [PATCH 15/39] [UPD] README.rst --- hr_expense_operating_unit/static/description/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hr_expense_operating_unit/static/description/index.html b/hr_expense_operating_unit/static/description/index.html index c8068c8848..d518e032ae 100644 --- a/hr_expense_operating_unit/static/description/index.html +++ b/hr_expense_operating_unit/static/description/index.html @@ -3,7 +3,7 @@ - + HR Expense Operating Unit