Skip to content

Commit

Permalink
[IMP] t9n: add tab in the menu to list available projects.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
MohammedBasioni committed May 6, 2024
1 parent c4f75f9 commit 5c1d70d
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 23 deletions.
8 changes: 5 additions & 3 deletions addons/t9n/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
2 changes: 2 additions & 0 deletions addons/t9n/models/language.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
class Language(models.Model):
_name = "t9n.language"
_description = "Language"

name = fields.Char("Language", required=True)
9 changes: 5 additions & 4 deletions addons/t9n/models/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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",
Expand Down
19 changes: 15 additions & 4 deletions addons/t9n/models/project.py
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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.")
)
1 change: 1 addition & 0 deletions addons/t9n/models/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions addons/t9n/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions addons/t9n/views/t9n_menu_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0"?>
<odoo>
<record id="t9n.open_app" model="ir.actions.client">
<field name="name">Translate</field>
<field name="tag">t9n.open_app</field>
<field name="target">main</field>
</record>
<menuitem id="t9n.menu_root" name="Translations" action="t9n.open_app"/>
<menuitem id="t9n.project_menu" name="Projects" action="t9n.project_action" parent="t9n.menu_root"/>
</odoo>
35 changes: 35 additions & 0 deletions addons/t9n/views/t9n_project_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0"?>
<odoo>
<record id="t9n.project_action" model="ir.actions.act_window">
<field name="name">Projects</field>
<field name="res_model">t9n.project</field>
<field name="view_mode">tree,form</field>
</record>

<record id="t9n.project_view_form" model="ir.ui.view">
<field name="name">t9n.project.form</field>
<field name="model">t9n.project</field>
<field name="arch" type="xml">
<form>
<sheet>
<h1>
<field name="name"/>
</h1>
<notebook>
<page string="Resources">
<field name="resource_ids"/>
</page>
<page string="Description">
<group>
<group>
<field name="src_lang_id" domain="[('id', 'not in', target_lang_ids)]"/>
<field name="target_lang_ids" domain="[('id', '!=', src_lang_id)]"/>
</group>
</group>
</page>
</notebook>
</sheet>
</form>
</field>
</record>
</odoo>
12 changes: 0 additions & 12 deletions addons/t9n/views/t9n_templates.xml

This file was deleted.

0 comments on commit 5c1d70d

Please sign in to comment.