From 76d3dbe276467089182d152d993b5cc1d1485b45 Mon Sep 17 00:00:00 2001 From: aheficent Date: Thu, 3 Aug 2017 18:13:44 +0200 Subject: [PATCH 01/13] [ADD] rma_operating_unit --- rma_operating_unit/README.rst | 33 ++++++++ rma_operating_unit/__init__.py | 5 ++ rma_operating_unit/__openerp__.py | 18 +++++ rma_operating_unit/models/__init__.py | 4 + rma_operating_unit/models/rma_order.py | 21 +++++ rma_operating_unit/security/rma_security.xml | 20 +++++ rma_operating_unit/tests/__init__.py | 3 + .../tests/test_rma_operating_unit.py | 77 +++++++++++++++++++ rma_operating_unit/views/rma_order_view.xml | 67 ++++++++++++++++ 9 files changed, 248 insertions(+) create mode 100644 rma_operating_unit/README.rst create mode 100644 rma_operating_unit/__init__.py create mode 100644 rma_operating_unit/__openerp__.py create mode 100644 rma_operating_unit/models/__init__.py create mode 100644 rma_operating_unit/models/rma_order.py create mode 100644 rma_operating_unit/security/rma_security.xml create mode 100644 rma_operating_unit/tests/__init__.py create mode 100644 rma_operating_unit/tests/test_rma_operating_unit.py create mode 100644 rma_operating_unit/views/rma_order_view.xml 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 + + + + + + + + + + From be856638ab069be47a114469fd94772482502a4a Mon Sep 17 00:00:00 2001 From: aheficent Date: Tue, 9 Jan 2018 14:02:51 +0100 Subject: [PATCH 02/13] [MIG]rma_operating_unit to v10 --- rma_operating_unit/README.rst | 2 +- .../{__openerp__.py => __manifest__.py} | 7 +- rma_operating_unit/models/__init__.py | 1 + rma_operating_unit/models/rma_order.py | 16 ++- rma_operating_unit/models/rma_order_line.py | 22 ++++ .../tests/test_rma_operating_unit.py | 42 ++++++- .../views/rma_order_line_view.xml | 69 +++++++++++ rma_operating_unit/views/rma_order_view.xml | 113 +++++++++--------- 8 files changed, 204 insertions(+), 68 deletions(-) rename rma_operating_unit/{__openerp__.py => __manifest__.py} (73%) create mode 100644 rma_operating_unit/models/rma_order_line.py create mode 100644 rma_operating_unit/views/rma_order_line_view.xml diff --git a/rma_operating_unit/README.rst b/rma_operating_unit/README.rst index b09234cb..43429a5c 100644 --- a/rma_operating_unit/README.rst +++ b/rma_operating_unit/README.rst @@ -30,4 +30,4 @@ Contributors Maintainer ---------- -This module is maintained by Eficent. \ No newline at end of file +This module is maintained by Eficent. diff --git a/rma_operating_unit/__openerp__.py b/rma_operating_unit/__manifest__.py similarity index 73% rename from rma_operating_unit/__openerp__.py rename to rma_operating_unit/__manifest__.py index 0f79c0ee..5010d934 100644 --- a/rma_operating_unit/__openerp__.py +++ b/rma_operating_unit/__manifest__.py @@ -3,8 +3,8 @@ # 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", + "name": "Operating Unit in RMA Groups", + "version": "10.0.1.0.0", "author": "Eficent", "license": "LGPL-3", "website": "http://www.eficent.com", @@ -12,7 +12,8 @@ "depends": ["rma", "operating_unit"], "data": [ "security/rma_security.xml", - "views/rma_order_view.xml" + "views/rma_order_view.xml", + "views/rma_order_line_view.xml", ], 'installable': True, } diff --git a/rma_operating_unit/models/__init__.py b/rma_operating_unit/models/__init__.py index 9cf2d984..935b7adb 100644 --- a/rma_operating_unit/models/__init__.py +++ b/rma_operating_unit/models/__init__.py @@ -2,3 +2,4 @@ # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from . import rma_order +from . import rma_order_line diff --git a/rma_operating_unit/models/rma_order.py b/rma_operating_unit/models/rma_order.py index b5757cb4..d11f992d 100644 --- a/rma_operating_unit/models/rma_order.py +++ b/rma_operating_unit/models/rma_order.py @@ -2,14 +2,26 @@ # © 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 +from odoo import api, fields, models, _ +from odoo.exceptions import ValidationError class RmaOrder(models.Model): _inherit = "rma.order" + @api.multi + @api.constrains('rma_line_ids', 'rma_line_ids.operating_unit') + def _check_operating_unit(self): + for rma in self: + bad_lines = rma.rma_line_ids.filtered( + lambda l: l.operating_unit_id != rma.operating_unit_id) + if bad_lines: + raise ValidationError( + _('The operating unit of the rma lines have to match the' + ' one of the group')) + return True + @api.model def _default_operating_unit(self): return self.env.user.default_operating_unit_id diff --git a/rma_operating_unit/models/rma_order_line.py b/rma_operating_unit/models/rma_order_line.py new file mode 100644 index 00000000..c96020c9 --- /dev/null +++ b/rma_operating_unit/models/rma_order_line.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# © 2018 Eficent Business and IT Consulting Services S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from odoo import api, fields, models + + +class RmaOrderLine(models.Model): + + _inherit = "rma.order.line" + + @api.model + def _default_operating_unit(self): + if self.rma_id.operating_unit_id: + return self.rma_id.operating_unit_id.id + 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/tests/test_rma_operating_unit.py b/rma_operating_unit/tests/test_rma_operating_unit.py index 1534cb7b..94f3bf2e 100644 --- a/rma_operating_unit/tests/test_rma_operating_unit.py +++ b/rma_operating_unit/tests/test_rma_operating_unit.py @@ -1,7 +1,8 @@ # -*- 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 +from odoo.tests import common +from odoo import exceptions class TestRmaOperatingUnit(common.TransactionCase): @@ -10,10 +11,14 @@ class TestRmaOperatingUnit(common.TransactionCase): super(TestRmaOperatingUnit, self).setUp() self.res_users_model = self.env['res.users'] self.rma_model = self.env['rma.order'] + self.rma_line_model = self.env['rma.order.line'] 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') + self.grp_ou = self.env.ref("operating_unit.group_multi_operating_unit") + self.grp_stock = self.env.ref("stock.group_stock_manager") + self.product = self.env.ref('product.product_product_12') # Main Operating Unit self.main_OU = self.env.ref('operating_unit.main_operating_unit') @@ -22,15 +27,18 @@ class TestRmaOperatingUnit(common.TransactionCase): # Users self.user1 = self._create_user('user_1', - [self.grp_rma_manager], + [self.grp_rma_manager, self.grp_ou, + self.grp_stock], self.company, [self.main_OU, self.b2c_OU]) self.user2 = self._create_user('user_2', - [self.grp_rma_manager], + [self.grp_rma_manager, self.grp_ou, + self.grp_stock], self.company, [self.b2c_OU]) self.user3 = self._create_user('user_3', - [self.grp_rma_manager], + [self.grp_rma_manager, self.grp_ou, + self.grp_stock], self.company, [self.main_OU, self.b2c_OU]) @@ -66,6 +74,25 @@ class TestRmaOperatingUnit(common.TransactionCase): }) return rma_order + def _create_rma_line(self, rma, uid, operating_unit): + """Creates an RMA""" + rma_order_line = self.rma_line_model.sudo(uid).create({ + 'operating_unit_id': operating_unit.id, + 'rma_id': rma.id, + 'partner_id': self.partner.id, + 'in_route_id': 1, + 'out_route_id': 1, + 'in_warehouse_id': 1, + 'out_warehouse_id': 1, + 'location_id': 1, + 'receipt_policy': 'ordered', + 'delivery_policy': 'ordered', + 'name': self.product.name, + 'product_id': self.product.id, + 'uom_id': self.product.uom_id.id + }) + return rma_order_line + def test_security(self): # User 2 is only assigned to Operating Unit B2C, and cannot # access RMA of Main Operating Unit. @@ -75,3 +102,10 @@ class TestRmaOperatingUnit(common.TransactionCase): self.main_OU.id)]) self.assertEqual(record.ids, [], 'User 2 should not have access to ' 'OU %s.' % self.main_OU.name) + + def test_constraint(self): + # RMA group should contain rma lines for the same OU + with self.assertRaises(exceptions.ValidationError): + self._create_rma_line(self.rma_order1, self.user1.id, self.main_OU) + self._create_rma_line(self.rma_order1, self.user1.id, self.b2c_OU) + self.rma_order1._check_operating_unit() diff --git a/rma_operating_unit/views/rma_order_line_view.xml b/rma_operating_unit/views/rma_order_line_view.xml new file mode 100644 index 00000000..6695d38c --- /dev/null +++ b/rma_operating_unit/views/rma_order_line_view.xml @@ -0,0 +1,69 @@ + + + + + rma.order.line.tree + rma.order.line + + + + + + + + + + rma.order.line.supplier.tree + rma.order.line + + + + + + + + + + rma.order.supplier.tree + rma.order + + + + + + + + + rma.order.line.supplier.form + rma.order.line + + + + + + + + + + rma.order.line.form + rma.order.line + + + + + + + + + + rma.order.line.select + rma.order.line + + + + + + + + diff --git a/rma_operating_unit/views/rma_order_view.xml b/rma_operating_unit/views/rma_order_view.xml index 770398e2..40f5f22d 100644 --- a/rma_operating_unit/views/rma_order_view.xml +++ b/rma_operating_unit/views/rma_order_view.xml @@ -1,67 +1,64 @@ - - - - - rma.order.tree - rma.order - - - - - + + + rma.order.tree + rma.order + + + + - + + - - rma.order.supplier.tree - rma.order - - - - - + + rma.order.supplier.tree + rma.order + + + + - + + - - rma.order.supplier.form - rma.order - - - - - - + + rma.order.supplier.form + rma.order + + + + + + + + + + + rma.order.form + rma.order + + + + + + + + + + + rma.order.select + rma.order + + + + - + + - - rma.order.form - rma.order - - - - - - - - - - - rma.order.select - rma.order - - - - - - - - - - + From 1b5c77d94694af1e1f9557ec34f9bc9842e59ba2 Mon Sep 17 00:00:00 2001 From: Nikul Chaudhary Date: Wed, 10 Jan 2018 13:54:55 +0100 Subject: [PATCH 03/13] [FIX] Fixed UT & Travis --- rma_operating_unit/models/rma_order.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rma_operating_unit/models/rma_order.py b/rma_operating_unit/models/rma_order.py index d11f992d..923724d1 100644 --- a/rma_operating_unit/models/rma_order.py +++ b/rma_operating_unit/models/rma_order.py @@ -11,7 +11,7 @@ class RmaOrder(models.Model): _inherit = "rma.order" @api.multi - @api.constrains('rma_line_ids', 'rma_line_ids.operating_unit') + @api.constrains('rma_line_ids', 'rma_line_ids.operating_unit_id') def _check_operating_unit(self): for rma in self: bad_lines = rma.rma_line_ids.filtered( From fcaef49fdfb5edcfe1e21e9149d2855a752e0bf2 Mon Sep 17 00:00:00 2001 From: Maxime Chambreuil Date: Fri, 9 Feb 2018 12:35:23 -0600 Subject: [PATCH 04/13] [MIG] Migrate configuration and cleanup --- rma_operating_unit/__manifest__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rma_operating_unit/__manifest__.py b/rma_operating_unit/__manifest__.py index 5010d934..1586b020 100644 --- a/rma_operating_unit/__manifest__.py +++ b/rma_operating_unit/__manifest__.py @@ -15,5 +15,5 @@ "views/rma_order_view.xml", "views/rma_order_line_view.xml", ], - 'installable': True, + 'installable': False, } From 250656eb293bba0af8de99049d3b3948a196165d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Be=C3=B1at=20Jimenez?= Date: Thu, 14 Feb 2019 09:51:31 +0100 Subject: [PATCH 05/13] [MIG] rma_operating_unit: Migration to v12 --- rma_operating_unit/README.rst | 4 ++-- rma_operating_unit/__init__.py | 1 - rma_operating_unit/__manifest__.py | 8 +++----- rma_operating_unit/models/__init__.py | 1 - rma_operating_unit/models/rma_order.py | 3 +-- rma_operating_unit/models/rma_order_line.py | 3 +-- rma_operating_unit/security/rma_security.xml | 2 +- rma_operating_unit/tests/__init__.py | 1 - rma_operating_unit/tests/test_rma_operating_unit.py | 3 +-- rma_operating_unit/views/rma_order_line_view.xml | 2 +- rma_operating_unit/views/rma_order_view.xml | 2 +- 11 files changed, 11 insertions(+), 19 deletions(-) diff --git a/rma_operating_unit/README.rst b/rma_operating_unit/README.rst index 43429a5c..1545840d 100644 --- a/rma_operating_unit/README.rst +++ b/rma_operating_unit/README.rst @@ -25,9 +25,9 @@ Contributors ------------ * Aaron Henriquez - +* Beñat Jimenez Maintainer ---------- -This module is maintained by Eficent. +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 index c5d44257..8ef85858 100644 --- a/rma_operating_unit/__init__.py +++ b/rma_operating_unit/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from . import models diff --git a/rma_operating_unit/__manifest__.py b/rma_operating_unit/__manifest__.py index 1586b020..ec809583 100644 --- a/rma_operating_unit/__manifest__.py +++ b/rma_operating_unit/__manifest__.py @@ -1,13 +1,12 @@ -# -*- coding: utf-8 -*- -# © 2017 Eficent Business and IT Consulting Services S.L. +# © 2017-19 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 Groups", - "version": "10.0.1.0.0", + "version": "12.0.1.0.0", "author": "Eficent", "license": "LGPL-3", - "website": "http://www.eficent.com", + "website": "https://www.eficent.com", "category": "Operating Units", "depends": ["rma", "operating_unit"], "data": [ @@ -15,5 +14,4 @@ "views/rma_order_view.xml", "views/rma_order_line_view.xml", ], - 'installable': False, } diff --git a/rma_operating_unit/models/__init__.py b/rma_operating_unit/models/__init__.py index 935b7adb..5141b758 100644 --- a/rma_operating_unit/models/__init__.py +++ b/rma_operating_unit/models/__init__.py @@ -1,4 +1,3 @@ -# -*- 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 index 923724d1..072cef98 100644 --- a/rma_operating_unit/models/rma_order.py +++ b/rma_operating_unit/models/rma_order.py @@ -1,5 +1,4 @@ -# -*- coding: utf-8 -*- -# © 2017 Eficent Business and IT Consulting Services S.L. +# © 2017-19 Eficent Business and IT Consulting Services S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from odoo import api, fields, models, _ diff --git a/rma_operating_unit/models/rma_order_line.py b/rma_operating_unit/models/rma_order_line.py index c96020c9..799a1ff7 100644 --- a/rma_operating_unit/models/rma_order_line.py +++ b/rma_operating_unit/models/rma_order_line.py @@ -1,5 +1,4 @@ -# -*- coding: utf-8 -*- -# © 2018 Eficent Business and IT Consulting Services S.L. +# © 2017-19 Eficent Business and IT Consulting Services S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from odoo import api, fields, models diff --git a/rma_operating_unit/security/rma_security.xml b/rma_operating_unit/security/rma_security.xml index 1114b9bf..5eb9a5bf 100644 --- a/rma_operating_unit/security/rma_security.xml +++ b/rma_operating_unit/security/rma_security.xml @@ -1,5 +1,5 @@ - diff --git a/rma_operating_unit/tests/__init__.py b/rma_operating_unit/tests/__init__.py index b7ac6782..85351693 100644 --- a/rma_operating_unit/tests/__init__.py +++ b/rma_operating_unit/tests/__init__.py @@ -1,3 +1,2 @@ -# -*- 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 index 94f3bf2e..5dd028e5 100644 --- a/rma_operating_unit/tests/test_rma_operating_unit.py +++ b/rma_operating_unit/tests/test_rma_operating_unit.py @@ -1,5 +1,4 @@ -# -*- coding: utf-8 -*- -# © 2017 Eficent Business and IT Consulting Services S.L. +# © 2017-19 Eficent Business and IT Consulting Services S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from odoo.tests import common from odoo import exceptions diff --git a/rma_operating_unit/views/rma_order_line_view.xml b/rma_operating_unit/views/rma_order_line_view.xml index 6695d38c..56d77093 100644 --- a/rma_operating_unit/views/rma_order_line_view.xml +++ b/rma_operating_unit/views/rma_order_line_view.xml @@ -1,5 +1,5 @@ - diff --git a/rma_operating_unit/views/rma_order_view.xml b/rma_operating_unit/views/rma_order_view.xml index 40f5f22d..87aedcfe 100644 --- a/rma_operating_unit/views/rma_order_view.xml +++ b/rma_operating_unit/views/rma_order_view.xml @@ -1,5 +1,5 @@ - From 3d6edd5eb856979519ae5a8bf56255f801d2687b Mon Sep 17 00:00:00 2001 From: aaron Date: Fri, 18 May 2018 12:41:49 +0200 Subject: [PATCH 06/13] [FIX]rma_operating_unit view domains --- rma_operating_unit/views/rma_order_line_view.xml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/rma_operating_unit/views/rma_order_line_view.xml b/rma_operating_unit/views/rma_order_line_view.xml index 56d77093..31655409 100644 --- a/rma_operating_unit/views/rma_order_line_view.xml +++ b/rma_operating_unit/views/rma_order_line_view.xml @@ -39,9 +39,12 @@ rma.order.line - + + + [('type','=','supplier'),('out_warehouse_id.operating_unit_id', '=', operating_unit_id)] + @@ -50,16 +53,19 @@ rma.order.line - + + + [('type','=','customer'),('in_warehouse_id.operating_unit_id', '=', operating_unit_id)] + rma.order.line.select rma.order.line - + From c2a31e556e64722e94f9d5154c321247e74b1503 Mon Sep 17 00:00:00 2001 From: aaron Date: Fri, 18 May 2018 13:02:21 +0200 Subject: [PATCH 07/13] [FIX]rma_operating_unit view --- rma_operating_unit/views/rma_order_line_view.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rma_operating_unit/views/rma_order_line_view.xml b/rma_operating_unit/views/rma_order_line_view.xml index 31655409..b29f94cd 100644 --- a/rma_operating_unit/views/rma_order_line_view.xml +++ b/rma_operating_unit/views/rma_order_line_view.xml @@ -39,7 +39,7 @@ rma.order.line - + @@ -53,7 +53,7 @@ rma.order.line - + From c680effc9fe0d87edf3fc3eadd1daaf1cbd7709a Mon Sep 17 00:00:00 2001 From: aheficent Date: Wed, 7 Nov 2018 16:41:09 +0100 Subject: [PATCH 08/13] [FIX]rma_operating_unit, wizard was not returning anything --- .../wizards/rma_add_stock_move.py | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 rma_operating_unit/wizards/rma_add_stock_move.py diff --git a/rma_operating_unit/wizards/rma_add_stock_move.py b/rma_operating_unit/wizards/rma_add_stock_move.py new file mode 100644 index 00000000..b3beff1f --- /dev/null +++ b/rma_operating_unit/wizards/rma_add_stock_move.py @@ -0,0 +1,38 @@ +# -*- 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 odoo import models, _ +from odoo.exceptions import ValidationError + + +class RmaAddStockMove(models.TransientModel): + _inherit = 'rma_add_stock_move' + _description = 'Wizard to add rma lines from pickings' + + def _prepare_rma_line_from_stock_move(self, sm, lot=False): + res = super(RmaAddStockMove, self)._prepare_rma_line_from_stock_move( + sm, lot) + if self.env.context.get('customer'): + operation = sm.product_id.rma_customer_operation_id or \ + sm.product_id.categ_id.rma_customer_operation_id + else: + operation = sm.product_id.rma_supplier_operation_id or \ + sm.product_id.categ_id.rma_supplier_operation_id + if not operation: + operation = self.env['rma.operation'].search( + [('type', '=', self.rma_id.type)], limit=1) + if not operation: + raise ValidationError(_("Please define an operation first")) + + if not operation.in_warehouse_id or not operation.out_warehouse_id: + warehouse = self.env['stock.warehouse'].search( + [('company_id', '=', self.rma_id.company_id.id), + ('lot_rma_id', '!=', False), + ('operating_unit_id', '=', self.line_id.operating_unit_id.id) + ], limit=1) + if not warehouse: + raise ValidationError(_( + "Please define a warehouse with a default RMA location")) + res.update(warehouse_id=warehouse.id) + return res From 18aa56b17e3c5616ad48ef4804e9bdc0babfdac1 Mon Sep 17 00:00:00 2001 From: Aaron Henriquez Date: Fri, 17 May 2019 18:01:44 +0200 Subject: [PATCH 09/13] [FIX]dependencies --- rma_operating_unit/__manifest__.py | 2 +- rma_operating_unit/wizards/rma_add_stock_move.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/rma_operating_unit/__manifest__.py b/rma_operating_unit/__manifest__.py index ec809583..ba5e9ce6 100644 --- a/rma_operating_unit/__manifest__.py +++ b/rma_operating_unit/__manifest__.py @@ -8,7 +8,7 @@ "license": "LGPL-3", "website": "https://www.eficent.com", "category": "Operating Units", - "depends": ["rma", "operating_unit"], + "depends": ["rma", "stock_operating_unit"], "data": [ "security/rma_security.xml", "views/rma_order_view.xml", diff --git a/rma_operating_unit/wizards/rma_add_stock_move.py b/rma_operating_unit/wizards/rma_add_stock_move.py index b3beff1f..a5c236c0 100644 --- a/rma_operating_unit/wizards/rma_add_stock_move.py +++ b/rma_operating_unit/wizards/rma_add_stock_move.py @@ -1,4 +1,3 @@ -# -*- 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 577dd0078d6b388b764629bd9978cf548529c5e0 Mon Sep 17 00:00:00 2001 From: Juany Davila Date: Mon, 20 Mar 2023 15:19:57 -0500 Subject: [PATCH 10/13] [IMP] rma_operating_unit: black, isort, prettier --- rma_operating_unit/__manifest__.py | 2 +- rma_operating_unit/models/rma_order.py | 18 ++- rma_operating_unit/models/rma_order_line.py | 4 +- rma_operating_unit/security/rma_security.xml | 21 +-- .../tests/test_rma_operating_unit.py | 140 ++++++++++-------- .../views/rma_order_line_view.xml | 52 +++++-- rma_operating_unit/views/rma_order_view.xml | 47 ++++-- .../wizards/rma_add_stock_move.py | 46 +++--- 8 files changed, 197 insertions(+), 133 deletions(-) diff --git a/rma_operating_unit/__manifest__.py b/rma_operating_unit/__manifest__.py index ba5e9ce6..bb87fad0 100644 --- a/rma_operating_unit/__manifest__.py +++ b/rma_operating_unit/__manifest__.py @@ -6,7 +6,7 @@ "version": "12.0.1.0.0", "author": "Eficent", "license": "LGPL-3", - "website": "https://www.eficent.com", + "website": "https://github.com/ForgeFlow/stock-rma", "category": "Operating Units", "depends": ["rma", "stock_operating_unit"], "data": [ diff --git a/rma_operating_unit/models/rma_order.py b/rma_operating_unit/models/rma_order.py index 072cef98..4d2dbb5b 100644 --- a/rma_operating_unit/models/rma_order.py +++ b/rma_operating_unit/models/rma_order.py @@ -1,7 +1,7 @@ # © 2017-19 Eficent Business and IT Consulting Services S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). -from odoo import api, fields, models, _ +from odoo import _, api, fields, models from odoo.exceptions import ValidationError @@ -10,15 +10,19 @@ class RmaOrder(models.Model): _inherit = "rma.order" @api.multi - @api.constrains('rma_line_ids', 'rma_line_ids.operating_unit_id') + @api.constrains("rma_line_ids", "rma_line_ids.operating_unit_id") def _check_operating_unit(self): for rma in self: bad_lines = rma.rma_line_ids.filtered( - lambda l: l.operating_unit_id != rma.operating_unit_id) + lambda l: l.operating_unit_id != rma.operating_unit_id + ) if bad_lines: raise ValidationError( - _('The operating unit of the rma lines have to match the' - ' one of the group')) + _( + "The operating unit of the rma lines have to match the" + " one of the group" + ) + ) return True @api.model @@ -26,7 +30,7 @@ class RmaOrder(models.Model): return self.env.user.default_operating_unit_id operating_unit_id = fields.Many2one( - comodel_name='operating.unit', - string='Operating Unit', + comodel_name="operating.unit", + string="Operating Unit", default=_default_operating_unit, ) diff --git a/rma_operating_unit/models/rma_order_line.py b/rma_operating_unit/models/rma_order_line.py index 799a1ff7..0059ccd6 100644 --- a/rma_operating_unit/models/rma_order_line.py +++ b/rma_operating_unit/models/rma_order_line.py @@ -15,7 +15,7 @@ class RmaOrderLine(models.Model): return self.env.user.default_operating_unit_id operating_unit_id = fields.Many2one( - comodel_name='operating.unit', - string='Operating Unit', + 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 index 5eb9a5bf..f0c15fd5 100644 --- a/rma_operating_unit/security/rma_security.xml +++ b/rma_operating_unit/security/rma_security.xml @@ -1,19 +1,20 @@ - + - - - ['|',('operating_unit_id','=',False),('operating_unit_id','in',[g.id for g in user.operating_unit_ids])] + + + ['|',('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/test_rma_operating_unit.py b/rma_operating_unit/tests/test_rma_operating_unit.py index 5dd028e5..50adb738 100644 --- a/rma_operating_unit/tests/test_rma_operating_unit.py +++ b/rma_operating_unit/tests/test_rma_operating_unit.py @@ -1,45 +1,47 @@ # © 2017-19 Eficent Business and IT Consulting Services S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). -from odoo.tests import common from odoo import exceptions +from odoo.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.rma_line_model = self.env['rma.order.line'] + self.res_users_model = self.env["res.users"] + self.rma_model = self.env["rma.order"] + self.rma_line_model = self.env["rma.order.line"] - 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') + 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") self.grp_ou = self.env.ref("operating_unit.group_multi_operating_unit") self.grp_stock = self.env.ref("stock.group_stock_manager") - self.product = self.env.ref('product.product_product_12') + self.product = self.env.ref("product.product_product_12") # Main Operating Unit - self.main_OU = self.env.ref('operating_unit.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') + self.b2c_OU = self.env.ref("operating_unit.b2c_operating_unit") # Users - self.user1 = self._create_user('user_1', - [self.grp_rma_manager, self.grp_ou, - self.grp_stock], - self.company, - [self.main_OU, self.b2c_OU]) - self.user2 = self._create_user('user_2', - [self.grp_rma_manager, self.grp_ou, - self.grp_stock], - self.company, - [self.b2c_OU]) - self.user3 = self._create_user('user_3', - [self.grp_rma_manager, self.grp_ou, - self.grp_stock], - self.company, - [self.main_OU, self.b2c_OU]) + self.user1 = self._create_user( + "user_1", + [self.grp_rma_manager, self.grp_ou, self.grp_stock], + self.company, + [self.main_OU, self.b2c_OU], + ) + self.user2 = self._create_user( + "user_2", + [self.grp_rma_manager, self.grp_ou, self.grp_stock], + self.company, + [self.b2c_OU], + ) + self.user3 = self._create_user( + "user_3", + [self.grp_rma_manager, self.grp_ou, self.grp_stock], + self.company, + [self.main_OU, self.b2c_OU], + ) # RMA Orders self.rma_order1 = self._create_rma(self.user1.id, self.main_OU) @@ -49,58 +51,68 @@ class TestRmaOperatingUnit(common.TransactionCase): 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)] - }) + 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, - }) + 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 _create_rma_line(self, rma, uid, operating_unit): """Creates an RMA""" - rma_order_line = self.rma_line_model.sudo(uid).create({ - 'operating_unit_id': operating_unit.id, - 'rma_id': rma.id, - 'partner_id': self.partner.id, - 'in_route_id': 1, - 'out_route_id': 1, - 'in_warehouse_id': 1, - 'out_warehouse_id': 1, - 'location_id': 1, - 'receipt_policy': 'ordered', - 'delivery_policy': 'ordered', - 'name': self.product.name, - 'product_id': self.product.id, - 'uom_id': self.product.uom_id.id - }) + rma_order_line = self.rma_line_model.sudo(uid).create( + { + "operating_unit_id": operating_unit.id, + "rma_id": rma.id, + "partner_id": self.partner.id, + "in_route_id": 1, + "out_route_id": 1, + "in_warehouse_id": 1, + "out_warehouse_id": 1, + "location_id": 1, + "receipt_policy": "ordered", + "delivery_policy": "ordered", + "name": self.product.name, + "product_id": self.product.id, + "uom_id": self.product.uom_id.id, + } + ) return rma_order_line 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) + 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, + ) def test_constraint(self): # RMA group should contain rma lines for the same OU diff --git a/rma_operating_unit/views/rma_order_line_view.xml b/rma_operating_unit/views/rma_order_line_view.xml index b29f94cd..a3d19f60 100644 --- a/rma_operating_unit/views/rma_order_line_view.xml +++ b/rma_operating_unit/views/rma_order_line_view.xml @@ -1,14 +1,17 @@ - + rma.order.line.tree rma.order.line - + - + @@ -16,10 +19,13 @@ rma.order.line.supplier.tree rma.order.line - + - + @@ -27,23 +33,31 @@ rma.order.supplier.tree rma.order - + - + rma.order.line.supplier.form rma.order.line - + - + - [('type','=','supplier'),('out_warehouse_id.operating_unit_id', '=', operating_unit_id)] + [('type','=','supplier'),('out_warehouse_id.operating_unit_id', '=', operating_unit_id)] @@ -51,13 +65,18 @@ rma.order.line.form rma.order.line - + - + - [('type','=','customer'),('in_warehouse_id.operating_unit_id', '=', operating_unit_id)] + [('type','=','customer'),('in_warehouse_id.operating_unit_id', '=', operating_unit_id)] @@ -65,10 +84,13 @@ rma.order.line.select rma.order.line - + - + diff --git a/rma_operating_unit/views/rma_order_view.xml b/rma_operating_unit/views/rma_order_view.xml index 87aedcfe..391c5e94 100644 --- a/rma_operating_unit/views/rma_order_view.xml +++ b/rma_operating_unit/views/rma_order_view.xml @@ -1,14 +1,17 @@ - + rma.order.tree rma.order - + - + @@ -16,10 +19,13 @@ rma.order.supplier.tree rma.order - + - + @@ -27,12 +33,16 @@ rma.order.supplier.form rma.order - + - - + + @@ -40,12 +50,16 @@ rma.order.form rma.order - + - - + + @@ -53,10 +67,13 @@ rma.order.select rma.order - + - + diff --git a/rma_operating_unit/wizards/rma_add_stock_move.py b/rma_operating_unit/wizards/rma_add_stock_move.py index a5c236c0..11062796 100644 --- a/rma_operating_unit/wizards/rma_add_stock_move.py +++ b/rma_operating_unit/wizards/rma_add_stock_move.py @@ -1,37 +1,45 @@ # © 2017 Eficent Business and IT Consulting Services S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) -from odoo import models, _ +from odoo import _, models from odoo.exceptions import ValidationError class RmaAddStockMove(models.TransientModel): - _inherit = 'rma_add_stock_move' - _description = 'Wizard to add rma lines from pickings' + _inherit = "rma_add_stock_move" + _description = "Wizard to add rma lines from pickings" def _prepare_rma_line_from_stock_move(self, sm, lot=False): - res = super(RmaAddStockMove, self)._prepare_rma_line_from_stock_move( - sm, lot) - if self.env.context.get('customer'): - operation = sm.product_id.rma_customer_operation_id or \ - sm.product_id.categ_id.rma_customer_operation_id + res = super(RmaAddStockMove, self)._prepare_rma_line_from_stock_move(sm, lot) + if self.env.context.get("customer"): + operation = ( + sm.product_id.rma_customer_operation_id + or sm.product_id.categ_id.rma_customer_operation_id + ) else: - operation = sm.product_id.rma_supplier_operation_id or \ - sm.product_id.categ_id.rma_supplier_operation_id + operation = ( + sm.product_id.rma_supplier_operation_id + or sm.product_id.categ_id.rma_supplier_operation_id + ) if not operation: - operation = self.env['rma.operation'].search( - [('type', '=', self.rma_id.type)], limit=1) + operation = self.env["rma.operation"].search( + [("type", "=", self.rma_id.type)], limit=1 + ) if not operation: raise ValidationError(_("Please define an operation first")) if not operation.in_warehouse_id or not operation.out_warehouse_id: - warehouse = self.env['stock.warehouse'].search( - [('company_id', '=', self.rma_id.company_id.id), - ('lot_rma_id', '!=', False), - ('operating_unit_id', '=', self.line_id.operating_unit_id.id) - ], limit=1) + warehouse = self.env["stock.warehouse"].search( + [ + ("company_id", "=", self.rma_id.company_id.id), + ("lot_rma_id", "!=", False), + ("operating_unit_id", "=", self.line_id.operating_unit_id.id), + ], + limit=1, + ) if not warehouse: - raise ValidationError(_( - "Please define a warehouse with a default RMA location")) + raise ValidationError( + _("Please define a warehouse with a default RMA location") + ) res.update(warehouse_id=warehouse.id) return res From d9e0367d985ed13103b4e98d8c78c7dc044a698f Mon Sep 17 00:00:00 2001 From: Juany Davila Date: Mon, 20 Mar 2023 15:31:53 -0500 Subject: [PATCH 11/13] [MIG] rma_operating_unit: migration to 14.0 --- rma_operating_unit/README.rst | 7 +- rma_operating_unit/__manifest__.py | 6 +- rma_operating_unit/models/rma_order.py | 3 +- rma_operating_unit/models/rma_order_line.py | 2 +- rma_operating_unit/security/rma_security.xml | 2 +- .../tests/test_rma_operating_unit.py | 74 +++++++++++-------- .../views/rma_order_line_view.xml | 15 +--- rma_operating_unit/views/rma_order_view.xml | 38 +++++----- .../wizards/rma_add_stock_move.py | 4 +- 9 files changed, 79 insertions(+), 72 deletions(-) diff --git a/rma_operating_unit/README.rst b/rma_operating_unit/README.rst index 1545840d..34879cd3 100644 --- a/rma_operating_unit/README.rst +++ b/rma_operating_unit/README.rst @@ -24,10 +24,11 @@ Usage Contributors ------------ -* Aaron Henriquez -* Beñat Jimenez +* Aaron Henriquez +* Beñat Jimenez +* Juany Davila Maintainer ---------- -This module is maintained by Eficent. \ No newline at end of file +This module is maintained by ForgeFlow. diff --git a/rma_operating_unit/__manifest__.py b/rma_operating_unit/__manifest__.py index bb87fad0..81a40343 100644 --- a/rma_operating_unit/__manifest__.py +++ b/rma_operating_unit/__manifest__.py @@ -1,10 +1,10 @@ -# © 2017-19 Eficent Business and IT Consulting Services S.L. +# Copyright 2017-19 ForgeFlow S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). { "name": "Operating Unit in RMA Groups", - "version": "12.0.1.0.0", - "author": "Eficent", + "version": "14.0.1.0.0", + "author": "ForgeFlow", "license": "LGPL-3", "website": "https://github.com/ForgeFlow/stock-rma", "category": "Operating Units", diff --git a/rma_operating_unit/models/rma_order.py b/rma_operating_unit/models/rma_order.py index 4d2dbb5b..2eb0889e 100644 --- a/rma_operating_unit/models/rma_order.py +++ b/rma_operating_unit/models/rma_order.py @@ -1,4 +1,4 @@ -# © 2017-19 Eficent Business and IT Consulting Services S.L. +# Copyright 2017-23 ForgeFlow S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from odoo import _, api, fields, models @@ -9,7 +9,6 @@ class RmaOrder(models.Model): _inherit = "rma.order" - @api.multi @api.constrains("rma_line_ids", "rma_line_ids.operating_unit_id") def _check_operating_unit(self): for rma in self: diff --git a/rma_operating_unit/models/rma_order_line.py b/rma_operating_unit/models/rma_order_line.py index 0059ccd6..b00806cd 100644 --- a/rma_operating_unit/models/rma_order_line.py +++ b/rma_operating_unit/models/rma_order_line.py @@ -1,4 +1,4 @@ -# © 2017-19 Eficent Business and IT Consulting Services S.L. +# Copyright 2017-19 ForgeFlow S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from odoo import api, fields, models diff --git a/rma_operating_unit/security/rma_security.xml b/rma_operating_unit/security/rma_security.xml index f0c15fd5..0384ead5 100644 --- a/rma_operating_unit/security/rma_security.xml +++ b/rma_operating_unit/security/rma_security.xml @@ -1,5 +1,5 @@ - diff --git a/rma_operating_unit/tests/test_rma_operating_unit.py b/rma_operating_unit/tests/test_rma_operating_unit.py index 50adb738..d1328496 100644 --- a/rma_operating_unit/tests/test_rma_operating_unit.py +++ b/rma_operating_unit/tests/test_rma_operating_unit.py @@ -1,4 +1,4 @@ -# © 2017-19 Eficent Business and IT Consulting Services S.L. +# Copyright 2017-19 ForgeFlow S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from odoo import exceptions from odoo.tests import common @@ -68,45 +68,61 @@ class TestRmaOperatingUnit(common.TransactionCase): 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, - } + operating_unit = ( + self.rma_model.sudo().with_user(uid)._default_operating_unit() + ) + rma_order = ( + self.rma_model.sudo() + .with_user(uid) + .create( + { + "operating_unit_id": operating_unit.id, + "partner_id": self.partner.id, + } + ) ) return rma_order def _create_rma_line(self, rma, uid, operating_unit): """Creates an RMA""" - rma_order_line = self.rma_line_model.sudo(uid).create( - { - "operating_unit_id": operating_unit.id, - "rma_id": rma.id, - "partner_id": self.partner.id, - "in_route_id": 1, - "out_route_id": 1, - "in_warehouse_id": 1, - "out_warehouse_id": 1, - "location_id": 1, - "receipt_policy": "ordered", - "delivery_policy": "ordered", - "name": self.product.name, - "product_id": self.product.id, - "uom_id": self.product.uom_id.id, - } + rma_order_line = ( + self.rma_line_model.sudo() + .with_user(uid) + .create( + { + "operating_unit_id": operating_unit.id, + "operation_id": self.env.ref( + "rma.rma_operation_supplier_replace" + ).id, + "rma_id": rma.id, + "partner_id": self.partner.id, + "in_route_id": 1, + "out_route_id": 1, + "in_warehouse_id": 1, + "out_warehouse_id": 1, + "location_id": 1, + "receipt_policy": "ordered", + "delivery_policy": "ordered", + "name": self.product.name, + "product_id": self.product.id, + "uom_id": self.product.uom_id.id, + } + ) ) return rma_order_line 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), - ] + record = ( + self.rma_model.sudo() + .with_user(self.user2.id) + .search( + [ + ("id", "=", self.rma_order1.id), + ("operating_unit_id", "=", self.main_OU.id), + ] + ) ) self.assertEqual( record.ids, diff --git a/rma_operating_unit/views/rma_order_line_view.xml b/rma_operating_unit/views/rma_order_line_view.xml index a3d19f60..e7bb3eb1 100644 --- a/rma_operating_unit/views/rma_order_line_view.xml +++ b/rma_operating_unit/views/rma_order_line_view.xml @@ -1,5 +1,5 @@ - @@ -30,19 +30,6 @@ - - rma.order.supplier.tree - rma.order - - - - - - - rma.order.line.supplier.form rma.order.line diff --git a/rma_operating_unit/views/rma_order_view.xml b/rma_operating_unit/views/rma_order_view.xml index 391c5e94..82b4310b 100644 --- a/rma_operating_unit/views/rma_order_view.xml +++ b/rma_operating_unit/views/rma_order_view.xml @@ -1,5 +1,5 @@ - @@ -35,14 +35,16 @@ rma.order - - - + + + + + @@ -52,14 +54,16 @@ rma.order - - - + + + + + diff --git a/rma_operating_unit/wizards/rma_add_stock_move.py b/rma_operating_unit/wizards/rma_add_stock_move.py index 11062796..7b35b7a7 100644 --- a/rma_operating_unit/wizards/rma_add_stock_move.py +++ b/rma_operating_unit/wizards/rma_add_stock_move.py @@ -1,4 +1,4 @@ -# © 2017 Eficent Business and IT Consulting Services S.L. +# Copyright 2017 ForgeFlow S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) from odoo import _, models @@ -33,7 +33,7 @@ class RmaAddStockMove(models.TransientModel): [ ("company_id", "=", self.rma_id.company_id.id), ("lot_rma_id", "!=", False), - ("operating_unit_id", "=", self.line_id.operating_unit_id.id), + ("operating_unit_id", "=", self.rma_id.operating_unit_id.id), ], limit=1, ) From 508c71b329c25ccc3b8f0980902e6321e1a8947f Mon Sep 17 00:00:00 2001 From: Juany Davila Date: Tue, 21 Mar 2023 17:03:34 -0500 Subject: [PATCH 12/13] [IMP] rma_operating_unit: black, isort, prettier --- setup/rma_operating_unit/odoo/addons/rma_operating_unit | 1 + setup/rma_operating_unit/setup.py | 6 ++++++ 2 files changed, 7 insertions(+) create mode 120000 setup/rma_operating_unit/odoo/addons/rma_operating_unit create mode 100644 setup/rma_operating_unit/setup.py diff --git a/setup/rma_operating_unit/odoo/addons/rma_operating_unit b/setup/rma_operating_unit/odoo/addons/rma_operating_unit new file mode 120000 index 00000000..dbb4c397 --- /dev/null +++ b/setup/rma_operating_unit/odoo/addons/rma_operating_unit @@ -0,0 +1 @@ +../../../../rma_operating_unit \ No newline at end of file diff --git a/setup/rma_operating_unit/setup.py b/setup/rma_operating_unit/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/rma_operating_unit/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) From 163b0984da05571064356995e345d6be42f661a4 Mon Sep 17 00:00:00 2001 From: Juany Davila Date: Tue, 21 Mar 2023 17:05:39 -0500 Subject: [PATCH 13/13] [MIG] rma_operating_unit: migration to 15.0 --- rma_operating_unit/README.rst | 4 +-- rma_operating_unit/__init__.py | 3 -- rma_operating_unit/__manifest__.py | 4 +-- rma_operating_unit/models/__init__.py | 2 -- rma_operating_unit/models/rma_order_line.py | 2 +- rma_operating_unit/security/rma_security.xml | 29 ++++++++----------- rma_operating_unit/tests/__init__.py | 1 - .../tests/test_rma_operating_unit.py | 2 +- .../views/rma_order_line_view.xml | 2 +- rma_operating_unit/views/rma_order_view.xml | 2 +- .../wizards/rma_add_stock_move.py | 4 +-- 11 files changed, 22 insertions(+), 33 deletions(-) diff --git a/rma_operating_unit/README.rst b/rma_operating_unit/README.rst index 34879cd3..700136ef 100644 --- a/rma_operating_unit/README.rst +++ b/rma_operating_unit/README.rst @@ -2,9 +2,9 @@ :target: https://www.gnu.org/licenses/lgpl.html :alt: License: LGPL-3 -============================== +======================== RMA with Operating Units -============================== +======================== This module introduces the following features: diff --git a/rma_operating_unit/__init__.py b/rma_operating_unit/__init__.py index 8ef85858..0650744f 100644 --- a/rma_operating_unit/__init__.py +++ b/rma_operating_unit/__init__.py @@ -1,4 +1 @@ -# 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/__manifest__.py b/rma_operating_unit/__manifest__.py index 81a40343..c89cc576 100644 --- a/rma_operating_unit/__manifest__.py +++ b/rma_operating_unit/__manifest__.py @@ -1,9 +1,9 @@ -# Copyright 2017-19 ForgeFlow S.L. +# Copyright 2017-23 ForgeFlow S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). { "name": "Operating Unit in RMA Groups", - "version": "14.0.1.0.0", + "version": "15.0.1.0.0", "author": "ForgeFlow", "license": "LGPL-3", "website": "https://github.com/ForgeFlow/stock-rma", diff --git a/rma_operating_unit/models/__init__.py b/rma_operating_unit/models/__init__.py index 5141b758..1bbd239d 100644 --- a/rma_operating_unit/models/__init__.py +++ b/rma_operating_unit/models/__init__.py @@ -1,4 +1,2 @@ -# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). - from . import rma_order from . import rma_order_line diff --git a/rma_operating_unit/models/rma_order_line.py b/rma_operating_unit/models/rma_order_line.py index b00806cd..f7cf802c 100644 --- a/rma_operating_unit/models/rma_order_line.py +++ b/rma_operating_unit/models/rma_order_line.py @@ -1,4 +1,4 @@ -# Copyright 2017-19 ForgeFlow S.L. +# Copyright 2017-23 ForgeFlow S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from odoo import api, fields, models diff --git a/rma_operating_unit/security/rma_security.xml b/rma_operating_unit/security/rma_security.xml index 0384ead5..f6553097 100644 --- a/rma_operating_unit/security/rma_security.xml +++ b/rma_operating_unit/security/rma_security.xml @@ -1,21 +1,16 @@ - - - - - - ['|',('operating_unit_id','=',False),('operating_unit_id','in',[g.id for g in user.operating_unit_ids])] - RMA from allowed operating units - - - - - - - - + + + + ['|', ('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 index 85351693..d588b49b 100644 --- a/rma_operating_unit/tests/__init__.py +++ b/rma_operating_unit/tests/__init__.py @@ -1,2 +1 @@ -# 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 index d1328496..fbcabc28 100644 --- a/rma_operating_unit/tests/test_rma_operating_unit.py +++ b/rma_operating_unit/tests/test_rma_operating_unit.py @@ -1,4 +1,4 @@ -# Copyright 2017-19 ForgeFlow S.L. +# Copyright 2017-23 ForgeFlow S.L. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from odoo import exceptions from odoo.tests import common diff --git a/rma_operating_unit/views/rma_order_line_view.xml b/rma_operating_unit/views/rma_order_line_view.xml index e7bb3eb1..114be881 100644 --- a/rma_operating_unit/views/rma_order_line_view.xml +++ b/rma_operating_unit/views/rma_order_line_view.xml @@ -1,5 +1,5 @@ - diff --git a/rma_operating_unit/views/rma_order_view.xml b/rma_operating_unit/views/rma_order_view.xml index 82b4310b..0506fe96 100644 --- a/rma_operating_unit/views/rma_order_view.xml +++ b/rma_operating_unit/views/rma_order_view.xml @@ -1,5 +1,5 @@ - diff --git a/rma_operating_unit/wizards/rma_add_stock_move.py b/rma_operating_unit/wizards/rma_add_stock_move.py index 7b35b7a7..98fe8656 100644 --- a/rma_operating_unit/wizards/rma_add_stock_move.py +++ b/rma_operating_unit/wizards/rma_add_stock_move.py @@ -1,5 +1,5 @@ -# Copyright 2017 ForgeFlow S.L. -# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html) +# Copyright 2017-23 ForgeFlow S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). from odoo import _, models from odoo.exceptions import ValidationError