Skip to content

Instantly share code, notes, and snippets.

@bealdav
Last active April 21, 2023 13:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bealdav/0baf06fab45369fc23e8da8d17a59e6b to your computer and use it in GitHub Desktop.
Save bealdav/0baf06fab45369fc23e8da8d17a59e6b to your computer and use it in GitHub Desktop.
Generate Odoo class code to make fields untranslatable
""" You may want some translatable fields in your project becomes untranslatable
Here is how to produce code
Note: to be executed with odoo shell
"""
print('\n'.join(
["\n\nclass %s(models.Model):\n\t_inherit = '%s'\n\t%s = fields.%s(translate=False)" % (
x.model.replace('.', ' ').title().replace(' ', ''), x.model, x['name'], x.ttype.capitalize())
for x in env['ir.model.fields'].search([('translate', '=', True)], order='model')
if x.ttype in ('char','text') and x.model_id.transient == False]))
# Result
class StockRule(models.Model):
_inherit = 'stock.rule'
name = fields.Char(translate=False)
class UtmCampaign(models.Model):
_inherit = 'utm.campaign'
name = fields.Char(translate=False)
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment