Skip to content

Commit

Permalink
[IMP] website_sale_order_to_cart: Add cancel sale.order button
Browse files Browse the repository at this point in the history
  • Loading branch information
unaiberis authored and anajuaristi committed Oct 17, 2024
1 parent 2685c45 commit 3f73a40
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
13 changes: 13 additions & 0 deletions website_sale_order_to_cart/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,16 @@ def sale_order_to_cart(self, **kwargs):
return request.redirect("/shop/cart")

return request.redirect("/shop")

@http.route("/cancel_sale_order", type="http", auth="user", website=True)
def cancel_sale_order(self, **kwargs):
order_id = kwargs.get("order_id")
if order_id:
sale_order = request.env["sale.order"].sudo().browse(int(order_id))
# Only cancel the order if the partner_id of the order is the user
# if sale_order.partner_id == request.env.user.partner_id: --> ...
# ... Doesn't work as expected
if sale_order and sale_order.state not in ["sale"]:
sale_order.action_cancel()

return request.redirect("/shop")
14 changes: 10 additions & 4 deletions website_sale_order_to_cart/views/website_templates.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
>
<t t-if="website_sale_order.id">
<div>
<a
<a
class="btn btn-primary mb32"
role="button"
t-att-href="'/action_quotation_mark_send?order_id=' + str(website_sale_order.id)"
Expand All @@ -24,16 +24,23 @@
inherit_id="sale.sale_order_portal_template"
>
<xpath expr="//a[@id='o_sale_portal_paynow']" position="after">
<t t-if="sale_order.id">
<t t-if="sale_order.id and sale_order.state not in ['sale']">
<div class="d-flex justify-content-center">
<div>
<a
<a
class="btn btn-primary mb32"
role="button"
t-att-href="'/sale_order_to_cart?order_id=' + str(sale_order.id)"
>
<span>Change Order</span>
</a>
<a
class="btn btn-danger mb32"
role="button"
t-att-href="'/cancel_sale_order?order_id=' + str(sale_order.id)"
>
<span>Cancel Order</span>
</a>
</div>
</div>
</t>
Expand All @@ -49,6 +56,5 @@
>
<attribute name="t-if">False</attribute>
</xpath>

</template>
</odoo>

0 comments on commit 3f73a40

Please sign in to comment.