تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
11819 أدوات العرض

I created a qweb report and it worked successfully. When I came to translate it I added this code:

<template id="my_report_id">
    <t t-call="report.html_container">
        <t t-foreach="doc_ids" t-as="doc_id">
        <t t-raw="translate_doc(doc_id, doc_model, 'lang' , 'my_module.my_report_id_document')"/>
        </t>
    </t>
</template>

When I tried to run it I got the following error 


QWebException: ""'my model name' object has no attribute 'lang'" while evaluating
'doc.lang'" while evaluating
"translate_doc(doc_id, doc_model, 'lang' , 'my_module.my_report_id_document')"

I changed it to several choices , for example:

'partner_id.lang'

user.lang

instance.session.user_context.lang, as per this link 

with no success. 

The module I'm working on I created it from scratch and it does not depend on any other module. How to resolve this issue.  

الصورة الرمزية
إهمال
أفضل إجابة

Hi,


instance.session.user_context.lang is in webclient (javascript) 


You want probably use  "request.lang"

But the method translate_doc take a field to specify the lang, not a lang directly...


In your case you should browse yourself in the correct lang the doc (with request.lang) and set translatable to True in the context


That should works, here the code in odoo...


if ctx.get('translatable') is True:
    qcontext['o'] = doc
else:
    # Reach the lang we want to translate the doc into
    ctx['lang'] = eval('doc.%s' % lang_field, {'doc': doc})
    qcontext['o'] = self.pool[model].browse(cr, uid, doc_id, context=ctx)

 

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
3
مايو 25
737
1
مايو 25
511
1
أبريل 25
1632
1
فبراير 25
686
0
أبريل 25
763