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

Two languages in a invoice

By
Steven Bliek
on 4/24/14, 5:00 AM 1,416 views

Hi there,

I would like to use two languages in one report (invoice). Not for every line, but only for the product name.

I know I have to use setLang but somehow I can't get it to work correctly. The whole report is made up in the language of the client [[ setLang(o.partner_id.lang) ]]. But we would like to have the name of the product in English and Chinese.

This is (a little part of) what I have till now.

<td>
  <para style="terp_default_9">[[ setLang('zh_CN') ]] [[ format(l.product_id.name) ]]</para>
</td>
<td>
  <para style="terp_default_9">[[ setLang('en_US') ]] [[ format(l.product_id.name) ]]</para>
</td>

I will send a big hug to the one who is able to help me ;-)

2
MacKan
On 5/21/14, 8:35 AM

def translation(self,name,lang=''zh_CN'',source_type=''):

    if source_type:
        query = "select value from ir_translation where lang='"+lang+"' and type='"+source_type+"' and src='"+name+"'"
    else:
        query = "select value from ir_translation where lang='"+lang+"' and src='"+name+"'"
    cr = self.cr
    cr.execute(str(query))
    res_trans = cr.fetchone()
    res = res_trans and res_trans[0] or name
    return res
              
def __init__(self, cr, uid, name, context):

    super(contract, self).__init__(cr, uid, name, context)
    self.cr = cr # re initialize cr
    self.localcontext.update({
            'time': time,
            'translate': self.translation
        })

<td>
  <para style="terp_default_9">[[ translate(format(l.product_id.name)) ]]</para>
</td>

or

<td>
  <para style="terp_default_9">[[translate(format(l.product_id.name),'en_US') ]]</para>
</td>

 

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

0 follower(s)

Stats

Asked: 4/24/14, 5:00 AM
Seen: 1416 times
Last updated: 3/16/15, 8:10 AM