[FIX] rma_sale: Allow to request a rma from portal order page only with portal user permission

This commit is contained in:
Víctor Martínez
2022-09-22 09:08:27 +02:00
parent abc1c8a86c
commit 5cf6f91ed2
5 changed files with 52 additions and 4 deletions

View File

@@ -99,6 +99,7 @@ Contributors
* Ernesto Tejeda
* Pedro M. Baeza
* David Vidal
* Víctor Martínez
* Chafique Delli <chafique.delli@akretion.com>
* Giovanni Serra - Ooops <giovanni@ooops404.com>

View File

@@ -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()
}

View File

@@ -3,6 +3,7 @@
* Ernesto Tejeda
* Pedro M. Baeza
* David Vidal
* Víctor Martínez
* Chafique Delli <chafique.delli@akretion.com>
* Giovanni Serra - Ooops <giovanni@ooops404.com>

View File

@@ -3,7 +3,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" />
<meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
<title>Return Merchandise Authorization Management - Link with Sales</title>
<style type="text/css">
@@ -448,6 +448,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
<li>Ernesto Tejeda</li>
<li>Pedro M. Baeza</li>
<li>David Vidal</li>
<li>Víctor Martínez</li>
</ul>
</li>
<li>Chafique Delli &lt;<a class="reference external" href="mailto:chafique.delli&#64;akretion.com">chafique.delli&#64;akretion.com</a>&gt;</li>

View File

@@ -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, SavepointCase
from odoo.tests.common import users
class TestRmaSale(SavepointCase):
@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(SavepointCase):
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,15 @@ class TestRmaSale(SavepointCase):
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.in_portal = True
wizard_all.action_apply()
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 +97,37 @@ class TestRmaSale(SavepointCase):
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)