Workflow doesn't propagate context and makes strings untranslatable

Bug #434266 reported by Albert Cervera i Areny - http://www.NaN-tic.com
24
This bug affects 5 people
Affects Status Importance Assigned to Milestone
Odoo Server (MOVED TO GITHUB)
Fix Released
Low
OpenERP's Framework R&D

Bug Description

None of the functions of the workflow service accept (and thus propagate) the context. This means that when an exception is risen (for example in action_move_create() in account/invoice.py) it isn't translated.

This is not a corner case, for example, it's usual to get a message when the user tries to validate a provider invoice in which totals differ.

I may work on that, but need to know whether the patch will be accepted and for which version it'd be applied.

Related branches

Revision history for this message
Ujjvala Collins (uco-openerp) wrote :

Hello,

Can you please tell whether you have made changes in your .po files or not?
And are these changes working perfectly at your end?

Thanks.

Revision history for this message
Albert Cervera i Areny - http://www.NaN-tic.com (albert-nan) wrote :

No, it does not translate it correctly, but the context "arrives" correctly at:

    def action_move_create(self, cr, uid, ids, context={}):

Translation doesn't work because there're these lines of code:

            context.update({'lang': inv.partner_id.lang})
            compute_taxes = ait_obj.compute(cr, uid, inv.id, context=context)

before the call to:

            raise osv.except_osv(_('Bad total !'), _('Please verify the price of the invoice !\nThe real total does not match the computed total.'))

So, the previous lines should be:

            ctx = {}
            ctx.update( context )
            ctx['lang'] = inv.partner_id.lang
            compute_taxes = ait_obj.compute(cr, uid, inv.id, context=ctx)

For the rest everything should be OK. As I said the context reaches the function with the correct value. Please check out latest changes from the branch as I found some bugs which should now be fixed. I think that could be considered stable.

Revision history for this message
Jay Vora (Serpent Consulting Services) (jayvora) wrote :

Hello Albert,

This is the issue of only the .po file. Nothing has to do with context as far as i know.

I would like to request you to go on supplier invoice with french language, generate the bad total error in English.

No, base/i18n/fr_FR.po .This file will be having the error listed. Add some translation here, Upgrade the module and have a look on the same error.

Thanks.

Changed in openobject-server:
status: New → Invalid
Revision history for this message
Albert Cervera i Areny - http://www.NaN-tic.com (albert-nan) wrote :

First of all, this bug is not only about one untranslatable string in the invoice. It's about untranslatable strings in all actions triggered from the workflow.

Second, yes, context has EVERYTHING to do with translations. Take a look at the code in "tools/translate.py" and GettextAlias class there. You need the context to translate the string into user's language, so one can't change the value of "lang" key in the "context" variable, unless she knows what's doing.

Third, Fabien already confirmed this was something to be considered as a bug.

Changed in openobject-server:
status: Invalid → New
Revision history for this message
Jay Vora (Serpent Consulting Services) (jayvora) wrote :

Hello Albert,

I agree that Context has a vital role to play in translations, but I was talking about the current issue.

The error message string belongs to code(Python code).

As I said, You would prefer to follow the way I mentioned. Its only missing translation in .po file.

Ok, we will have a discussion regarding this issue.

Thanks.

Revision history for this message
Albert Cervera i Areny - http://www.NaN-tic.com (albert-nan) wrote : Re: [Bug 434266] Re: Workflow doesn't propagate context and makes strings untranslatable

A Dimecres, 30 de setembre de 2009, Jay (Open ERP) va escriure:
> Hello Albert,
>
> I agree that Context has a vital role to play in translations, but I was
> talking about the current issue.
>
> The error message string belongs to code(Python code).

I don't think you looked at the code I told you in tools/translate.py. Python
code strings are ALSO translated into the language indicated by the context
variable too. So having the appropiate context is a MUST there. You won't be
able to translate that string even if you modify the appropiate .po file.

Apart from translations, context is very important in OpenERP as you already
know, so we definitely need the context to be propagated to workflow steps
too.

>
> As I said, You would prefer to follow the way I mentioned. Its only
> missing translation in .po file.
>
> Ok, we will have a discussion regarding this issue.
>
> Thanks.
>

--
Albert Cervera i Areny
http://www.NaN-tic.com
Mòbil: +34 669 40 40 18

Revision history for this message
Borja López Soilán (NeoPolus) (borjals) wrote :

As Albert said, the context is not being passed on the workflow 'executes'. Enabling the RPC debug output on the GTK Client, you get something like this:

For a normal action over an object:

DEBUG_RPC:rpc.request:('execute', 'test', 1, 'pass', ('account.invoice.line', 'read', [173], ['__last_update', 'uos_id', 'name', 'price_unit', 'price_subtotal', 'price_subtotal_incl', 'invoice_line_tax_id', 'product_id', 'account_analytic_id', 'quantity', 'account_id'], {'lang': u'es_ES', 'tz': False}))

The last dict is the context, and it contains a 'lang' key.

For an action over a workflow:

DEBUG_RPC:rpc.request:('exec_workflow', 'test', 1, 'pass', (u'account.invoice', 'invoice_open', 136L))

No context dict, so no 'lang' is defined here.

In some places, like the invoice.action_create, a new context is created with a new lang key IN INCONSISTENT WAYS: some actions will never get a lang, some actions will get an incorrect lang.

For example, in invoice.action_create the lang of the partner is used, instead of the lang of the current user, for displaying warnings.

That means, that:
  - Spanish users creating an (invalid) invoice for a spanish partner, will get a warning in spanish. (i.e. "¡Total erróneo!")
  - Spanish users creating an (invalid) invoice for a french partner, will get a warning in french. (I did get "Bad Total !", seems that it is not translated to french...)
  - Spanish users creating an (invalid) invoice for a partner with no language defined, will get a warning in english. (i.e. "Bad Total !")

In the end... those -put here whatever language you like- speaking users just get pissed! (and so do the translators that don't understand why some messages won't get propertly translated).

Revision history for this message
Christophe CHAUVET (christophe-chauvet) wrote :

Hi Jay

I confirm this issue at technical training in tiny belgium, the GTK client (and maybe Web client) doesn't transmit the context to the server, and when a raise osv.except_osv(_('Error'), _('boo')) only return the messagebox in english.

debug trace
DEBUG_RPC:rpc.request:('exec_workflow', 'formation2', 1, 'admin', (u'openacademy.formation', 'button_confirm', 9))

context is missing

Regards,

Revision history for this message
Albert Cervera i Areny - http://www.NaN-tic.com (albert-nan) wrote :

A Dimecres, 21 d'octubre de 2009, Christophe Chauvet - http://www.syleam.fr/
va escriure:
> Hi Jay
>
> I confirm this issue at technical training in tiny belgium, the GTK
> client (and maybe Web client) doesn't transmit the context to the
> server, and when a raise osv.except_osv(_('Error'), _('boo')) only
> return the messagebox in english.

None of the clients do except my locally patched Koo. We need first to have
the server support that and then change the clients. Of course, trying to use
newer clients with older server versions simply won't work.

>
> debug trace
> DEBUG_RPC:rpc.request:('exec_workflow', 'formation2', 1, 'admin',
> (u'openacademy.formation', 'button_confirm', 9))
>
> context is missing
>
> Regards,
>

--
Albert Cervera i Areny
http://www.NaN-tic.com
Mòbil: +34 669 40 40 18

Changed in openobject-server:
status: New → Confirmed
Revision history for this message
Anup(SerpentCS) (anup-serpent) wrote :

Hello Everyone,

    I have checked the code in translate.py and also in invoice.py. I also tried your code but both the code give the same result. the problem was with the translate.py code and we have modified that solves the problem.
    And for the action_move_create's string "Bad Total" to be translated you need a .po entry which is blank. For that i m attaching a patch you can apply and check.
   The changes in the translate.py are committed in stable server revision no 1875.
    Please apply the changes and let us notify.

Thank you.

Revision history for this message
Anup(SerpentCS) (anup-serpent) wrote :

If the lang in the cotext is false the only reason can be that there is no language defined for the specific partner.

Revision history for this message
Albert Cervera i Areny - http://www.NaN-tic.com (albert-nan) wrote :

Can you carefully read the bug report, please? Let me quote the most important
sentence:

"None of the functions of the workflow service accept (and thus propagate) the
context. [...]"

A Dimecres, 4 de novembre de 2009, Anup (Open ERP) va escriure:
> If the lang in the cotext is false the only reason can be that there is
> no language defined for the specific partner.
>
> ** Attachment added: "invoice_patch.diff"
> http://launchpadlibrarian.net/35103589/invoice_patch.diff
>

--
Albert Cervera i Areny
http://www.NaN-tic.com
Mòbil: +34 669 40 40 18

Revision history for this message
Jay Vora (Serpent Consulting Services) (jayvora) wrote :

Hi,

Can you please check with this patch?

Thank you.

Revision history for this message
Albert Cervera i Areny - http://www.NaN-tic.com (albert-nan) wrote :

IMHO this is not the best solution. It solves the problem of translations in
exceptions risen from a workflow, but I think that is not the only usage of
context.

A Divendres, 13 de novembre de 2009, Jay (Open ERP) va escriure:
> Hi,
>
> Can you please check with this patch?
>
> Thank you.
>
> ** Attachment added: "context_trans.patch"
> http://launchpadlibrarian.net/35651322/context_trans.patch
>

--
Albert Cervera i Areny
http://www.NaN-tic.com
Mòbil: +34 669 40 40 18

Revision history for this message
Albert Cervera i Areny - http://www.NaN-tic.com (albert-nan) wrote :

If the problem is API breakage, I'd go for this patch for 5.0 (I think it will
do the job for most cases) and propagate context in 5.2.

Just my 2 cents.

A Divendres, 13 de novembre de 2009, Albert Cervera i Areny va escriure:
> IMHO this is not the best solution. It solves the problem of translations
> in exceptions risen from a workflow, but I think that is not the only
> usage of context.
>
> A Divendres, 13 de novembre de 2009, Jay (Open ERP) va escriure:
> > Hi,
> >
> > Can you please check with this patch?
> >
> > Thank you.
> >
> > ** Attachment added: "context_trans.patch"
> > http://launchpadlibrarian.net/35651322/context_trans.patch
>

--
Albert Cervera i Areny
http://www.NaN-tic.com
Mòbil: +34 669 40 40 18

Changed in openobject-server:
assignee: nobody → Anup (Open ERP) (ach-openerp)
Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote :

For the record, marking this bug as the original one, instead of (wrongly) a duplicate of bug 432504, that is related by different. Further duplicates should refer to this one.

Changed in openobject-server:
assignee: Anup(Sunlux) (anup-sunlux) → OpenERP's Framework R&D (openerp-dev-framework)
importance: Undecided → Low
milestone: none → 6.1
Revision history for this message
Gustavo Adrian Marino (gamarino) wrote :

I have implemented the attached patch to solve the translation problems due to lack of context info for both workflow triggers and onchange events.
Best regards

Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote :

A workaround for this issue was implemented in 6.0 [1] and 6.1 [2], and will be ported to trunk along with the next batch of corrections. It is similar to the patch suggested by Jay in comment #13, and works by translating in the language of the user performing the action, when no specific context can be found.
There is a limitation to this workaround: some operations are performed using temporarily elevated privileges (i.e. sudo mode), and in that case the language of the admin user will be used instead. This might be suitable for most companies where all employees speak the same language, but large international companies should make sure the admin language is set to a common language that everyone can understand (e.g. english).

Note: The workflow engine will still not propagate the context, because that requires a big refactoring and carries major risks, and it would be deprecated very soon anyway, when the new OpenERP API is implemented [3]. There is also no reason to propagate context except for translations, because the workflow itself should not depend on the context: it should operate exclusively based on the state of the documents - and should always fulfill the same 'contract'. So if translations work, there is no need to propagate the context anymore. This is why we can consider the bug fixed.

Thanks for your patience!

[1] server revno 3627 revision-id: <email address hidden>
[2] server revno 4226 revision-id: <email address hidden>
[3] the new ORM API that was introduced during OpenERP Open Days 2012 in Brussels

Changed in openobject-server:
status: Confirmed → Fix Released
Revision history for this message
Levent Karakaş (levent) wrote :

It's 2015! Is this bug still remains or am I wrong?

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.