From c077aac50c90be1880098b88248e59b185717e76 Mon Sep 17 00:00:00 2001 From: David Date: Wed, 30 Aug 2023 16:02:50 +0200 Subject: [PATCH] [MIG] rma_sale: sale portal - Migrate bs4 to bs5 - Fix shipping address choice functionality - Add tour for the user portal workflow --- rma_sale/__manifest__.py | 3 + rma_sale/controllers/sale_portal.py | 5 ++ rma_sale/static/src/js/rma_portal_form.js | 11 +++ .../tests/test_rma_sale_portal_tour.esm.js | 64 ++++++++++++++++ rma_sale/tests/__init__.py | 1 + rma_sale/tests/test_rma_sale_portal.py | 63 ++++++++++++++++ rma_sale/views/sale_portal_template.xml | 74 ++++++++++--------- 7 files changed, 188 insertions(+), 33 deletions(-) create mode 100644 rma_sale/static/src/tests/test_rma_sale_portal_tour.esm.js create mode 100644 rma_sale/tests/test_rma_sale_portal.py diff --git a/rma_sale/__manifest__.py b/rma_sale/__manifest__.py index 3642eed0e..fd6996ed8 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 05c07dcb2..64e248113 100644 --- a/rma_sale/controllers/sale_portal.py +++ b/rma_sale/controllers/sale_portal.py @@ -33,6 +33,11 @@ def request_rma(self, order_id, access_token=None, **post): 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 1bda0788c..89e3d3103 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 000000000..7e2288e2f --- /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 89e734624..5318a7053 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 000000000..1b548240f --- /dev/null +++ b/rma_sale/tests/test_rma_sale_portal.py @@ -0,0 +1,63 @@ +# 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 + +from .test_rma_sale import TestRmaSaleBase + + +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 ff2739e5e..d9196057f 100644 --- a/rma_sale/views/sale_portal_template.xml +++ b/rma_sale/views/sale_portal_template.xml @@ -12,9 +12,9 @@
Choose a delivery address -
-
-
@@ -81,18 +89,18 @@ - - - - + + + + - + - - - - @@ -183,7 +191,7 @@ t-att-id="sale_order.id" class="btn btn-primary" > Request RMAs - @@ -216,9 +224,9 @@ Request RMAs @@ -244,7 +252,7 @@ inherit_id="sale.sale_order_portal_content" > - +
ProductQuantityDeliveryRequested operationProductQuantityDeliveryRequested operation
+ +
+ @@ -139,7 +147,7 @@ t-att-value="data['picking'] and data['picking'].id" /> +