Adding translation on confirm attribute defined in other module

Hi,

We have a custom module that defines the confirm attribute of the Confirm button of the Sale model. I will expect to include the translation of such attribute under or custom module but we are failing to do so. Here is my xml definition of such change:

<tryton>                                                                       
    <data>                                                                     
        <record model="ir.model.button" id="sale.sale_confirm_button">         
            <field name="confirm">Are you sure to confirm the sale?</field>    
        </record>
    </data>                                                                    
</tryton> 

The issue here is that the translation created by the system is related to the sale module (because the button is created from such module) so we can not update such translation using the standard translation system.

I tried creating an override translation for the Spanish language on the new string but this fails when updating the module:

  File "/home/pokoli/.virtualenvs/sale_confirm/bin/trytond-admin", line 7, in <module>
    exec(compile(f.read(), __file__, 'exec'))
  File "/home/pokoli/projectes/sale_confirm/trytond/bin/trytond-admin", line 23, in <module>
    admin.run(options)
  File "/home/pokoli/projectes/sale_confirm/trytond/trytond/admin.py", line 57, in run
    pool.init(update=options.update, lang=list(lang),
  File "/home/pokoli/projectes/sale_confirm/trytond/trytond/pool.py", line 165, in init
    restart = not load_modules(
  File "/home/pokoli/projectes/sale_confirm/trytond/trytond/modules/__init__.py", line 438, in load_modules
    _load_modules(update)
  File "/home/pokoli/projectes/sale_confirm/trytond/trytond/modules/__init__.py", line 406, in _load_modules
    load_module_graph(graph, pool, update, lang)
  File "/home/pokoli/projectes/sale_confirm/trytond/trytond/modules/__init__.py", line 256, in load_module_graph
    load_translations(pool, node, lang)
  File "/home/pokoli/projectes/sale_confirm/trytond/trytond/modules/__init__.py", line 184, in load_translations
    Translation.translation_import(language, module, files)
  File "/home/pokoli/projectes/sale_confirm/trytond/trytond/ir/translation.py", line 801, in translation_import
    to_save.append(override_translation(res_id,
  File "/home/pokoli/projectes/sale_confirm/trytond/trytond/ir/translation.py", line 768, in override_translation
    translation, = cls.search(domain)
ValueError: not enough values to unpack (expected 1, got 0)

This problem is because the original translation does not exist in the sale module for the Spanish language as the XML import just created the translation for the English language.

Am I doing something wrong? How can I translate such string?

I guess you have to define a new button.

But I can not as the button name should be unique and the ir.model.button can not be deactivable.

Do you mean defining a new button with a diferent name and updating all the views to use the new button? Maybe this can work but I find it quite complex to just update the confirm attribute.

Maybe write_records should use self.module instead of module.

I tried such change and everything works well on the translation database but the problem is that the translation will never be updated as it does not exist any ModelData record for the confirm button related to the overriding module. So tryton thinks this is a local translation and does not export them.

Here is the related code.

I do not see why you are overriding the translations.

If I update write_records the translation is not overriden but related to the current module.
The problem is that the export wizard ignores it as is not related to any model data.

I guess it is a limitation of Tryton.
Any way modifying XML record has never been a clean thing.
For the confirm attribute of button, I guess it is better to modify the attribute in the view.

Also the ir.model.button unique constraint has been at multiple times a problem. I guess it should be replaced by an Exclude for active only. So they can be customized like reports.

I filled Allow to deactivate button access (#11284) · Issues · Tryton / Tryton · GitLab which replaces the unique by Exclude for active only.

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