Skip to content

Commit

Permalink
[MIG] rma_sale: sale portal
Browse files Browse the repository at this point in the history
- Migrate bs4 to bs5
- Fix shipping address choice functionality
- Add tour for the user portal workflow
  • Loading branch information
chienandalu authored and pedrobaeza committed Sep 2, 2023
1 parent 54e08e8 commit 4c6dbd2
Show file tree
Hide file tree
Showing 7 changed files with 189 additions and 33 deletions.
3 changes: 3 additions & 0 deletions rma_sale/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
},
}
5 changes: 5 additions & 0 deletions rma_sale/controllers/sale_portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check warning on line 40 in rma_sale/controllers/sale_portal.py

View check run for this annotation

Codecov / codecov/patch

rma_sale/controllers/sale_portal.py#L39-L40

Added lines #L39 - L40 were not covered by tests
for name, value in post.items():
try:
row, field_name = name.split("-", 1)
Expand Down
11 changes: 11 additions & 0 deletions rma_sale/static/src/js/rma_portal_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},

/**
Expand Down Expand Up @@ -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");
},
});
});
64 changes: 64 additions & 0 deletions rma_sale/static/src/tests/test_rma_sale_portal_tour.esm.js
Original file line number Diff line number Diff line change
@@ -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')",
},
]
);
1 change: 1 addition & 0 deletions rma_sale/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -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
64 changes: 64 additions & 0 deletions rma_sale/tests/test_rma_sale_portal.py
Original file line number Diff line number Diff line change
@@ -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": "[email protected]"}
)
cls.another_partner = cls.res_partner.create(
{
"name": "Another address",
"email": "[email protected]",
"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("<p>I'd like to change this product</p>")
)
74 changes: 41 additions & 33 deletions rma_sale/views/sale_portal_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
<h4 class="modal-title">Request RMAs</h4>
<button
type="button"
class="close"
data-dismiss="modal"
class="btn-close"
aria-label="Close"
data-bs-dismiss="modal"
>&amp;times;</button>
</header>
<main
Expand Down Expand Up @@ -45,32 +45,40 @@
<button
class="btn btn-primary btn-block mb8"
type="button"
data-toggle="collapse"
data-target="#delivery_address_picker"
aria-expanded="false"
data-bs-toggle="collapse"
data-bs-target="#delivery_address_picker"
><i class="fa fa-truck" /> Choose a delivery address</button>
<div class="col-lg-12 collapse mt8" id="delivery_address_picker">
<div data-toggle="buttons" class="row">
<label
t-attf-class="card mr4 btn btn-light #{address == sale_order.partner_shipping_id and 'active' or ''}"
<div
class="collapse mt8 p16"
id="delivery_address_picker"
data-bs-toggle="buttons"
>
<div
class="d-flex flex-wrap justify-content-evenly col-lg-12 form-check"
>

<div
t-attf-class="col-lg-5 o_rma_portal_shipping_card card mb4 #{address == sale_order.partner_shipping_id and 'bg-primary text-primary' or ''}"
t-foreach="delivery_addresses"
t-as="address"
>
<div class="card-body">
<input
class="d-none"
type="radio"
name="partner_shipping_id"
t-att-value="address.id"
>
<strong>
class="d-none form-check-input"
type="radio"
name="partner_shipping_id"
t-att-value="address.id"
/>
<strong>
<i
t-attf-class="text-secondary fa #{address.type == 'delivery' and 'fa-truck' or 'fa-user'}"
/>
<t t-out="address.name" />
</strong>
<pre><h6 t-out="address.contact_address" /></pre>
</input>
</label>
</strong>
<pre><h6 t-out="address.contact_address" /></pre>
</div>
</div>
</div>
</div>
<t t-set="data_list" t-value="sale_order.get_delivery_rma_data()" />
Expand All @@ -81,18 +89,18 @@
<table class="table table-sm" id="request-rma-table">
<thead class="bg-100">
<tr>
<th class="text-left">Product</th>
<th class="text-right">Quantity</th>
<th class="text-left">Delivery</th>
<th class="text-left">Requested operation</th>
<th class="text-start">Product</th>
<th class="text-end">Quantity</th>
<th class="text-start">Delivery</th>
<th class="text-start">Requested operation</th>
<th name="portal_rma_button_desc" />
</tr>
</thead>
<tbody class="request-rma-tbody">
<t t-foreach="data_list" t-as="data">
<t t-if="data['quantity'] > 0 and data['picking']">
<t t-if="data['quantity'] &gt; 0 and data['picking']">
<tr>
<td class="text-left">
<td class="text-start">
<span t-out="data['product'].display_name" />
<input
type="hidden"
Expand All @@ -106,12 +114,12 @@
t-att-value="data['sale_line_id'].id"
/>
</td>
<td class="text-right">
<td class="text-end">
<div id="delivery-rma-qty">
<input
type="number"
t-attf-name="#{data_index}-quantity"
class="o_input text-right"
class="o_input text-end"
placeholder="0"
min="0"
t-att-max="data['quantity']"
Expand All @@ -129,7 +137,7 @@
/>
</div>
</td>
<td class="text-left">
<td class="text-start">
<span
t-out="data['picking'] and data['picking'].name"
/>
Expand All @@ -139,7 +147,7 @@
t-att-value="data['picking'] and data['picking'].id"
/>
</td>
<td class="text-left">
<td class="text-start">
<select
t-attf-name="#{data_index}-operation_id"
class="form-control rma-operation"
Expand All @@ -156,10 +164,10 @@
<button
class="btn btn-primary fa fa-comments"
type="button"
data-toggle="collapse"
t-attf-data-target="#comment-#{data_index}"
aria-expanded="false"
t-attf-aria-controls="comment-#{data_index}"
data-bs-toggle="collapse"
/>
</td>
</tr>
Expand All @@ -183,7 +191,7 @@
t-att-id="sale_order.id"
class="btn btn-primary"
><i class="fa fa-check" /> Request RMAs</button>
<button type="button" class="btn btn-danger" data-dismiss="modal"><i
<button type="button" class="btn btn-danger" data-bs-dismiss="modal"><i
class="fa fa-times"
/> Cancel</button>
</footer>
Expand Down Expand Up @@ -216,9 +224,9 @@
<a
role="button"
class="btn btn-secondary btn-block mb8"
data-toggle="modal"
data-target="#modal-request-rma"
href="#"
data-bs-toggle="modal"
data-bs-target="#modal-request-rma"
>
<i class="fa fa-reply" /> Request RMAs
</a>
Expand All @@ -244,7 +252,7 @@
inherit_id="sale.sale_order_portal_content"
>
<xpath expr="//div[@id='introduction']/h2[hasclass('my-0')]" position="inside">
<span t-if="sale_order.rma_count" class="float-right">
<span t-if="sale_order.rma_count" class="float-end">
<a
role="button"
t-attf-href="/my/rmas?sale_id=#{sale_order.id}"
Expand Down

0 comments on commit 4c6dbd2

Please sign in to comment.