diff --git a/rma_sale/__manifest__.py b/rma_sale/__manifest__.py
index 3642eed0..fd6996ed 100644
--- a/rma_sale/__manifest__.py
+++ b/rma_sale/__manifest__.py
@@ -29,5 +29,8 @@
"/rma_sale/static/src/js/rma_portal_form.js",
"/rma_sale/static/src/scss/rma_sale.scss",
],
+ "web.assets_tests": [
+ "/rma_sale/static/src/tests/*.js",
+ ],
},
}
diff --git a/rma_sale/controllers/sale_portal.py b/rma_sale/controllers/sale_portal.py
index 05c07dcb..64e24811 100644
--- a/rma_sale/controllers/sale_portal.py
+++ b/rma_sale/controllers/sale_portal.py
@@ -33,6 +33,11 @@ class CustomerPortal(CustomerPortal):
mapped_vals = {}
custom_vals = {}
partner_shipping_id = post.pop("partner_shipping_id", False)
+ if partner_shipping_id:
+ try:
+ partner_shipping_id = int(partner_shipping_id)
+ except ValueError:
+ partner_shipping_id = False
for name, value in post.items():
try:
row, field_name = name.split("-", 1)
diff --git a/rma_sale/static/src/js/rma_portal_form.js b/rma_sale/static/src/js/rma_portal_form.js
index 1bda0788..89e3d310 100644
--- a/rma_sale/static/src/js/rma_portal_form.js
+++ b/rma_sale/static/src/js/rma_portal_form.js
@@ -18,6 +18,7 @@ odoo.define("rma_sale.animation", function (require) {
events: {
"change .rma-operation": "_onChangeOperationId",
"change #delivery-rma-qty input": "_onChangeQty",
+ "click .o_rma_portal_shipping_card": "_onChangeShippingAddress",
},
/**
@@ -120,5 +121,15 @@ odoo.define("rma_sale.animation", function (require) {
_onChangeQty: function () {
this._checkCanSubmit();
},
+ _onChangeShippingAddress: function (ev) {
+ const $address_container = $(ev.currentTarget.parentElement);
+ $address_container.find("input").removeAttr("checked");
+ $address_container
+ .find(".o_rma_portal_shipping_card")
+ .removeClass("bg-primary")
+ .removeClass("text-primary");
+ $(ev.currentTarget).find("input").attr("checked", "checked");
+ $(ev.currentTarget).addClass("bg-primary").addClass("text-primary");
+ },
});
});
diff --git a/rma_sale/static/src/tests/test_rma_sale_portal_tour.esm.js b/rma_sale/static/src/tests/test_rma_sale_portal_tour.esm.js
new file mode 100644
index 00000000..7e2288e2
--- /dev/null
+++ b/rma_sale/static/src/tests/test_rma_sale_portal_tour.esm.js
@@ -0,0 +1,64 @@
+/** @odoo-module */
+/* Copyright 2021 Tecnativa - David Vidal
+ License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). */
+
+import tour from "web_tour.tour";
+
+tour.register(
+ "rma_sale_portal",
+ {
+ test: true,
+ url: "/my/orders",
+ },
+ [
+ {
+ content: "Open the test sale order",
+ trigger: 'a:containsExact("Test Sale RMA SO")',
+ },
+ {
+ content: "Open the RMA request pop-up",
+ trigger: 'a:contains("Request RMAs")',
+ },
+ {
+ content:
+ "Submit button is disabled until we set quanity and requested operation",
+ trigger: "button[type='submit'][disabled]",
+ },
+ {
+ content: "Return 1 unit for the first row",
+ trigger: "input[name='0-quantity']",
+ run: "text 1",
+ },
+ {
+ content: "Select the operation",
+ trigger: "select[name='0-operation_id']",
+ run: "text Replace",
+ },
+ {
+ content: "Write some comments",
+ trigger: "textarea[name='0-description']",
+ run: "text I'd like to change this product",
+ },
+ {
+ content: "Unfold the Delivery Address picker",
+ trigger: "button:contains('Choose a delivery address')",
+ },
+ {
+ content: "Choose another address",
+ trigger: ".o_rma_portal_shipping_card:contains('Another address')",
+ run: "click",
+ },
+ {
+ content: "Submit the RMA",
+ trigger: "button[type='submit']",
+ },
+ {
+ content: "We're redirected to the new draft RMA",
+ trigger: "h5:contains('RMA Order')",
+ },
+ {
+ content: "We're redirected to the new draft RMA",
+ trigger: "h5:contains('RMA Order')",
+ },
+ ]
+);
diff --git a/rma_sale/tests/__init__.py b/rma_sale/tests/__init__.py
index 89e73462..5318a705 100644
--- a/rma_sale/tests/__init__.py
+++ b/rma_sale/tests/__init__.py
@@ -1,3 +1,4 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from . import test_rma_sale
+from . import test_rma_sale_portal
diff --git a/rma_sale/tests/test_rma_sale_portal.py b/rma_sale/tests/test_rma_sale_portal.py
new file mode 100644
index 00000000..2378ef2b
--- /dev/null
+++ b/rma_sale/tests/test_rma_sale_portal.py
@@ -0,0 +1,64 @@
+# Copyright 2023 Tecnativa - David Vidal
+# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
+from markupsafe import Markup
+
+from odoo import Command
+from odoo.tests import HttpCase, tagged
+
+from .test_rma_sale import TestRmaSaleBase
+
+
+@tagged("-at-install", "post-install")
+class TestRmaSalePortal(TestRmaSaleBase, HttpCase):
+ @classmethod
+ def setUpClass(cls):
+ super().setUpClass()
+ cls.sale_order = cls._create_sale_order(cls, [[cls.product_1, 5]])
+ # So we can click it in the tour
+ cls.sale_order.name = "Test Sale RMA SO"
+ cls.sale_order.action_confirm()
+ # Maybe other modules create additional lines in the create
+ # method in sale.order model, so let's find the correct line.
+ cls.order_line = cls.sale_order.order_line.filtered(
+ lambda r: r.product_id == cls.product_1
+ )
+ cls.order_out_picking = cls.sale_order.picking_ids
+ cls.order_out_picking.move_ids.quantity_done = 5
+ cls.order_out_picking.button_validate()
+ # Let's create some companion contacts
+ cls.partner_company = cls.res_partner.create(
+ {"name": "Partner test Co", "email": "partner_co@test.com"}
+ )
+ cls.another_partner = cls.res_partner.create(
+ {
+ "name": "Another address",
+ "email": "another_partner@test.com",
+ "parent_id": cls.partner_company.id,
+ }
+ )
+ cls.partner.parent_id = cls.partner_company
+ # Create our portal user
+ cls.user_portal = (
+ cls.env["res.users"]
+ .with_context(no_reset_password=True)
+ .create(
+ {
+ "login": "rma_portal",
+ "password": "rma_portal",
+ "partner_id": cls.partner.id,
+ "groups_id": [Command.set([cls.env.ref("base.group_portal").id])],
+ }
+ )
+ )
+
+ def test_rma_sale_portal(self):
+ self.start_tour("/", "rma_sale_portal", login="rma_portal")
+ rma = self.sale_order.rma_ids
+ # Check that the portal values are properly transmited
+ self.assertEqual(rma.state, "draft")
+ self.assertEqual(rma.partner_id, self.partner)
+ self.assertEqual(rma.partner_shipping_id, self.another_partner)
+ self.assertEqual(rma.product_uom_qty, 1)
+ self.assertEqual(
+ rma.description, Markup("
I'd like to change this product
")
+ )
diff --git a/rma_sale/views/sale_portal_template.xml b/rma_sale/views/sale_portal_template.xml
index ff2739e5..d9196057 100644
--- a/rma_sale/views/sale_portal_template.xml
+++ b/rma_sale/views/sale_portal_template.xml
@@ -12,9 +12,9 @@
Request RMAs
Choose a delivery address
-
-
-
@@ -81,18 +89,18 @@