Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

1

How to get current url in odoo 9?

By
Prince Caspion
on 10/30/16, 10:58 AM 312 views

Hello all,

I want to fetch the current url like  this :http://localhost:8069/web?debug=#id=10&view_type=form&model=crm.lead&action=251

in method.

How can we do that? i've tried with several ways but didn't work for me. I can get the base url using config parameter but not ful URL.

Regards,

Prince.


 


1
shameem@aχoncoms
On 10/31/16, 1:18 AM

Hi Prince, You try my way


Step1 : Create a javascript file and call a python function when URL changes

refer : https://www.odoo.com/forum/help-1/question/odoo-9-website-js-help-109603#answer-109604

Pass the current url in that function

Example

$(window).on('hashchange', function(e){
    ajax.jsonRpc("/action_set_current_url/", 'call', window.location.href)
});


Step2: In python function, Set the current url to session.

Example

from openerp import http
from openerp.http import request
class YourModel(http.Controller):
    @http.route(['/action_set_current_url/<string:url>'], type='json', auth="public")
    def set_current_url(self, url,**post):
        # CODE TO SET COOKIES
        request.session['my_current_url'] = url


Step3:

 Call the current url from your function

 Example

def your_function(self):
    # CODE TO GET URL
    current_url = request.session.get('my_current_url')


Note : my code is not tested

thanks for your answer and quick response. but the problem is my function is called in back end it is not dealing with any web/js action. I am not sure, can i get the current full path in the method which is called in button click.

Prince Caspion
on 10/31/16, 1:40 AM

I have tried many times

https://www.odoo.com/forum/help-1/question/how-to-get-current-url-from-bowser-101333#answer-108714

I found this is only one solution

It is possible in backend

Link JS like this

<template id="assets_backend" name="im assets" inherit_id="web.assets_backend">

<xpath expr="." position="inside">

<script type="text/javascript" src="/path /to/file.js"></script>

</xpath>

</template>

shameem@aχoncoms
on 10/31/16, 1:47 AM

thanks, i will check it.

Prince Caspion
on 10/31/16, 5:47 AM

A small change in my answer. I told to write script when document is ready.

But you need to write when url changes

shameem@aχoncoms
on 11/2/16, 2:33 AM
0

deep

--deep--
1617
| 5 4 7
Bengaluru, India
--deep--

Techno-Functional Associate with 6+ years of experience in Odoo (formerly known as OpenERP).

deep
On 10/31/16, 1:45 AM

You can get the current url from Prams object as follows

base_url = self.env['ir.config_parameter'].sudo().get_param('web.base.url')


or you can fetch the details from self.environment



I've already tried this one but it just gives base url not complete url. i need complete url.

Prince Caspion
on 11/1/16, 8:19 AM

Then fetch the details from self.environment or http/request

deep
on 11/1/16, 9:12 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 10/30/16, 10:58 AM
Seen: 312 times
Last updated: 11/1/16, 9:30 PM