Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions project_agile/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,16 @@ def post_init_hook(cr, registry):

# Set default project task type to the existing tasks
env['project.task'].sudo()._set_default_task_type_id()
task_type_task = env.ref("project_agile.project_task_type_task")
cr.execute("UPDATE project_task SET type_id=%s WHERE type_id IS NULL;", (task_type_task.id,))

# and set ``type_id`` field to not null
cr.execute("ALTER TABLE project_task ALTER COLUMN type_id SET NOT NULL;")

# Set default task priority to the existing tasks
env['project.task'].sudo()._set_default_task_priority_id()
priority_minor = env.ref("project_agile.project_task_priority_minor")
cr.execute("UPDATE project_task SET priority_id=%s WHERE priority_id IS NULL;", (priority_minor.id,))

# and set ``priority_id`` field to not null
cr.execute(
Expand Down
28 changes: 20 additions & 8 deletions project_key/models/project_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,27 @@ def get_next_task_key(self):
def generate_project_key(self, text):
if not text:
return ''

data = text.split(' ')
data = text.strip().split(' ')
if len(data) == 1:
return data[0][:3].upper()

key = []
for item in data:
key.append(item[0].upper())
return "".join(key)
key = data[0][:3].upper()
else:
key = []
for item in data:
if item and item[0].isalnum():
key.append(item[0].upper())
key = "".join(key)
i = 2
base_key = key
while self._check_key_exists(key):
key = '%s%s' % (base_key, i)
i += 1
return key

def _check_key_exists(self, key):
projects = self.with_context(active_test=False).search([
('key', '=', key)
])
return bool(projects)

@api.multi
def _reindex_task_keys(self):
Expand Down