From 4dce7e6b53cd9403def7e81106f1ae24632f2329 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Mart=C3=ADnez?= Date: Thu, 22 Sep 2022 09:08:27 +0200 Subject: [PATCH] [FIX] rma_sale: Allow to request a rma from portal order page only with portal user permission --- rma_sale/README.rst | 1 + rma_sale/__manifest__.py | 2 +- rma_sale/controllers/sale_portal.py | 2 +- rma_sale/readme/CONTRIBUTORS.rst | 1 + rma_sale/static/description/index.html | 1 + rma_sale/tests/test_rma_sale.py | 48 ++++++++++++++++++++++++-- 6 files changed, 51 insertions(+), 4 deletions(-) diff --git a/rma_sale/README.rst b/rma_sale/README.rst index 1f3b8076..a867b0a7 100644 --- a/rma_sale/README.rst +++ b/rma_sale/README.rst @@ -99,6 +99,7 @@ Contributors * Ernesto Tejeda * Pedro M. Baeza * David Vidal + * Víctor Martínez * Chafique Delli * Giovanni Serra - Ooops diff --git a/rma_sale/__manifest__.py b/rma_sale/__manifest__.py index ab99826d..ec37b648 100644 --- a/rma_sale/__manifest__.py +++ b/rma_sale/__manifest__.py @@ -3,7 +3,7 @@ { "name": "Return Merchandise Authorization Management - Link with Sales", "summary": "Sale Order - Return Merchandise Authorization (RMA)", - "version": "15.0.1.0.0", + "version": "15.0.1.0.1", "development_status": "Production/Stable", "category": "RMA", "website": "https://github.com/OCA/rma", diff --git a/rma_sale/controllers/sale_portal.py b/rma_sale/controllers/sale_portal.py index 50a7d51d..05c07dcb 100644 --- a/rma_sale/controllers/sale_portal.py +++ b/rma_sale/controllers/sale_portal.py @@ -25,7 +25,7 @@ class CustomerPortal(CustomerPortal): except (AccessError, MissingError): return request.redirect("/my") order_obj = request.env["sale.order"] - wizard_obj = request.env["sale.order.rma.wizard"] + wizard_obj = request.env["sale.order.rma.wizard"].sudo() wizard_line_field_types = { f: d["type"] for f, d in wizard_obj.line_ids.fields_get().items() } diff --git a/rma_sale/readme/CONTRIBUTORS.rst b/rma_sale/readme/CONTRIBUTORS.rst index c93f1606..75646b6d 100644 --- a/rma_sale/readme/CONTRIBUTORS.rst +++ b/rma_sale/readme/CONTRIBUTORS.rst @@ -3,6 +3,7 @@ * Ernesto Tejeda * Pedro M. Baeza * David Vidal + * Víctor Martínez * Chafique Delli * Giovanni Serra - Ooops diff --git a/rma_sale/static/description/index.html b/rma_sale/static/description/index.html index 43411b5a..74d1706f 100644 --- a/rma_sale/static/description/index.html +++ b/rma_sale/static/description/index.html @@ -448,6 +448,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
  • Ernesto Tejeda
  • Pedro M. Baeza
  • David Vidal
  • +
  • Víctor Martínez
  • Chafique Delli <chafique.delli@akretion.com>
  • diff --git a/rma_sale/tests/test_rma_sale.py b/rma_sale/tests/test_rma_sale.py index 54d4a456..78e867b5 100644 --- a/rma_sale/tests/test_rma_sale.py +++ b/rma_sale/tests/test_rma_sale.py @@ -1,13 +1,15 @@ # Copyright 2020 Tecnativa - Ernesto Tejeda +# Copyright 2022 Tecnativa - Víctor Martínez # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). from odoo.tests import Form, TransactionCase +from odoo.tests.common import users class TestRmaSale(TransactionCase): @classmethod def setUpClass(cls): - super(TestRmaSale, cls).setUpClass() + super().setUpClass() cls.res_partner = cls.env["res.partner"] cls.product_product = cls.env["product.product"] cls.sale_order = cls.env["sale.order"] @@ -18,7 +20,10 @@ class TestRmaSale(TransactionCase): cls.product_2 = cls.product_product.create( {"name": "Product test 2", "type": "product"} ) - cls.partner = cls.res_partner.create({"name": "Partner test"}) + cls.partner = cls.res_partner.create( + {"name": "Partner test", "email": "partner@rma"} + ) + cls._partner_portal_wizard(cls, cls.partner) order_form = Form(cls.sale_order) order_form.partner_id = cls.partner with order_form.order_line.new() as line_form: @@ -35,6 +40,14 @@ class TestRmaSale(TransactionCase): cls.order_out_picking.move_lines.quantity_done = 5 cls.order_out_picking.button_validate() + def _partner_portal_wizard(self, partner): + wizard_all = ( + self.env["portal.wizard"] + .with_context(**{"active_ids": [partner.id]}) + .create({}) + ) + wizard_all.user_ids.action_grant_access() + def _rma_sale_wizard(self, order): wizard_id = order.action_create_rma()["res_id"] return self.env["sale.order.rma.wizard"].browse(wizard_id) @@ -83,6 +96,37 @@ class TestRmaSale(TransactionCase): rma.action_refund() self.assertEqual(rma.refund_id.user_id, user) + @users("partner@rma") + def test_create_rma_from_so_portal_user(self): + order = self.sale_order + wizard_obj = ( + self.env["sale.order.rma.wizard"].sudo().with_context(active_id=order) + ) + operation = self.env["rma.operation"].sudo().search([], limit=1) + line_vals = [ + ( + 0, + 0, + { + "product_id": order.order_line.product_id.id, + "sale_line_id": order.order_line.id, + "quantity": order.order_line.product_uom_qty, + "uom_id": order.order_line.product_uom.id, + "picking_id": order.picking_ids[0].id, + "operation_id": operation.id, + }, + ) + ] + wizard = wizard_obj.create( + { + "line_ids": line_vals, + "location_id": order.warehouse_id.rma_loc_id.id, + } + ) + rma = wizard.sudo().create_rma(from_portal=True) + self.assertEqual(rma.order_id, order) + self.assertIn(order.partner_id, rma.message_partner_ids) + def test_create_recurrent_rma(self): """An RMA of a product that had an RMA in the past should be possible""" wizard = self._rma_sale_wizard(self.sale_order)