Skip to Content
Menu
This question has been flagged

I am trying to display all the user wise sale order of the current logged in user, but I have no idea how/what to enter in the search. You can refer my code below-

controllers.py code:

class saleOrder(http.Controller):
  @http.route('/sale-order', type='http',auth='public',website=True)
def render_sale_order(self):
  saleorders = http.request.env['sale.order'].sudo().search([])
return http.request.render('sale_portal.sale_order', {'saleorders': saleorders})


templates.xml code:

<template id="sale_order"name="Sale Order">
<t t-call="website.layout">
<div class="oe_structure">
<div class="container">
<center><h3>Your Sale Orders</h3></center>
<t t-foreach="saleorders" t-as="saleorder">
<a t-attf-href="/sale-order/my-order"class="btn btn-info">
<h4><spant-esc="saleorder.name"/></h4>
</a>
</t>
</div>
</div>
</t>
</template>


I was able to print the name of all the sale order, but I wanted to print only the sale order of the logged in user.
Any help is really appreciated.
Thanks!

Avatar
Discard
Author

Yes, but I did't understand

Author

I can see everything under my account section but i want to redirect in the website menu button

Author Best Answer

Achieved my solution by:

<odoo>
<data noupdate="0">
<record id="furdo_portal_sale_order_menu"model="website.menu">
<field name="name">Sale Orders</field>
<field name="url">/my/orders</field>
<field name="sequence"type="int">1</field>
</record>
</data>
</odoo>

Thanks!

Avatar
Discard
Best Answer

Did you check the default functionality and code of the sales portal: https://www.odoo.com/documentation/user/12.0/ecommerce/shopper_experience/portal.html?

Avatar
Discard
Best Answer

Hello Ujjwal Singh,

By using following code we can do it.

class saleOrder(http.Controller):


    @http.route('/sale-order', type='http',auth='public',website=True)

    def render_sale_order(self):

user_id = you can get it from http.request or http.request.env.uid or self.env.uid

        saleorders = http.request.env['sale.order'].sudo().search([('user_id','=',user_id)])

    return http.request.render('sale_portal.sale_order', {'saleorders': saleorders})

Avatar
Discard
Related Posts Replies Views Activity
6
Jan 24
11970
2
Dec 18
3212
5
Nov 18
6809
2
Aug 23
9978
1
Aug 21
4969