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 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, +)