Skip to Content
Menu
This question has been flagged
1 Reply
3787 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 ?

Avatar
Discard
Author Best Answer

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])
Avatar
Discard
Related Posts Replies Views Activity
1
Jul 19
2486
4
May 16
5410
0
Mar 15
2915
2
Mar 15
3058
0
Nov 22
1422