Skip to content

Commit

Permalink
[MIG] project_task_code: Migration to 12.0 (fix)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-pelykh authored and Yoshiro009 committed Jan 27, 2021
1 parent 62e745f commit dbb6a69
Show file tree
Hide file tree
Showing 15 changed files with 592 additions and 89 deletions.
73 changes: 52 additions & 21 deletions project_task_code/README.rst
Original file line number Diff line number Diff line change
@@ -1,12 +1,36 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3

=========================
Sequential code for tasks
Sequential Code for Tasks
=========================

* This module adds a sequential code for tasks.
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! 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-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-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_task_code
: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_task_code
: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 adds a sequential code for tasks.

**Table of contents**

.. contents::
:local:

Configuration
=============
Expand All @@ -26,43 +50,50 @@ To use this module, you need to:
new code saving it.
#. If you duplicate a task, you will get a new code for the new task.


.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/140/12.0

Bug Tracker
===========

Bugs are tracked on `GitHub Issues
<https://github.com/OCA/project/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.
Bugs are tracked on `GitHub Issues <https://github.com/OCA/project/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 <https://github.com/OCA/project/issues/new?body=module:%20project_task_code%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Credits
=======

Authors
~~~~~~~

* OdooMRP team
* AvanzOSC
* Tecnativa

Contributors
------------
~~~~~~~~~~~~

* Oihane Crucelaegui <[email protected]>
* Pedro M. Baeza <[email protected]>
* Ana Juaristi <[email protected]>
* Vicent Cubells <[email protected]>
* Rodrigo Ferreira <[email protected]>
* Damien Bouvy <[email protected]>
* Alexey Pelykh <[email protected]>

Maintainer
----------
Maintainers
~~~~~~~~~~~

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 <https://github.com/OCA/project/tree/12.0/project_task_code>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
32 changes: 2 additions & 30 deletions project_task_code/__init__.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,5 @@
# Copyright 2016 Tecnativa <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import models
from odoo import api, SUPERUSER_ID


def create_code_equal_to_id(cr):
"""
With this pre-init-hook we want to avoid error when creating the UNIQUE
code constraint when the module is installed and before the post-init-hook
is launched.
"""
cr.execute('ALTER TABLE project_task '
'ADD COLUMN code character varying;')
cr.execute('UPDATE project_task '
'SET code = id;')


def assign_old_sequences(cr, registry):
"""
This post-init-hook will update all existing task assigning them the
corresponding sequence code.
"""
env = api.Environment(cr, SUPERUSER_ID, dict())
task_obj = env['project.task']
sequence_obj = env['ir.sequence']
tasks = task_obj.search([], order="id")
for task_id in tasks.ids:
cr.execute('UPDATE project_task '
'SET code = %s '
'WHERE id = %s;',
(sequence_obj.next_by_code('project.task'), task_id,))
from .hooks import pre_init_hook
from .hooks import post_init_hook
38 changes: 16 additions & 22 deletions project_task_code/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,23 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Sequential Code for Tasks",
"version": "12.0.1.1.0",
"category": "Project Management",
"author": "OdooMRP team, "
"AvanzOSC, "
"Tecnativa, "
"Odoo Community Association (OCA)",
"website": "http://www.avanzosc.es",
"license": "AGPL-3",
"contributors": [
"Oihane Crucelaegui <[email protected]>",
"Pedro M. Baeza <[email protected]>",
"Ana Juaristi <[email protected]>",
"Vicent Cubells <[email protected]>",
'name': 'Sequential Code for Tasks',
'version': '12.0.1.0.0',
'category': 'Project Management',
'author': 'OdooMRP team, '
'AvanzOSC, '
'Tecnativa, '
'Odoo Community Association (OCA)',
'website': 'https://github.com/OCA/project',
'license': 'AGPL-3',
'depends': [
'project',
],
"depends": [
"project",
],
"data": [
"data/task_sequence.xml",
"views/project_view.xml",
'data': [
'data/task_sequence.xml',
'views/project_view.xml',
],
'installable': True,
"pre_init_hook": "create_code_equal_to_id",
"post_init_hook": "assign_old_sequences",
'pre_init_hook': 'pre_init_hook',
'post_init_hook': 'post_init_hook',
}
15 changes: 9 additions & 6 deletions project_task_code/data/task_sequence.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo noupdate="1">
<!--
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->

<record id="sequence_task" model="ir.sequence">
<field name="name">Task code</field>
<field name="code">project.task</field>
<field eval="4" name="padding" />
<field name="prefix">T</field>
</record>
<record id="sequence_task" model="ir.sequence">
<field name="name">Task code</field>
<field name="code">project.task</field>
<field eval="4" name="padding" />
<field name="prefix">T</field>
</record>

</odoo>
32 changes: 32 additions & 0 deletions project_task_code/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright 2016 Tecnativa <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, SUPERUSER_ID


def pre_init_hook(cr):
"""
With this pre-init-hook we want to avoid error when creating the UNIQUE
code constraint when the module is installed and before the post-init-hook
is launched.
"""
cr.execute('ALTER TABLE project_task '
'ADD COLUMN code character varying;')
cr.execute('UPDATE project_task '
'SET code = id;')


def post_init_hook(cr, registry):
"""
This post-init-hook will update all existing task assigning them the
corresponding sequence code.
"""
env = api.Environment(cr, SUPERUSER_ID, dict())
task_obj = env['project.task']
sequence_obj = env['ir.sequence']
tasks = task_obj.search([], order="id")
for task_id in tasks.ids:
cr.execute('UPDATE project_task '
'SET code = %s '
'WHERE id = %s;',
(sequence_obj.next_by_code('project.task'), task_id,))
1 change: 0 additions & 1 deletion project_task_code/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# Copyright 2016 Tecnativa <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import project_task
23 changes: 16 additions & 7 deletions project_task_code/models/project_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,37 @@ class ProjectTask(models.Model):
_inherit = 'project.task'

code = fields.Char(
string='Task Number', required=True, default="/", readonly=True)
string='Task Number',
required=True,
default='/',
readonly=True,
)

_sql_constraints = [
('project_task_unique_code', 'UNIQUE (code)',
_('The code must be unique!')),
(
'project_task_unique_code',
'UNIQUE (code)',
_('The code must be unique!')
),
]

@api.model_create_multi
def create(self, vals_list):
for vals in vals_list:
if vals.get('code', '/') == '/':
vals['code'] = self.env['ir.sequence'].next_by_code('project.task')
return super(ProjectTask, self).create(vals_list)
vals['code'] = self.env['ir.sequence'].next_by_code(
'project.task'
)
return super().create(vals)

def copy(self, default=None):
if default is None:
default = {}
default['code'] = self.env['ir.sequence'].next_by_code('project.task')
return super(ProjectTask, self).copy(default)
return super().copy(default)

def name_get(self):
result = super(ProjectTask, self).name_get()
result = super().name_get()
new_result = []

for task in result:
Expand Down
5 changes: 5 additions & 0 deletions project_task_code/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
To change the task code sequence, you must:

#. Activate the developer mode.
#. Go to Settings > Technical > Sequences & Identifiers > Sequences.
#. Click on "Task code" sequence to edit.
7 changes: 7 additions & 0 deletions project_task_code/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
* Oihane Crucelaegui <[email protected]>
* Pedro M. Baeza <[email protected]>
* Ana Juaristi <[email protected]>
* Vicent Cubells <[email protected]>
* Rodrigo Ferreira <[email protected]>
* Damien Bouvy <[email protected]>
* Alexey Pelykh <[email protected]>
1 change: 1 addition & 0 deletions project_task_code/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module adds a sequential code for tasks.
5 changes: 5 additions & 0 deletions project_task_code/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
To use this module, you need to:

#. Go to menu Project > Search > Tasks and create a new task, and you get a
new code saving it.
#. If you duplicate a task, you will get a new code for the new task.
Loading

0 comments on commit dbb6a69

Please sign in to comment.