diff --git a/rma_operating_unit/README.rst b/rma_operating_unit/README.rst new file mode 100644 index 00000000..b09234cb --- /dev/null +++ b/rma_operating_unit/README.rst @@ -0,0 +1,33 @@ +.. image:: https://img.shields.io/badge/license-LGPLv3-blue.svg + :target: https://www.gnu.org/licenses/lgpl.html + :alt: License: LGPL-3 + +============================== +RMA with Operating Units +============================== + +This module introduces the following features: + +* Adds the Operating Unit (OU) to the RMA order. + +* Users can only view and manage the rma orders associated to their operating + unit. + + +Usage +===== + +* The default operating unit of the RMA comes from the default operating unit + of the user + + +Contributors +------------ + +* Aaron Henriquez + + +Maintainer +---------- + +This module is maintained by Eficent. \ No newline at end of file diff --git a/rma_operating_unit/__init__.py b/rma_operating_unit/__init__.py new file mode 100644 index 00000000..c5d44257 --- /dev/null +++ b/rma_operating_unit/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from . import models +from . import tests diff --git a/rma_operating_unit/__openerp__.py b/rma_operating_unit/__openerp__.py new file mode 100644 index 00000000..0f79c0ee --- /dev/null +++ b/rma_operating_unit/__openerp__.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +# © 2017 Eficent Business and IT Consulting Services S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +{ + "name": "Operating Unit in RMA Orders", + "version": "9.0.1.0.0", + "author": "Eficent", + "license": "LGPL-3", + "website": "http://www.eficent.com", + "category": "Operating Units", + "depends": ["rma", "operating_unit"], + "data": [ + "security/rma_security.xml", + "views/rma_order_view.xml" + ], + 'installable': True, +} diff --git a/rma_operating_unit/models/__init__.py b/rma_operating_unit/models/__init__.py new file mode 100644 index 00000000..9cf2d984 --- /dev/null +++ b/rma_operating_unit/models/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from . import rma_order diff --git a/rma_operating_unit/models/rma_order.py b/rma_operating_unit/models/rma_order.py new file mode 100644 index 00000000..b5757cb4 --- /dev/null +++ b/rma_operating_unit/models/rma_order.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# © 2017 Eficent Business and IT Consulting Services S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from openerp import api, fields, models, _ +from openerp.exceptions import ValidationError + + +class RmaOrder(models.Model): + + _inherit = "rma.order" + + @api.model + def _default_operating_unit(self): + return self.env.user.default_operating_unit_id + + operating_unit_id = fields.Many2one( + comodel_name='operating.unit', + string='Operating Unit', + default=_default_operating_unit, + ) diff --git a/rma_operating_unit/security/rma_security.xml b/rma_operating_unit/security/rma_security.xml new file mode 100644 index 00000000..1114b9bf --- /dev/null +++ b/rma_operating_unit/security/rma_security.xml @@ -0,0 +1,20 @@ + + + + + + + + ['|',('operating_unit_id','=',False),('operating_unit_id','in',[g.id for g in user.operating_unit_ids])] + RMA from allowed operating units + + + + + + + + + diff --git a/rma_operating_unit/tests/__init__.py b/rma_operating_unit/tests/__init__.py new file mode 100644 index 00000000..b7ac6782 --- /dev/null +++ b/rma_operating_unit/tests/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +from . import test_rma_operating_unit diff --git a/rma_operating_unit/tests/test_rma_operating_unit.py b/rma_operating_unit/tests/test_rma_operating_unit.py new file mode 100644 index 00000000..1534cb7b --- /dev/null +++ b/rma_operating_unit/tests/test_rma_operating_unit.py @@ -0,0 +1,77 @@ +# -*- coding: utf-8 -*- +# © 2017 Eficent Business and IT Consulting Services S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +from openerp.tests import common + + +class TestRmaOperatingUnit(common.TransactionCase): + + def setUp(self): + super(TestRmaOperatingUnit, self).setUp() + self.res_users_model = self.env['res.users'] + self.rma_model = self.env['rma.order'] + + self.company = self.env.ref('base.main_company') + self.partner = self.env.ref('base.res_partner_1') + self.grp_rma_manager = self.env.ref('rma.group_rma_manager') + + # Main Operating Unit + self.main_OU = self.env.ref('operating_unit.main_operating_unit') + # B2C Operating Unit + self.b2c_OU = self.env.ref('operating_unit.b2c_operating_unit') + + # Users + self.user1 = self._create_user('user_1', + [self.grp_rma_manager], + self.company, + [self.main_OU, self.b2c_OU]) + self.user2 = self._create_user('user_2', + [self.grp_rma_manager], + self.company, + [self.b2c_OU]) + self.user3 = self._create_user('user_3', + [self.grp_rma_manager], + self.company, + [self.main_OU, self.b2c_OU]) + + # RMA Orders + self.rma_order1 = self._create_rma(self.user1.id, self.main_OU) + self.rma_order2 = self._create_rma(self.user2.id, self.b2c_OU) + self.rma_order3 = self._create_rma(self.user3.id) + + def _create_user(self, login, groups, company, operating_units): + """Creates a user.""" + group_ids = [group.id for group in groups] + user = self.res_users_model.create({ + 'name': login, + 'login': login, + 'password': 'demo', + '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_rma(self, uid, operating_unit=False): + """Creates an RMA""" + if not operating_unit: + operating_unit = self.rma_model.sudo(uid).\ + _default_operating_unit() + rma_order = self.rma_model.sudo(uid).create({ + 'operating_unit_id': operating_unit.id, + 'partner_id': self.partner.id, + 'user_id': uid, + }) + return rma_order + + def test_security(self): + # User 2 is only assigned to Operating Unit B2C, and cannot + # access RMA of Main Operating Unit. + record = self.rma_model.sudo( + self.user2.id).search([('id', '=', self.rma_order1.id), + ('operating_unit_id', '=', + self.main_OU.id)]) + self.assertEqual(record.ids, [], 'User 2 should not have access to ' + 'OU %s.' % self.main_OU.name) diff --git a/rma_operating_unit/views/rma_order_view.xml b/rma_operating_unit/views/rma_order_view.xml new file mode 100644 index 00000000..770398e2 --- /dev/null +++ b/rma_operating_unit/views/rma_order_view.xml @@ -0,0 +1,67 @@ + + + + + + + rma.order.tree + rma.order + + + + + + + + + + rma.order.supplier.tree + rma.order + + + + + + + + + + rma.order.supplier.form + rma.order + + + + + + + + + + + rma.order.form + rma.order + + + + + + + + + + + rma.order.select + rma.order + + + + + + + + + +