From 9fb52bb7c1059a0ba92713acc3adf291829ef010 Mon Sep 17 00:00:00 2001 From: Petar Najman Date: Fri, 23 Feb 2018 18:30:43 +0100 Subject: [PATCH 01/46] ADD: Adding module project_key --- project_key/README.rst | 72 ++++++++++ project_key/__init__.py | 3 + project_key/__manifest__.py | 19 +++ project_key/controllers/__init__.py | 1 + project_key/controllers/main.py | 42 ++++++ project_key/hooks.py | 12 ++ project_key/models/__init__.py | 2 + project_key/models/project_project.py | 183 ++++++++++++++++++++++++ project_key/models/project_task.py | 109 ++++++++++++++ project_key/static/description/icon.png | Bin 0 -> 9455 bytes project_key/tests/__init__.py | 3 + project_key/tests/test_common.py | 55 +++++++ project_key/tests/test_controller.py | 36 +++++ project_key/tests/test_project.py | 60 ++++++++ project_key/tests/test_task.py | 53 +++++++ project_key/views/project_key_views.xml | 116 +++++++++++++++ 16 files changed, 766 insertions(+) create mode 100644 project_key/README.rst create mode 100644 project_key/__init__.py create mode 100644 project_key/__manifest__.py create mode 100644 project_key/controllers/__init__.py create mode 100644 project_key/controllers/main.py create mode 100644 project_key/hooks.py create mode 100644 project_key/models/__init__.py create mode 100644 project_key/models/project_project.py create mode 100644 project_key/models/project_task.py create mode 100644 project_key/static/description/icon.png create mode 100644 project_key/tests/__init__.py create mode 100644 project_key/tests/test_common.py create mode 100644 project_key/tests/test_controller.py create mode 100644 project_key/tests/test_project.py create mode 100644 project_key/tests/test_task.py create mode 100644 project_key/views/project_key_views.xml diff --git a/project_key/README.rst b/project_key/README.rst new file mode 100644 index 0000000000..32799cf683 --- /dev/null +++ b/project_key/README.rst @@ -0,0 +1,72 @@ +.. image:: https://www.gnu.org/graphics/lgplv3-147x51.png + :target: https://www.gnu.org/licenses/lgpl-3.0.en.html + :alt: License: LGPL-v3 + +============ +Project key +============ + +This module provides functionality to uniquely identify projects and tasks by simple ``key`` field. + + +Usage +===== + +To use this module functionality you just need to: + +On ``project.project`` level: + +In Kanban View: + +#. Go to Project > Dashboard +#. Create +#. Enter project name and use auto generated key or simply override value by entering your own key value. + +In Tree View: + +#. Go to Project > Configuration > Projects +#. Create +#. Enter project name and use auto generated key or simply override value by entering your own key value. + +In form View: + +#. Go to Project > Dashboard +#. Open the projects settings +#. Modify the "key" value +#. After modifying project key the key of any existing tasks related to that project will be updated automatically. + +When you create a project, under the hood a ir.sequence record gets creted with prefix: ``-``. + +On ``project.task`` level: + +#. Actually there is nothing to be done here +#. Task keys are auto generated based on project key value with per project auto incremented number (i.e. PA-1, PA-2, etc) + +In browser address bar: + +#. Navigate to your project by entering following url: http://<>/projects/PROJECT-KEY +#. Navigate to your task by entering following url: http://<>/tasks/TASK-KEY + +Credits +======= + +Contributors +------------ + +* Petar Najman +* Sladjan Kantar + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +To contribute to this module, please visit http://odoo-community.org. diff --git a/project_key/__init__.py b/project_key/__init__.py new file mode 100644 index 0000000000..3d05e191a9 --- /dev/null +++ b/project_key/__init__.py @@ -0,0 +1,3 @@ +from . import models +from . import controllers +from .hooks import post_init_hook diff --git a/project_key/__manifest__.py b/project_key/__manifest__.py new file mode 100644 index 0000000000..f7fa541376 --- /dev/null +++ b/project_key/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2017 - 2018 Modoolar +# License LGPLv3.0 or later (https://www.gnu.org/licenses/lgpl-3.0.en.html). + +{ + "name": "Project key", + "summary": "Module decorates projects and tasks with ``key`` field", + "category": "Project", + "version": "11.0.1.0.0", + "license": "LGPL-3", + "author": "Modoolar, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/project/", + "depends": [ + "project", + ], + "data": [ + "views/project_key_views.xml", + ], + "post_init_hook": "post_init_hook", +} diff --git a/project_key/controllers/__init__.py b/project_key/controllers/__init__.py new file mode 100644 index 0000000000..12a7e529b6 --- /dev/null +++ b/project_key/controllers/__init__.py @@ -0,0 +1 @@ +from . import main diff --git a/project_key/controllers/main.py b/project_key/controllers/main.py new file mode 100644 index 0000000000..a783f3a151 --- /dev/null +++ b/project_key/controllers/main.py @@ -0,0 +1,42 @@ +# Copyright 2017 - 2018 Modoolar +# License LGPLv3.0 or later (https://www.gnu.org/licenses/lgpl-3.0.en.html). + +import werkzeug +from odoo import http +# from odoo.http import request + + +class ProjectBrowser(http.Controller): + + def get_record_url(self, model, domain, action_xml_id): + env = http.request.env() + + records = env[model].search(domain) + record_id = records and records.id or -1 + action_id = env.ref(action_xml_id).id + + return "/web#id=%s&view_type=form&model=%s&action=%s" % ( + record_id, model, action_id + ) + + def get_task_url(self, key): + return self.get_record_url( + "project.task", + [('key', '=ilike', key)], + "project.action_view_task" + ) + + def get_project_url(self, key): + return self.get_record_url( + "project.project", + [('key', '=ilike', key)], + "project.open_view_project_all_config" + ) + + @http.route(['/projects/'], type='http', auth='user') + def open_project(self, key, **kwargs): + return werkzeug.utils.redirect(self.get_project_url(key), 301) + + @http.route(['/tasks/'], type='http', auth='user') + def open_task(self, key, **kwargs): + return werkzeug.utils.redirect(self.get_task_url(key), 301) diff --git a/project_key/hooks.py b/project_key/hooks.py new file mode 100644 index 0000000000..4ff17461dd --- /dev/null +++ b/project_key/hooks.py @@ -0,0 +1,12 @@ +# Copyright 2017 - 2018 Modoolar +# License LGPLv3.0 or later (https://www.gnu.org/licenses/lgpl-3.0.en.html). + + +def post_init_hook(cr, registry): + from odoo import api, SUPERUSER_ID + env = api.Environment(cr, SUPERUSER_ID, {}) + env['project.project']._set_default_project_key() + cr.execute( + "ALTER TABLE project_project ALTER COLUMN key SET NOT NULL", + log_exceptions=False + ) diff --git a/project_key/models/__init__.py b/project_key/models/__init__.py new file mode 100644 index 0000000000..2128188969 --- /dev/null +++ b/project_key/models/__init__.py @@ -0,0 +1,2 @@ +from . import project_project +from . import project_task diff --git a/project_key/models/project_project.py b/project_key/models/project_project.py new file mode 100644 index 0000000000..769297f230 --- /dev/null +++ b/project_key/models/project_project.py @@ -0,0 +1,183 @@ +# Copyright 2017 - 2018 Modoolar +# License LGPLv3.0 or later (https://www.gnu.org/licenses/lgpl-3.0.en.html). + +from odoo import models, fields, api, _ +from odoo.osv import expression + + +class Project(models.Model): + _inherit = "project.project" + + task_key_sequence_id = fields.Many2one( + comodel_name='ir.sequence', + string='Key Sequence', + ondelete="restrict", + ) + + key = fields.Char( + string='key', + size=10, + required=False, + index=True, + ) + + _sql_constraints = [ + ("project_key_unique", "UNIQUE(key)", "Project key must be unique") + ] + + @api.multi + @api.onchange('name') + def _onchange_project_name(self): + for rec in self: + if rec.name: + rec.key = self.generate_project_key(rec.name) + else: + rec.key = '' + + @api.model + def create(self, vals): + if 'key' not in vals: + vals['key'] = self.generate_project_key(vals['name']) + + new_project = super(Project, self).create(vals) + new_project.create_sequence() + + return new_project + + @api.multi + def write(self, values): + update_key = False + + if 'key' in values: + key = values['key'] + update_key = self.key != key + + res = super(Project, self).write(values) + + if update_key: + # Here we don't expect to have more than one record + # because we can not have multiple projects with the same KEY. + self.update_sequence() + self._update_task_keys() + + return res + + @api.multi + def unlink(self): + for project in self: + sequence = project.task_key_sequence_id + project.task_key_sequence_id = False + sequence.sudo().unlink() + return super(Project, self).unlink() + + @api.model + def name_search(self, name, args=None, operator='ilike', limit=100): + res = super(Project, self).name_search(name, args, operator, limit) + if name: + domain = [ + '|', + ('key', 'ilike', name + '%'), + ('id', 'in', [x[0] for x in res]) + ] + if operator in expression.NEGATIVE_TERM_OPERATORS: + domain = ['&', '!'] + domain[1:] + projects = self.search(domain + (args or []), limit=limit) + return projects.name_get() + else: + return res + + def create_sequence(self): + """ + This method creates ir.sequence fot the current project + :return: Returns create sequence + """ + self.ensure_one() + sequence_data = self._prepare_sequence_data() + sequence = self.env['ir.sequence'].sudo().create(sequence_data) + self.write({'task_key_sequence_id': sequence.id}) + return sequence + + def update_sequence(self): + """ + This method updates existing task sequence + :return: + """ + sequence_data = self._prepare_sequence_data(init=False) + self.task_key_sequence_id.sudo().write(sequence_data) + + def _prepare_sequence_data(self, init=True): + """ + This method prepares data for create/update_sequence methods + :param init: Set to False in case you don't want to set initial values + for number_increment and number_next_actual + """ + values = { + 'name': "%s %s" % ( + _("Project task sequence for project "), self.name + ), + 'implementation': 'standard', + 'code': 'project.task.key.%s' % (self.id,), + 'prefix': "%s-" % (self.key,), + 'use_date_range': False, + } + + if init: + values.update(dict(number_increment=1, number_next_actual=1)) + + return values + + def get_next_task_key(self): + return self.sudo().task_key_sequence_id.next_by_id() + + def generate_project_key(self, text): + if not text: + return '' + + data = text.split(' ') + if len(data) == 1: + return data[0][:3].upper() + + key = [] + for item in data: + key.append(item[0].upper()) + return "".join(key) + + @api.multi + def _update_task_keys(self): + """ + This method will update task keys of the current project. + """ + self.ensure_one() + + reindex_query = """ + UPDATE project_task + SET key = x.key + FROM ( + SELECT t.id, p.key || '-' || split_part(t.key, '-', 2) AS key + FROM project_task t + INNER JOIN project_project p ON t.project_id = p.id + WHERE t.project_id = %s + ) AS x + WHERE project_task.id = x.id; + """ + + self.env.cr.execute(reindex_query, (self.id,)) + self.env['project.task'].invalidate_cache(['key'], self.task_ids.ids) + + @api.model + def _set_default_project_key(self): + """ + This method will be called from the post_init hook in order to set + default values on project.project and + project.task, so we leave those tables nice and clean after module + installation. + :return: + """ + for project in self.with_context(active_test=False).search([ + ('key', '=', False) + ]): + project.key = self.generate_project_key(project.name) + project.create_sequence() + + for task in project.task_ids: + task.key = project.get_next_task_key() diff --git a/project_key/models/project_task.py b/project_key/models/project_task.py new file mode 100644 index 0000000000..40ebc2e83a --- /dev/null +++ b/project_key/models/project_task.py @@ -0,0 +1,109 @@ +# Copyright 2017 - 2018 Modoolar +# License LGPLv3.0 or later (https://www.gnu.org/licenses/lgpl-3.0.en.html). + +from odoo import models, fields, api +from odoo.osv import expression + +TASK_URL = "/web#id=%s&view_type=form&model=project.task&action=%s" + + +class Task(models.Model): + _inherit = 'project.task' + + key = fields.Char( + string='key', + size=20, + required=False, + index=True, + ) + + url = fields.Char( + string='URL', + compute="_compute_task_url", + ) + + _sql_constraints = [ + ("task_key_unique", "UNIQUE(key)", "Task key must be unique!") + ] + + @api.multi + def _compute_task_url(self): + action_id = self.env.ref('project.action_view_task').id + for task in self: + task.url = TASK_URL % (task.id, action_id) + + @api.model + @api.returns('self', lambda value: value.id) + def create(self, vals): + get = self.env.context.get + + project_id = vals.get('project_id', False) + if not project_id: + project_id = get('default_project_id', False) + + if not project_id and get('active_model', False) == 'project.project': + project_id = get('active_id', False) + + if project_id: + project = self.env['project.project'].browse(project_id) + vals['key'] = project.get_next_task_key() + return super(Task, self).create(vals) + + @api.multi + def write(self, vals): + project_id = vals.get('project_id', False) + if not project_id: + return super(Task, self).write(vals) + + project = self.env['project.project'].browse(project_id) + for task in self: + if task.key and task.project_id.id == project.id: + continue + + values = self.prepare_task_for_project_switch(task, project) + super(Task, task).write(values) + + return super(Task, self).write(vals) + + def prepare_task_for_project_switch(self, task, project): + data = { + 'key': project.get_next_task_key(), + 'project_id': project.id + } + + if len(task.child_ids) > 0: + data['child_ids'] = [ + (1, child.id, self.prepare_task_for_project_switch( + child, project + )) + for child in task.child_ids + ] + return data + + @api.model + def name_search(self, name, args=None, operator='ilike', limit=100): + args = args or [] + domain = [] + if name: + domain = [ + '|', + ('key', '=ilike', name + '%'), + ('name', operator, name) + ] + if operator in expression.NEGATIVE_TERM_OPERATORS: + domain = ['&', '!'] + domain[1:] + tasks = self.search(domain + args, limit=limit) + return tasks.name_get() + + @api.multi + def name_get(self): + result = [] + + for record in self: + task_name = [] + if record.key: + task_name.append(record.key) + task_name.append(record.name) + result.append((record.id, " - ".join(task_name))) + + return result diff --git a/project_key/static/description/icon.png b/project_key/static/description/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..3a0328b516c4980e8e44cdb63fd945757ddd132d GIT binary patch literal 9455 zcmW++2RxMjAAjx~&dlBk9S+%}OXg)AGE&Cb*&}d0jUxM@u(PQx^-s)697TX`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e2ot~6%7mLt5t8Vwi^Jy7|jWXqa3amOIoRb zOr}WVFP--DsS`1WpN%~)t3R!arKF^Q$e12KEqU36AWwnCBICpH4XCsfnyrHr>$I$4 z!DpKX$OKLWarN7nv@!uIA+~RNO)l$$w}p(;b>mx8pwYvu;dD_unryX_NhT8*Tj>BTrTTL&!?O+%Rv;b?B??gSzdp?6Uug9{ zd@V08Z$BdI?fpoCS$)t4mg4rT8Q_I}h`0d-vYZ^|dOB*Q^S|xqTV*vIg?@fVFSmMpaw0qtTRbx} z({Pg?#{2`sc9)M5N$*N|4;^t$+QP?#mov zGVC@I*lBVrOU-%2y!7%)fAKjpEFsgQc4{amtiHb95KQEwvf<(3T<9-Zm$xIew#P22 zc2Ix|App^>v6(3L_MCU0d3W##AB0M~3D00EWoKZqsJYT(#@w$Y_H7G22M~ApVFTRHMI_3be)Lkn#0F*V8Pq zc}`Cjy$bE;FJ6H7p=0y#R>`}-m4(0F>%@P|?7fx{=R^uFdISRnZ2W_xQhD{YuR3t< z{6yxu=4~JkeA;|(J6_nv#>Nvs&FuLA&PW^he@t(UwFFE8)|a!R{`E`K`i^ZnyE4$k z;(749Ix|oi$c3QbEJ3b~D_kQsPz~fIUKym($a_7dJ?o+40*OLl^{=&oq$<#Q(yyrp z{J-FAniyAw9tPbe&IhQ|a`DqFTVQGQ&Gq3!C2==4x{6EJwiPZ8zub-iXoUtkJiG{} zPaR&}_fn8_z~(=;5lD-aPWD3z8PZS@AaUiomF!G8I}Mf>e~0g#BelA-5#`cj;O5>N Xviia!U7SGha1wx#SCgwmn*{w2TRX*I literal 0 HcmV?d00001 diff --git a/project_key/tests/__init__.py b/project_key/tests/__init__.py new file mode 100644 index 0000000000..54a206ecf1 --- /dev/null +++ b/project_key/tests/__init__.py @@ -0,0 +1,3 @@ +from . import test_project +from . import test_task +from . import test_controller diff --git a/project_key/tests/test_common.py b/project_key/tests/test_common.py new file mode 100644 index 0000000000..6af178787d --- /dev/null +++ b/project_key/tests/test_common.py @@ -0,0 +1,55 @@ +# Copyright 2017 - 2018 Modoolar +# License LGPLv3.0 or later (https://www.gnu.org/licenses/lgpl-3.0.en.html). + +from odoo.tests.common import TransactionCase, HttpCase + + +class TestCommon(TransactionCase): + + def setUp(self): + super(TestCommon, self).setUp() + + self.Project = self.env['project.project'] + self.Task = self.env['project.task'] + + self.project_action = self.ref("project.open_view_project_all_config") + self.task_action = self.ref("project.action_view_task") + + self.project_1 = self.Project.create({'name': 'OCA'}) + self.project_2 = self.Project.create({'name': 'Odoo', 'key': 'ODOO'}) + self.project_3 = self.Project.create({'name': 'Python'}) + + self.task11 = self.Task.create({ + 'name': '1', + 'project_id': self.project_1.id, + }) + + self.task12 = self.Task.create({ + 'name': '2', + 'parent_id': self.task11.id, + 'project_id': self.project_1.id, + }) + + self.task21 = self.Task.create({ + 'name': '3', + 'project_id': self.project_2.id, + }) + + self.task30 = self.Task.create({ + 'name': '3', + }) + + def get_record_url(self, record, model, action): + return "/web#id=%s&view_type=form&model=%s&action=%s" % ( + record.id, model, action + ) + + def get_task_url(self, task): + return self.get_record_url(task, task._name, self.task_action) + + def get_project_url(self, project): + return self.get_record_url(project, project._name, self.project_action) + + +class HttpTestCommon(HttpCase, TestCommon): + pass diff --git a/project_key/tests/test_controller.py b/project_key/tests/test_controller.py new file mode 100644 index 0000000000..1bd9e679b9 --- /dev/null +++ b/project_key/tests/test_controller.py @@ -0,0 +1,36 @@ +# Copyright 2017 - 2018 Modoolar +# License LGPLv3.0 or later (https://www.gnu.org/licenses/lgpl-3.0.en.html). + +from mock import patch +from odoo import http +from odoo.addons.project_key.controllers.main import ProjectBrowser +from .test_common import HttpTestCommon + + +class TestController(HttpTestCommon): + def setUp(self): + super(TestController, self).setUp() + + def test_01_project_browse(self): + with patch.object(http, 'request') as request: + request.env = self.env + controller = ProjectBrowser() + response = controller.open_project(self.project_1.key) + + self.assertEqual(response.status_code, 301) + self.assertEqual( + response.location, + self.get_project_url(self.project_1) + ) + + def test_02_task_browse(self): + with patch.object(http, 'request') as request: + request.env = self.env + controller = ProjectBrowser() + response = controller.open_task(self.task11.key) + + self.assertEqual(response.status_code, 301) + self.assertEqual( + response.location, + self.get_task_url(self.task11) + ) diff --git a/project_key/tests/test_project.py b/project_key/tests/test_project.py new file mode 100644 index 0000000000..39af3c35c1 --- /dev/null +++ b/project_key/tests/test_project.py @@ -0,0 +1,60 @@ +# Copyright 2017 - 2018 Modoolar +# License LGPLv3.0 or later (https://www.gnu.org/licenses/lgpl-3.0.en.html). + +from .test_common import TestCommon + + +class TestProject(TestCommon): + + def test_01_key(self): + self.assertEqual(self.project_1.key, "OCA") + self.assertEqual(self.project_2.key, "ODOO") + self.assertEqual(self.project_3.key, "PYT") + + def test_02_change_key(self): + self.project_1.key = "XXX" + + self.assertEqual(self.task11.key, "XXX-1") + self.assertEqual(self.task12.key, "XXX-2") + + def test_03_name_search(self): + + projects = self.Project.name_search('ODO') + self.assertEqual(len(projects), 1) + + non_odoo_projects = [ + x[0] for x in self.Project.name_search("ODO", operator="not ilike") + ] + + odoo_projects = self.Project.browse(non_odoo_projects).filtered( + lambda x: x.id == self.project_2.id + ) + + self.assertEqual(len(odoo_projects), 0) + + def test_04_name_search_empty(self): + projects = self.Project.name_search('') + self.assertGreater(len(projects), 0) + + def test_05_name_onchange(self): + project = self.Project.new({'name': 'Software Development'}) + project._onchange_project_name() + self.assertEqual(project.key, 'SD') + + def test_06_name_onchange(self): + project = self.Project.new({}) + project._onchange_project_name() + self.assertEqual(project.key, '') + + def test_07_delete(self): + self.project_1.task_ids.unlink() + self.project_1.unlink() + + self.project_2.task_ids.unlink() + self.project_2.unlink() + + self.project_3.unlink() + + def test_08_generate_empty_project_key(self): + empty_key = self.Project.generate_project_key(False) + self.assertEqual(empty_key, '') diff --git a/project_key/tests/test_task.py b/project_key/tests/test_task.py new file mode 100644 index 0000000000..a9db4aaec9 --- /dev/null +++ b/project_key/tests/test_task.py @@ -0,0 +1,53 @@ +# Copyright 2017 - 2018 Modoolar +# License LGPLv3.0 or later (https://www.gnu.org/licenses/lgpl-3.0.en.html). + +from .test_common import TestCommon + + +class TestTask(TestCommon): + + def test_01_key(self): + self.assertEqual(self.task11.key, "OCA-1") + self.assertEqual(self.task12.key, "OCA-2") + self.assertEqual(self.task21.key, "ODOO-1") + self.assertEqual(self.task30.key, False) + + def test_02_compute_task_url(self): + task_url = self.get_task_url(self.task11) + + self.task11._compute_task_url() + self.assertEqual(self.task11.url, task_url) + + def test_03_create_task_project_in_context(self): + self.Task.with_context( + active_model='project.project', + active_id=self.project_1.id, + ).create({'name': '4'}) + + def test_04_no_switch_project(self): + self.task11.write({'project_id': self.project_1.id}) + self.assertEqual(self.task11.key, 'OCA-1') + self.assertEqual(self.task12.key, 'OCA-2') + + def test_05_switch_project(self): + self.task11.write({'project_id': self.project_2.id}) + self.assertEqual(self.task11.key, 'ODOO-2') + self.assertEqual(self.task12.key, 'ODOO-3') + + def test_06_name_search(self): + oca_tasks = self.Task.name_search("OCA") + self.assertEqual(len(oca_tasks), 2) + + non_oca_task_ids = [ + x[0] for x in self.Task.name_search("OCA", operator="not ilike") + ] + + oca_tasks = self.Task.browse(non_oca_task_ids).filtered( + lambda x: x.project_id.id == self.project_1.id + ) + + self.assertEqual(len(oca_tasks), 0) + + def test_07_name_search_empty(self): + tasks = self.Task.name_search('') + self.assertGreater(len(tasks), 0) diff --git a/project_key/views/project_key_views.xml b/project_key/views/project_key_views.xml new file mode 100644 index 0000000000..4ac60cc359 --- /dev/null +++ b/project_key/views/project_key_views.xml @@ -0,0 +1,116 @@ + + + + + project.edit.project.inherited + project.project + + + + + + + + + + project.project.tree + project.project + + + + + + + + + + project.project.select + project.project + + + + ['|',('name','ilike',self),('key','ilike',self)] + + + + + + project.task.form.key + project.task + + + + + + + + + + project.task.tree + project.task + + + + + + + + + + + project.task.search.key + project.task + + + + ['|',('name','ilike',self),('key','ilike',self)] + + + + + + project.task.kanban.key + project.task + + + + + + + + + + + + + + + + project.project.view.form.simplified + project.project + + +
+ +
+
+
+ + + project.project.kanban + project.project + + + + + + + + - + + + +
From 5c4b4f70f1398ba30fa2be41b0b089b2e3392940 Mon Sep 17 00:00:00 2001 From: oca-travis Date: Mon, 18 Jun 2018 03:32:14 +0000 Subject: [PATCH 02/46] [UPD] Update project_key.pot --- project_key/i18n/project_key.pot | 57 ++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 project_key/i18n/project_key.pot diff --git a/project_key/i18n/project_key.pot b/project_key/i18n/project_key.pot new file mode 100644 index 0000000000..7a61331e94 --- /dev/null +++ b/project_key/i18n/project_key.pot @@ -0,0 +1,57 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * project_key +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 11.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: project_key +#: model:ir.model.fields,field_description:project_key.field_project_project_task_key_sequence_id +msgid "Key Sequence" +msgstr "" + +#. module: project_key +#: model:ir.model,name:project_key.model_project_project +msgid "Project" +msgstr "" + +#. module: project_key +#: sql_constraint:project.project:0 +msgid "Project key must be unique" +msgstr "" + +#. module: project_key +#: code:addons/project_key/models/project_project.py:116 +#, python-format +msgid "Project task sequence for project " +msgstr "" + +#. module: project_key +#: model:ir.model,name:project_key.model_project_task +msgid "Task" +msgstr "" + +#. module: project_key +#: sql_constraint:project.task:0 +msgid "Task key must be unique!" +msgstr "" + +#. module: project_key +#: model:ir.model.fields,field_description:project_key.field_project_task_url +msgid "URL" +msgstr "" + +#. module: project_key +#: model:ir.model.fields,field_description:project_key.field_project_project_key +#: model:ir.model.fields,field_description:project_key.field_project_task_key +msgid "key" +msgstr "" + From dfd4920fdf07d4aefcd854f55f1e3c8814824f60 Mon Sep 17 00:00:00 2001 From: Dennis Sluijk Date: Thu, 6 Sep 2018 09:48:07 +0200 Subject: [PATCH 03/46] [FIX] Copying projects --- project_key/models/project_project.py | 1 + 1 file changed, 1 insertion(+) diff --git a/project_key/models/project_project.py b/project_key/models/project_project.py index 769297f230..e2c71e8e57 100644 --- a/project_key/models/project_project.py +++ b/project_key/models/project_project.py @@ -19,6 +19,7 @@ class Project(models.Model): size=10, required=False, index=True, + copy=False ) _sql_constraints = [ From 96637af34038f2cf84ceea59eaf2e24ae1ed2754 Mon Sep 17 00:00:00 2001 From: oca-travis Date: Thu, 6 Sep 2018 08:43:03 +0000 Subject: [PATCH 04/46] [UPD] Update project_key.pot --- project_key/i18n/project_key.pot | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project_key/i18n/project_key.pot b/project_key/i18n/project_key.pot index 7a61331e94..33edcd87e3 100644 --- a/project_key/i18n/project_key.pot +++ b/project_key/i18n/project_key.pot @@ -29,7 +29,7 @@ msgid "Project key must be unique" msgstr "" #. module: project_key -#: code:addons/project_key/models/project_project.py:116 +#: code:addons/project_key/models/project_project.py:117 #, python-format msgid "Project task sequence for project " msgstr "" From 207f8302ced95d20dbf2f7183b2698cbc41f2389 Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Mon, 19 Nov 2018 16:10:12 +0200 Subject: [PATCH 05/46] [MIG] project_key: Migration to 12.0 --- project_key/README.rst | 65 ++- project_key/__init__.py | 2 + project_key/__manifest__.py | 4 +- project_key/controllers/__init__.py | 2 + project_key/models/__init__.py | 2 + project_key/models/project_project.py | 2 +- project_key/readme/CONTRIBUTORS.rst | 3 + project_key/readme/DESCRIPTION.rst | 1 + project_key/readme/USAGE.rst | 34 ++ project_key/static/description/index.html | 457 ++++++++++++++++++++++ project_key/tests/__init__.py | 2 + 11 files changed, 559 insertions(+), 15 deletions(-) create mode 100644 project_key/readme/CONTRIBUTORS.rst create mode 100644 project_key/readme/DESCRIPTION.rst create mode 100644 project_key/readme/USAGE.rst create mode 100644 project_key/static/description/index.html diff --git a/project_key/README.rst b/project_key/README.rst index 32799cf683..ae225bbb9b 100644 --- a/project_key/README.rst +++ b/project_key/README.rst @@ -1,13 +1,36 @@ -.. image:: https://www.gnu.org/graphics/lgplv3-147x51.png - :target: https://www.gnu.org/licenses/lgpl-3.0.en.html - :alt: License: LGPL-v3 - -============ +=========== Project key -============ +=========== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png + :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html + :alt: License: LGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fproject-lightgray.png?logo=github + :target: https://github.com/OCA/project/tree/12.0/project_key + :alt: OCA/project +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/project-12-0/project-12-0-project_key + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/140/12.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| This module provides functionality to uniquely identify projects and tasks by simple ``key`` field. +**Table of contents** + +.. contents:: + :local: Usage ===== @@ -47,26 +70,44 @@ In browser address bar: #. Navigate to your project by entering following url: http://<>/projects/PROJECT-KEY #. Navigate to your task by entering following url: http://<>/tasks/TASK-KEY +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + Credits ======= +Authors +~~~~~~~ + +* Modoolar + Contributors ------------- +~~~~~~~~~~~~ * Petar Najman * Sladjan Kantar +* Alexey Pelykh + +Maintainers +~~~~~~~~~~~ -Maintainer ----------- +This module is maintained by the OCA. .. image:: https://odoo-community.org/logo.png :alt: Odoo Community Association :target: https://odoo-community.org -This module is maintained by the OCA. - OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. -To contribute to this module, please visit http://odoo-community.org. +This module is part of the `OCA/project `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/project_key/__init__.py b/project_key/__init__.py index 3d05e191a9..2474bef694 100644 --- a/project_key/__init__.py +++ b/project_key/__init__.py @@ -1,3 +1,5 @@ +# License LGPLv3.0 or later (https://www.gnu.org/licenses/lgpl-3.0.en.html). + from . import models from . import controllers from .hooks import post_init_hook diff --git a/project_key/__manifest__.py b/project_key/__manifest__.py index f7fa541376..bde4a3aa70 100644 --- a/project_key/__manifest__.py +++ b/project_key/__manifest__.py @@ -3,9 +3,9 @@ { "name": "Project key", - "summary": "Module decorates projects and tasks with ``key`` field", + "summary": "Module decorates projects and tasks with Project Key", "category": "Project", - "version": "11.0.1.0.0", + "version": "12.0.1.0.0", "license": "LGPL-3", "author": "Modoolar, Odoo Community Association (OCA)", "website": "https://github.com/OCA/project/", diff --git a/project_key/controllers/__init__.py b/project_key/controllers/__init__.py index 12a7e529b6..4e80e131bf 100644 --- a/project_key/controllers/__init__.py +++ b/project_key/controllers/__init__.py @@ -1 +1,3 @@ +# License LGPLv3.0 or later (https://www.gnu.org/licenses/lgpl-3.0.en.html). + from . import main diff --git a/project_key/models/__init__.py b/project_key/models/__init__.py index 2128188969..443c6f46cb 100644 --- a/project_key/models/__init__.py +++ b/project_key/models/__init__.py @@ -1,2 +1,4 @@ +# License LGPLv3.0 or later (https://www.gnu.org/licenses/lgpl-3.0.en.html). + from . import project_project from . import project_task diff --git a/project_key/models/project_project.py b/project_key/models/project_project.py index e2c71e8e57..c2e19ff271 100644 --- a/project_key/models/project_project.py +++ b/project_key/models/project_project.py @@ -15,7 +15,7 @@ class Project(models.Model): ) key = fields.Char( - string='key', + string='Key', size=10, required=False, index=True, diff --git a/project_key/readme/CONTRIBUTORS.rst b/project_key/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..eae0135eb9 --- /dev/null +++ b/project_key/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* Petar Najman +* Sladjan Kantar +* Alexey Pelykh diff --git a/project_key/readme/DESCRIPTION.rst b/project_key/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..9b7adc76ca --- /dev/null +++ b/project_key/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module provides functionality to uniquely identify projects and tasks by simple ``key`` field. diff --git a/project_key/readme/USAGE.rst b/project_key/readme/USAGE.rst new file mode 100644 index 0000000000..206ca8b2eb --- /dev/null +++ b/project_key/readme/USAGE.rst @@ -0,0 +1,34 @@ +To use this module functionality you just need to: + +On ``project.project`` level: + +In Kanban View: + +#. Go to Project > Dashboard +#. Create +#. Enter project name and use auto generated key or simply override value by entering your own key value. + +In Tree View: + +#. Go to Project > Configuration > Projects +#. Create +#. Enter project name and use auto generated key or simply override value by entering your own key value. + +In form View: + +#. Go to Project > Dashboard +#. Open the projects settings +#. Modify the "key" value +#. After modifying project key the key of any existing tasks related to that project will be updated automatically. + +When you create a project, under the hood a ir.sequence record gets creted with prefix: ``-``. + +On ``project.task`` level: + +#. Actually there is nothing to be done here +#. Task keys are auto generated based on project key value with per project auto incremented number (i.e. PA-1, PA-2, etc) + +In browser address bar: + +#. Navigate to your project by entering following url: http://<>/projects/PROJECT-KEY +#. Navigate to your task by entering following url: http://<>/tasks/TASK-KEY diff --git a/project_key/static/description/index.html b/project_key/static/description/index.html new file mode 100644 index 0000000000..e747d61971 --- /dev/null +++ b/project_key/static/description/index.html @@ -0,0 +1,457 @@ + + + + + + +Project key + + + +
+

Project key

+ + +

Beta License: LGPL-3 OCA/project Translate me on Weblate Try me on Runbot

+

This module provides functionality to uniquely identify projects and tasks by simple key field.

+

Table of contents

+ +
+

Usage

+

To use this module functionality you just need to:

+

On project.project level:

+

In Kanban View:

+
    +
  1. Go to Project > Dashboard
  2. +
  3. Create
  4. +
  5. Enter project name and use auto generated key or simply override value by entering your own key value.
  6. +
+

In Tree View:

+
    +
  1. Go to Project > Configuration > Projects
  2. +
  3. Create
  4. +
  5. Enter project name and use auto generated key or simply override value by entering your own key value.
  6. +
+

In form View:

+
    +
  1. Go to Project > Dashboard
  2. +
  3. Open the projects settings
  4. +
  5. Modify the “key” value
  6. +
  7. After modifying project key the key of any existing tasks related to that project will be updated automatically.
  8. +
+

When you create a project, under the hood a ir.sequence record gets creted with prefix: <project-key>-.

+

On project.task level:

+
    +
  1. Actually there is nothing to be done here
  2. +
  3. Task keys are auto generated based on project key value with per project auto incremented number (i.e. PA-1, PA-2, etc)
  4. +
+

In browser address bar:

+
    +
  1. Navigate to your project by entering following url: http://<<your-domain>>/projects/PROJECT-KEY
  2. +
  3. Navigate to your task by entering following url: http://<<your-domain>>/tasks/TASK-KEY
  4. +
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Modoolar
  • +
+
+ +
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/project project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/project_key/tests/__init__.py b/project_key/tests/__init__.py index 54a206ecf1..31f0029620 100644 --- a/project_key/tests/__init__.py +++ b/project_key/tests/__init__.py @@ -1,3 +1,5 @@ +# License LGPLv3.0 or later (https://www.gnu.org/licenses/lgpl-3.0.en.html). + from . import test_project from . import test_task from . import test_controller From 6fbc1027ad54d0e284bf99ccadaa33bf55ac018b Mon Sep 17 00:00:00 2001 From: oca-travis Date: Sat, 24 Nov 2018 18:42:47 +0000 Subject: [PATCH 06/46] [UPD] Update project_key.pot --- project_key/i18n/project_key.pot | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/project_key/i18n/project_key.pot b/project_key/i18n/project_key.pot index 33edcd87e3..e8727615d7 100644 --- a/project_key/i18n/project_key.pot +++ b/project_key/i18n/project_key.pot @@ -4,7 +4,7 @@ # msgid "" msgstr "" -"Project-Id-Version: Odoo Server 11.0\n" +"Project-Id-Version: Odoo Server 12.0\n" "Report-Msgid-Bugs-To: \n" "Last-Translator: <>\n" "Language-Team: \n" @@ -14,7 +14,12 @@ msgstr "" "Plural-Forms: \n" #. module: project_key -#: model:ir.model.fields,field_description:project_key.field_project_project_task_key_sequence_id +#: model:ir.model.fields,field_description:project_key.field_project_project__key +msgid "Key" +msgstr "" + +#. module: project_key +#: model:ir.model.fields,field_description:project_key.field_project_project__task_key_sequence_id msgid "Key Sequence" msgstr "" @@ -45,13 +50,12 @@ msgid "Task key must be unique!" msgstr "" #. module: project_key -#: model:ir.model.fields,field_description:project_key.field_project_task_url +#: model:ir.model.fields,field_description:project_key.field_project_task__url msgid "URL" msgstr "" #. module: project_key -#: model:ir.model.fields,field_description:project_key.field_project_project_key -#: model:ir.model.fields,field_description:project_key.field_project_task_key +#: model:ir.model.fields,field_description:project_key.field_project_task__key msgid "key" msgstr "" From e3fa3b7468a28ee4a6314bbd6a4715af08ab023e Mon Sep 17 00:00:00 2001 From: Alexey Pelykh Date: Mon, 26 Nov 2018 10:01:40 +0200 Subject: [PATCH 07/46] [IMP] project_key: do not regenerate project key if it's already set --- project_key/models/project_project.py | 3 +++ project_key/tests/test_project.py | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/project_key/models/project_project.py b/project_key/models/project_project.py index c2e19ff271..edf2ac228f 100644 --- a/project_key/models/project_project.py +++ b/project_key/models/project_project.py @@ -30,6 +30,9 @@ class Project(models.Model): @api.onchange('name') def _onchange_project_name(self): for rec in self: + if rec.key: + continue + if rec.name: rec.key = self.generate_project_key(rec.name) else: diff --git a/project_key/tests/test_project.py b/project_key/tests/test_project.py index 39af3c35c1..feb80c4e63 100644 --- a/project_key/tests/test_project.py +++ b/project_key/tests/test_project.py @@ -58,3 +58,11 @@ def test_07_delete(self): def test_08_generate_empty_project_key(self): empty_key = self.Project.generate_project_key(False) self.assertEqual(empty_key, '') + + def test_09_name_onchange_with_key(self): + project = self.Project.new({ + 'name': 'Software Development', + 'key': 'TEST', + }) + project._onchange_project_name() + self.assertEqual(project.key, 'TEST') From 3929b24e0cf9c4905f445c7eeaca0e464406559f Mon Sep 17 00:00:00 2001 From: oca-travis Date: Mon, 26 Nov 2018 14:52:34 +0000 Subject: [PATCH 08/46] [UPD] Update project_key.pot --- project_key/i18n/project_key.pot | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project_key/i18n/project_key.pot b/project_key/i18n/project_key.pot index e8727615d7..c5338485b0 100644 --- a/project_key/i18n/project_key.pot +++ b/project_key/i18n/project_key.pot @@ -34,7 +34,7 @@ msgid "Project key must be unique" msgstr "" #. module: project_key -#: code:addons/project_key/models/project_project.py:117 +#: code:addons/project_key/models/project_project.py:120 #, python-format msgid "Project task sequence for project " msgstr "" From 70daad95acd008fca17b46b5172c139bc7b8ebfb Mon Sep 17 00:00:00 2001 From: tbaden Date: Tue, 30 Apr 2019 18:40:15 +0200 Subject: [PATCH 09/46] [FIX][12.0] project_key relative path --- project_key/tests/test_controller.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project_key/tests/test_controller.py b/project_key/tests/test_controller.py index 1bd9e679b9..fc5f24538c 100644 --- a/project_key/tests/test_controller.py +++ b/project_key/tests/test_controller.py @@ -3,7 +3,7 @@ from mock import patch from odoo import http -from odoo.addons.project_key.controllers.main import ProjectBrowser +from ..controllers.main import ProjectBrowser from .test_common import HttpTestCommon From e45c5afb48a55e92c085220c3eac9e7f263c7ec5 Mon Sep 17 00:00:00 2001 From: ernesto Date: Tue, 21 May 2019 19:35:25 -0400 Subject: [PATCH 10/46] project_key: add test context key --- project_key/hooks.py | 4 ---- project_key/models/project_project.py | 8 ++++++++ project_key/tests/test_common.py | 6 ++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/project_key/hooks.py b/project_key/hooks.py index 4ff17461dd..379d672c36 100644 --- a/project_key/hooks.py +++ b/project_key/hooks.py @@ -6,7 +6,3 @@ def post_init_hook(cr, registry): from odoo import api, SUPERUSER_ID env = api.Environment(cr, SUPERUSER_ID, {}) env['project.project']._set_default_project_key() - cr.execute( - "ALTER TABLE project_project ALTER COLUMN key SET NOT NULL", - log_exceptions=False - ) diff --git a/project_key/models/project_project.py b/project_key/models/project_project.py index edf2ac228f..217d0047e7 100644 --- a/project_key/models/project_project.py +++ b/project_key/models/project_project.py @@ -3,6 +3,7 @@ from odoo import models, fields, api, _ from odoo.osv import expression +from odoo.tools import config class Project(models.Model): @@ -131,9 +132,16 @@ def _prepare_sequence_data(self, init=True): return values def get_next_task_key(self): + test_project_key = self.env.context.get('test_project_key') + if config['test_enable'] and not test_project_key: + return False return self.sudo().task_key_sequence_id.next_by_id() def generate_project_key(self, text): + test_project_key = self.env.context.get('test_project_key') + if config['test_enable'] and not test_project_key: + return False + if not text: return '' diff --git a/project_key/tests/test_common.py b/project_key/tests/test_common.py index 6af178787d..53eaadefd2 100644 --- a/project_key/tests/test_common.py +++ b/project_key/tests/test_common.py @@ -9,8 +9,10 @@ class TestCommon(TransactionCase): def setUp(self): super(TestCommon, self).setUp() - self.Project = self.env['project.project'] - self.Task = self.env['project.task'] + self.Project = self.env['project.project'].with_context( + test_project_key=True) + self.Task = self.env['project.task'].with_context( + test_project_key=True) self.project_action = self.ref("project.open_view_project_all_config") self.task_action = self.ref("project.action_view_task") From 28d5c3063da75c105cf76b038644d0f5818ed23c Mon Sep 17 00:00:00 2001 From: oca-travis Date: Wed, 22 May 2019 07:45:21 +0000 Subject: [PATCH 11/46] [UPD] Update project_key.pot --- project_key/i18n/project_key.pot | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project_key/i18n/project_key.pot b/project_key/i18n/project_key.pot index c5338485b0..1202f4aea0 100644 --- a/project_key/i18n/project_key.pot +++ b/project_key/i18n/project_key.pot @@ -34,7 +34,7 @@ msgid "Project key must be unique" msgstr "" #. module: project_key -#: code:addons/project_key/models/project_project.py:120 +#: code:addons/project_key/models/project_project.py:121 #, python-format msgid "Project task sequence for project " msgstr "" From fbe3b961809551d5cb87e1d271863acf0fef7c8a Mon Sep 17 00:00:00 2001 From: Maria Sparenberg Date: Tue, 9 Jul 2019 07:15:09 +0000 Subject: [PATCH 12/46] Added translation using Weblate (German) --- project_key/i18n/de.po | 61 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 project_key/i18n/de.po diff --git a/project_key/i18n/de.po b/project_key/i18n/de.po new file mode 100644 index 0000000000..ba6a4922ba --- /dev/null +++ b/project_key/i18n/de.po @@ -0,0 +1,61 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * project_key +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: Automatically generated\n" +"Language-Team: none\n" +"Language: de\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" + +#. module: project_key +#: model:ir.model.fields,field_description:project_key.field_project_project__key +msgid "Key" +msgstr "" + +#. module: project_key +#: model:ir.model.fields,field_description:project_key.field_project_project__task_key_sequence_id +msgid "Key Sequence" +msgstr "" + +#. module: project_key +#: model:ir.model,name:project_key.model_project_project +msgid "Project" +msgstr "" + +#. module: project_key +#: sql_constraint:project.project:0 +msgid "Project key must be unique" +msgstr "" + +#. module: project_key +#: code:addons/project_key/models/project_project.py:121 +#, python-format +msgid "Project task sequence for project " +msgstr "" + +#. module: project_key +#: model:ir.model,name:project_key.model_project_task +msgid "Task" +msgstr "" + +#. module: project_key +#: sql_constraint:project.task:0 +msgid "Task key must be unique!" +msgstr "" + +#. module: project_key +#: model:ir.model.fields,field_description:project_key.field_project_task__url +msgid "URL" +msgstr "" + +#. module: project_key +#: model:ir.model.fields,field_description:project_key.field_project_task__key +msgid "key" +msgstr "" From 3a717508647a58ba5a8580f0fd97d0de7336514b Mon Sep 17 00:00:00 2001 From: Maria Sparenberg Date: Tue, 9 Jul 2019 11:06:42 +0000 Subject: [PATCH 13/46] Translated using Weblate (German) Currently translated at 100.0% (9 of 9 strings) Translation: project-12.0/project-12.0-project_key Translate-URL: https://translation.odoo-community.org/projects/project-12-0/project-12-0-project_key/de/ --- project_key/i18n/de.po | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/project_key/i18n/de.po b/project_key/i18n/de.po index ba6a4922ba..f7f6888a86 100644 --- a/project_key/i18n/de.po +++ b/project_key/i18n/de.po @@ -6,56 +6,58 @@ msgid "" msgstr "" "Project-Id-Version: Odoo Server 12.0\n" "Report-Msgid-Bugs-To: \n" -"Last-Translator: Automatically generated\n" +"PO-Revision-Date: 2019-07-09 13:43+0000\n" +"Last-Translator: Maria Sparenberg \n" "Language-Team: none\n" "Language: de\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: \n" "Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 3.7.1\n" #. module: project_key #: model:ir.model.fields,field_description:project_key.field_project_project__key msgid "Key" -msgstr "" +msgstr "Nummerierungsmuster" #. module: project_key #: model:ir.model.fields,field_description:project_key.field_project_project__task_key_sequence_id msgid "Key Sequence" -msgstr "" +msgstr "Musterfolge" #. module: project_key #: model:ir.model,name:project_key.model_project_project msgid "Project" -msgstr "" +msgstr "Projekt" #. module: project_key #: sql_constraint:project.project:0 msgid "Project key must be unique" -msgstr "" +msgstr "Das Nummerierungsmuster für Projekte muss eindeutig sein" #. module: project_key #: code:addons/project_key/models/project_project.py:121 #, python-format msgid "Project task sequence for project " -msgstr "" +msgstr "Aufgabennummerierung für Projekt " #. module: project_key #: model:ir.model,name:project_key.model_project_task msgid "Task" -msgstr "" +msgstr "Aufgabe" #. module: project_key #: sql_constraint:project.task:0 msgid "Task key must be unique!" -msgstr "" +msgstr "Aufgabennummerierung muss eindeutig sein!" #. module: project_key #: model:ir.model.fields,field_description:project_key.field_project_task__url msgid "URL" -msgstr "" +msgstr "URL" #. module: project_key #: model:ir.model.fields,field_description:project_key.field_project_task__key msgid "key" -msgstr "" +msgstr "Nummer" From 17e2b5f175cc387d24983b409e3e6e41a304afef Mon Sep 17 00:00:00 2001 From: Maria Sparenberg Date: Fri, 12 Jul 2019 13:36:31 +0000 Subject: [PATCH 14/46] Translated using Weblate (German) Currently translated at 100.0% (9 of 9 strings) Translation: project-12.0/project-12.0-project_key Translate-URL: https://translation.odoo-community.org/projects/project-12-0/project-12-0-project_key/de/ --- project_key/i18n/de.po | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/project_key/i18n/de.po b/project_key/i18n/de.po index f7f6888a86..3f506c87e9 100644 --- a/project_key/i18n/de.po +++ b/project_key/i18n/de.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: Odoo Server 12.0\n" "Report-Msgid-Bugs-To: \n" -"PO-Revision-Date: 2019-07-09 13:43+0000\n" +"PO-Revision-Date: 2019-07-12 15:43+0000\n" "Last-Translator: Maria Sparenberg \n" "Language-Team: none\n" "Language: de\n" @@ -34,7 +34,7 @@ msgstr "Projekt" #. module: project_key #: sql_constraint:project.project:0 msgid "Project key must be unique" -msgstr "Das Nummerierungsmuster für Projekte muss eindeutig sein" +msgstr "Das Nummerierungsmuster für Projekte muss eindeutig sein." #. module: project_key #: code:addons/project_key/models/project_project.py:121 From 574295e32a6b53e8e69e1aa609353293e1c0bcc6 Mon Sep 17 00:00:00 2001 From: OCA-git-bot Date: Mon, 29 Jul 2019 03:29:12 +0000 Subject: [PATCH 15/46] [UPD] README.rst --- project_key/static/description/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project_key/static/description/index.html b/project_key/static/description/index.html index e747d61971..9d2a8f564f 100644 --- a/project_key/static/description/index.html +++ b/project_key/static/description/index.html @@ -3,7 +3,7 @@ - + Project key