Product quantity unit is translated into the wrong language in sale report

So I am creating offers for different customers, and based on the language in the party settings the offer should be in English or German. This works 99%, however, when creating an offer to a non-German client, for some reason the unit in each of the lines in the sale report always says “Stück”, i.e. the German translation for “Units”.

In the original report, the placeholder in question is format_number_symbol(line.quantity, sale.party.lang, line.unit, digits=line.unit.digits). I have played around a bit and tried to “break it up” by using line.product_uom_category.rec_name, just to see what happens. It still produces “Stück” instead of “Units”. Everything else is in English though.

Is there a setting I am missing somewhere?

Are you sure the party has a language set?

Yes, I even confirmed it by looking in the Database. And if I don’t set any language, the reports are usually in German, as this is the primary language for our Tryton installation.

Maybe you’re missing the English translation of the unit name itself? That’s the only other thing I can think of

Yeah, I triple-checked that by using the Tryton Console; there, because no language is involved, it says “Unit”, as expected.

I’m thinking that we’re talking about the unit symbol, since that’s what format_number_symbol is for. If anything, you should be getting ‘u’ in English, or whatever symbol is used for German. Is the translation for the symbol done as well? (Sorry if you’ve already checked this too, but I really can’t think of anything else, as format_number_symbol(line.quantity, sale.party.lang, line.unit, digits=line.unit.digits) works perfectly fine in our reports).

Is this the only item where translation does not work? Which Tryton version are you running?

Yes, I checked that.

Is this the only item where translation does not work? Which Tryton version are you running?

Yes, everything else works as expected; as I said, the report is 99% English. I am running Version 7.4.

For the time being, I decided to implement a workaround that looks like this:

<format_number(line.quantity, sale.party.lang, digits=line.unit.digits)> <choose test=""><when test="sale.party.lang.rec_name=='Englisch' and line.product_uom_category.rec_name=='Stück'">Units</when><otherwise test=""><line.product_uom_category.rec_name></otherwise></choose>

This hardcodes “Units” and will stop to work if we ever sell products that are quantified not in “Units”, but e.g. “grams”; however, this does not seem to be the case for the forseeable future.

If I figure out the original reason for the issue, I will update it here. I am 100% sure that I misconfigured something, but I just can’t find it right now.

For me this means that line.unit does not have the right language context.
Normally it should inherit the context from the record which should have it set by set_lang call.

As far as I can tell, the only set_lang call we have is this in the top of the report:

set_lang(sale.party.lang and sale.party.lang.code or 'de_DE')

So de_DE is the default for parties without a Language. I could try to change this and see what happens.

Then you are missing sale.set_lang(sale.party.lang)

1 Like

Indeed, that fixed it, thanks a lot!

Also, to include all details: I was wrong when I answered @yangoon before. More experimentation showed that the names of the products used the wrong language, too. Thanks to @ced this is now resolved as well!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.