From 5c1d70d3c825991b9ed400b190c6a897e7cc0974 Mon Sep 17 00:00:00 2001 From: Mohammed Basioni Date: Fri, 8 Mar 2024 14:20:55 +0200 Subject: [PATCH] [IMP] t9n: add tab in the menu to list available projects. This commit adds a tab in the menu bar that lists the available projects. Also, the form view of the project is configured to have two tabs: one for resources and the other one for the description of the project. Also, some security permissions have been included in the manifest file. --- addons/t9n/__manifest__.py | 8 +++--- addons/t9n/models/language.py | 2 ++ addons/t9n/models/message.py | 9 ++++--- addons/t9n/models/project.py | 19 +++++++++++--- addons/t9n/models/resource.py | 1 + addons/t9n/security/ir.model.access.csv | 5 ++++ addons/t9n/views/t9n_menu_views.xml | 10 +++++++ addons/t9n/views/t9n_project_views.xml | 35 +++++++++++++++++++++++++ addons/t9n/views/t9n_templates.xml | 12 --------- 9 files changed, 78 insertions(+), 23 deletions(-) create mode 100644 addons/t9n/views/t9n_menu_views.xml create mode 100644 addons/t9n/views/t9n_project_views.xml delete mode 100644 addons/t9n/views/t9n_templates.xml diff --git a/addons/t9n/__manifest__.py b/addons/t9n/__manifest__.py index 0aa80663ed4fe..6ac8c7a01d92a 100644 --- a/addons/t9n/__manifest__.py +++ b/addons/t9n/__manifest__.py @@ -4,14 +4,16 @@ "category": "TODO: find the appropriate category", "description": "TODO: write a description of the module", "depends": ["base", "web"], - "data": [ - "views/t9n_templates.xml" - ], "application": True, "assets": { "web.assets_backend": [ "t9n/static/src/**/*", ], }, + "data": [ + "security/ir.model.access.csv", + "views/t9n_project_views.xml", + "views/t9n_menu_views.xml", + ], "license": "LGPL-3", } diff --git a/addons/t9n/models/language.py b/addons/t9n/models/language.py index 9a0b69ce9cbcc..91f9a9232d182 100644 --- a/addons/t9n/models/language.py +++ b/addons/t9n/models/language.py @@ -4,3 +4,5 @@ class Language(models.Model): _name = "t9n.language" _description = "Language" + + name = fields.Char("Language", required=True) diff --git a/addons/t9n/models/message.py b/addons/t9n/models/message.py index d6846e08da082..a36404dcabcf4 100644 --- a/addons/t9n/models/message.py +++ b/addons/t9n/models/message.py @@ -2,10 +2,11 @@ class Message(models.Model): - """ Models a localizable message, i.e. any textual content to be translated. - Messages are retrieved from a Resource. - A Message localized to a specific Language becomes a Translation. + """Models a localizable message, i.e. any textual content to be translated. + Messages are retrieved from a Resource. + A Message localized to a specific Language becomes a Translation. """ + _name = "t9n.message" _description = "Localizable message" @@ -14,7 +15,7 @@ class Message(models.Model): ) resource_id = fields.Many2one( comodel_name="t9n.resource", - help="The resource (typically a file) from which the entry is coming from." + help="The resource (typically a file) from which the entry is coming from.", ) translation_ids = fields.One2many( comodel_name="t9n.translation", diff --git a/addons/t9n/models/project.py b/addons/t9n/models/project.py index 49c46d072d429..424edfecc080d 100644 --- a/addons/t9n/models/project.py +++ b/addons/t9n/models/project.py @@ -1,17 +1,20 @@ -from odoo import fields, models +from odoo import fields, models, api, _ +from odoo.exceptions import ValidationError class Project(models.Model): - """ A project is a collection of Resources to be localized into a given set - of Languages. + """A project is a collection of Resources to be localized into a given set + of Languages. """ + _name = "t9n.project" _description = "Translation project" + name = fields.Char("Project", required=True) src_lang_id = fields.Many2one( comodel_name="t9n.language", string="Source Language", - help="The original language of the messages you want to translate." + help="The original language of the messages you want to translate.", ) resource_ids = fields.One2many( comodel_name="t9n.resource", @@ -23,3 +26,11 @@ class Project(models.Model): string="Languages", help="The list of languages into which the project can be translated.", ) + + @api.constrains("src_lang_id", "target_lang_ids") + def _check_source_and_target_languages(self): + for record in self: + if record.src_lang_id in record.target_lang_ids: + raise ValidationError( + _("Target languages must be different from source language.") + ) diff --git a/addons/t9n/models/resource.py b/addons/t9n/models/resource.py index 4219a1f947094..792f71b9ca39e 100644 --- a/addons/t9n/models/resource.py +++ b/addons/t9n/models/resource.py @@ -5,6 +5,7 @@ class Resource(models.Model): _name = "t9n.resource" _description = "Resource file" + name = fields.Char("Resource") message_ids = fields.One2many( comodel_name="t9n.message", inverse_name="resource_id", diff --git a/addons/t9n/security/ir.model.access.csv b/addons/t9n/security/ir.model.access.csv index 97dd8b917b8a2..892a06d3a359f 100644 --- a/addons/t9n/security/ir.model.access.csv +++ b/addons/t9n/security/ir.model.access.csv @@ -1 +1,6 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_t9n_project_system,t9n.project.system,t9n.model_t9n_project,base.group_system,1,1,1,1 +access_t9n_language_system,t9n.language.system,t9n.model_t9n_language,base.group_system,1,1,1,1 +access_t9n_message_system,t9n.message.system,t9n.model_t9n_message,base.group_system,1,1,1,1 +access_t9n_resource_system,t9n.resource.system,t9n.model_t9n_resource,base.group_system,1,1,1,1 +access_t9n_translation_system,t9n.translation.system,t9n.model_t9n_translation,base.group_system,1,1,1,1 diff --git a/addons/t9n/views/t9n_menu_views.xml b/addons/t9n/views/t9n_menu_views.xml new file mode 100644 index 0000000000000..8abacaa28f29f --- /dev/null +++ b/addons/t9n/views/t9n_menu_views.xml @@ -0,0 +1,10 @@ + + + + Translate + t9n.open_app + main + + + + diff --git a/addons/t9n/views/t9n_project_views.xml b/addons/t9n/views/t9n_project_views.xml new file mode 100644 index 0000000000000..dbd1c557a8be5 --- /dev/null +++ b/addons/t9n/views/t9n_project_views.xml @@ -0,0 +1,35 @@ + + + + Projects + t9n.project + tree,form + + + + t9n.project.form + t9n.project + +
+ +

+ +

+ + + + + + + + + + + + + +
+
+
+
+
diff --git a/addons/t9n/views/t9n_templates.xml b/addons/t9n/views/t9n_templates.xml deleted file mode 100644 index 75cb0ff6bb04b..0000000000000 --- a/addons/t9n/views/t9n_templates.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - Translate - t9n.open_app - main - - - - -