Skip to content

Commit 94c93c0

Browse files
MohammedBasionioomsveta
authored andcommitted
[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.
1 parent 84c8850 commit 94c93c0

File tree

9 files changed

+78
-23
lines changed

9 files changed

+78
-23
lines changed

addons/t9n/__manifest__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44
"category": "TODO: find the appropriate category",
55
"description": "TODO: write a description of the module",
66
"depends": ["base", "web"],
7-
"data": [
8-
"views/t9n_templates.xml"
9-
],
107
"application": True,
118
"assets": {
129
"web.assets_backend": [
1310
"t9n/static/src/**/*",
1411
],
1512
},
13+
"data": [
14+
"security/ir.model.access.csv",
15+
"views/t9n_project_views.xml",
16+
"views/t9n_menu_views.xml",
17+
],
1618
"license": "LGPL-3",
1719
}

addons/t9n/models/language.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@
44
class Language(models.Model):
55
_name = "t9n.language"
66
_description = "Language"
7+
8+
name = fields.Char("Language", required=True)

addons/t9n/models/message.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33

44
class Message(models.Model):
5-
""" Models a localizable message, i.e. any textual content to be translated.
6-
Messages are retrieved from a Resource.
7-
A Message localized to a specific Language becomes a Translation.
5+
"""Models a localizable message, i.e. any textual content to be translated.
6+
Messages are retrieved from a Resource.
7+
A Message localized to a specific Language becomes a Translation.
88
"""
9+
910
_name = "t9n.message"
1011
_description = "Localizable message"
1112

@@ -14,7 +15,7 @@ class Message(models.Model):
1415
)
1516
resource_id = fields.Many2one(
1617
comodel_name="t9n.resource",
17-
help="The resource (typically a file) from which the entry is coming from."
18+
help="The resource (typically a file) from which the entry is coming from.",
1819
)
1920
translation_ids = fields.One2many(
2021
comodel_name="t9n.translation",

addons/t9n/models/project.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
from odoo import fields, models
1+
from odoo import fields, models, api, _
2+
from odoo.exceptions import ValidationError
23

34

45
class Project(models.Model):
5-
""" A project is a collection of Resources to be localized into a given set
6-
of Languages.
6+
"""A project is a collection of Resources to be localized into a given set
7+
of Languages.
78
"""
9+
810
_name = "t9n.project"
911
_description = "Translation project"
1012

13+
name = fields.Char("Project", required=True)
1114
src_lang_id = fields.Many2one(
1215
comodel_name="t9n.language",
1316
string="Source Language",
14-
help="The original language of the messages you want to translate."
17+
help="The original language of the messages you want to translate.",
1518
)
1619
resource_ids = fields.One2many(
1720
comodel_name="t9n.resource",
@@ -23,3 +26,11 @@ class Project(models.Model):
2326
string="Languages",
2427
help="The list of languages into which the project can be translated.",
2528
)
29+
30+
@api.constrains("src_lang_id", "target_lang_ids")
31+
def _check_source_and_target_languages(self):
32+
for record in self:
33+
if record.src_lang_id in record.target_lang_ids:
34+
raise ValidationError(
35+
_("Target languages must be different from source language.")
36+
)

addons/t9n/models/resource.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ class Resource(models.Model):
55
_name = "t9n.resource"
66
_description = "Resource file"
77

8+
name = fields.Char("Resource")
89
message_ids = fields.One2many(
910
comodel_name="t9n.message",
1011
inverse_name="resource_id",
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
11
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
2+
access_t9n_project_system,t9n.project.system,t9n.model_t9n_project,base.group_system,1,1,1,1
3+
access_t9n_language_system,t9n.language.system,t9n.model_t9n_language,base.group_system,1,1,1,1
4+
access_t9n_message_system,t9n.message.system,t9n.model_t9n_message,base.group_system,1,1,1,1
5+
access_t9n_resource_system,t9n.resource.system,t9n.model_t9n_resource,base.group_system,1,1,1,1
6+
access_t9n_translation_system,t9n.translation.system,t9n.model_t9n_translation,base.group_system,1,1,1,1

addons/t9n/views/t9n_menu_views.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0"?>
2+
<odoo>
3+
<record id="t9n.open_app" model="ir.actions.client">
4+
<field name="name">Translate</field>
5+
<field name="tag">t9n.open_app</field>
6+
<field name="target">main</field>
7+
</record>
8+
<menuitem id="t9n.menu_root" name="Translations" action="t9n.open_app"/>
9+
<menuitem id="t9n.project_menu" name="Projects" action="t9n.project_action" parent="t9n.menu_root"/>
10+
</odoo>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0"?>
2+
<odoo>
3+
<record id="t9n.project_action" model="ir.actions.act_window">
4+
<field name="name">Projects</field>
5+
<field name="res_model">t9n.project</field>
6+
<field name="view_mode">tree,form</field>
7+
</record>
8+
9+
<record id="t9n.project_view_form" model="ir.ui.view">
10+
<field name="name">t9n.project.form</field>
11+
<field name="model">t9n.project</field>
12+
<field name="arch" type="xml">
13+
<form>
14+
<sheet>
15+
<h1>
16+
<field name="name"/>
17+
</h1>
18+
<notebook>
19+
<page string="Resources">
20+
<field name="resource_ids"/>
21+
</page>
22+
<page string="Description">
23+
<group>
24+
<group>
25+
<field name="src_lang_id" domain="[('id', 'not in', target_lang_ids)]"/>
26+
<field name="target_lang_ids" domain="[('id', '!=', src_lang_id)]"/>
27+
</group>
28+
</group>
29+
</page>
30+
</notebook>
31+
</sheet>
32+
</form>
33+
</field>
34+
</record>
35+
</odoo>

addons/t9n/views/t9n_templates.xml

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)