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.

0

[8] Why my records are not translated in website frontend when using a JS rpc call ?

By
PY
on 9/23/15, 11:03 AM 436 views

Hi !

Pretty much the whole context is in the title. It seems that my product doesn't care about the website lang, just the res.users lang. Here's my JS code:

new openerp.Session()
    .rpc(rpcUrl, { 'user_input': value })
    .then(function(options) {
        if (options) {  
            $datalist.append(options;
        }
    });

and my python controller function called at the 'rpcUrl':

Product = request.env['product.product']
user_input = '%{}%'.format(user_input)
records = Product.search(['|', ('name', '=ilike', user_input),
('default_code', '=ilike', user_input))
if not records:
return False

return ''.join([u'<option value="{}" id="{}">{}</option>'.format(
record.display_name, record.id, record.display_name)
for record in records])

Plain and simple. However, in the page that do the rpc calls, the options appears in the language of the user. But, in the page after, I display the selected products with a t-field element, and there, the website language matters, because the products names are properly translated...


Any help, thought, idea ?

0
PY
On 9/24/15, 10:32 AM

I found a workaround, if not an explanation...

JS:

// the lang is passed through the rpc call as an argument
new openerp.Session()
.rpc(rpcUrl, { 'user_input': value, 'lang': openerp.website.get_context()['lang'] })
.then(function(options) {
if (options) {
$datalist.append(options;
}
});

Python:

# the lang is retrieved in the function arguments
Product = request.env['product.product'].with_context({'lang': lang})
user_input = '%{}%'.format(user_input)
records = Product.search(['|', ('name', '=ilike', user_input),
('default_code', '=ilike', user_input))
if not records:
return False

return ''.join([u'<option value="{}" id="{}">{}</option>'.format(
record.display_name, record.id, record.display_name)
for record in records])

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: 9/23/15, 11:03 AM
Seen: 436 times
Last updated: 9/24/15, 10:32 AM