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
  • Loading branch information
chienandalu committed Aug 31, 2023
1 parent 34efadf commit 802a191
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 33 deletions.
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)

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

View check run for this annotation

Codecov / codecov/patch

rma_sale/controllers/sale_portal.py#L33-L35

Added lines #L33 - L35 were not covered by tests
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#L37-L40

Added lines #L37 - L40 were not covered by tests
for name, value in post.items():
try:
row, field_name = name.split("-", 1)

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

View check run for this annotation

Codecov / codecov/patch

rma_sale/controllers/sale_portal.py#L42-L43

Added lines #L42 - L43 were not covered by tests
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");
},
});
});
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 802a191

Please sign in to comment.