Skip to content

Commit

Permalink
[14.0][ADD] project_sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
OCA-git-bot authored and Andrea Cattalani committed Apr 10, 2023
1 parent 2f14c71 commit 4072367
Show file tree
Hide file tree
Showing 19 changed files with 320 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ addon | version | maintainers | summary
[project_stage_mgmt](project_stage_mgmt/) | 14.0.1.0.0 | [![DavidJForgeFlow](https://github.com/DavidJForgeFlow.png?size=30px)](https://github.com/DavidJForgeFlow) | Allows to assign and create stages on project creation wizard
[project_stage_state](project_stage_state/) | 14.0.1.1.0 | | Restore State attribute removed from Project Stages in 8.0
[project_status](project_status/) | 14.0.1.0.0 | [![patrickrwilson](https://github.com/patrickrwilson.png?size=30px)](https://github.com/patrickrwilson) | Project Status
[project_stock](project_stock/) | 14.0.1.1.3 | [![victoralmau](https://github.com/victoralmau.png?size=30px)](https://github.com/victoralmau) | Project Stock
[project_stock_product_set](project_stock_product_set/) | 14.0.1.0.1 | [![victoralmau](https://github.com/victoralmau.png?size=30px)](https://github.com/victoralmau) | Project Stock Product Set
[project_stock](project_stock/) | 14.0.1.1.4 | [![victoralmau](https://github.com/victoralmau.png?size=30px)](https://github.com/victoralmau) | Project Stock
[project_stock_product_set](project_stock_product_set/) | 14.0.1.0.2 | [![victoralmau](https://github.com/victoralmau.png?size=30px)](https://github.com/victoralmau) | Project Stock Product Set
[project_stock_request](project_stock_request/) | 14.0.1.0.0 | | Create stock requests from a projects and project tasks
[project_tag](project_tag/) | 14.0.1.0.0 | [![patrickrwilson](https://github.com/patrickrwilson.png?size=30px)](https://github.com/patrickrwilson) | Project Tags
[project_task_add_very_high](project_task_add_very_high/) | 14.0.1.0.0 | [![astirpe](https://github.com/astirpe.png?size=30px)](https://github.com/astirpe) | Adds extra options 'High' and 'Very High' on tasks
Expand Down
35 changes: 35 additions & 0 deletions project_sequence/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
**This file is going to be generated by oca-gen-addon-readme.**

*Manual changes will be overwritten.*

Please provide content in the ``readme`` directory:

* **DESCRIPTION.rst** (required)
* INSTALL.rst (optional)
* CONFIGURE.rst (optional)
* **USAGE.rst** (optional, highly recommended)
* DEVELOP.rst (optional)
* ROADMAP.rst (optional)
* HISTORY.rst (optional, recommended)
* **CONTRIBUTORS.rst** (optional, highly recommended)
* CREDITS.rst (optional)

Content of this README will also be drawn from the addon manifest,
from keys such as name, authors, maintainers, development_status,
and license.

A good, one sentence summary in the manifest is also highly recommended.


Automatic changelog generation
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

`HISTORY.rst` can be auto generated using `towncrier <https://pypi.org/project/towncrier>`_.

Just put towncrier compatible changelog fragments into `readme/newsfragments`
and the changelog file will be automatically generated and updated when a new fragment is added.

Please refer to `towncrier` documentation to know more.

NOTE: the changelog will be automatically generated when using `/ocabot merge $option`.
If you need to run it manually, refer to `OCA/maintainer-tools README <https://github.com/OCA/maintainer-tools>`_.
1 change: 1 addition & 0 deletions project_sequence/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
28 changes: 28 additions & 0 deletions project_sequence/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2023 Moduon Team S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0)

{
"name": "Project Sequence",
"summary": "Add a sequence field to projects, filled automatically",
"version": "14.0.0.1.0",
"development_status": "Alpha",
"category": "Services/Project",
"website": "https://github.com/OCA/project",
"author": "Moduon, Odoo Community Association (OCA)",
"maintainers": ["yajo", "anddago78"],
"license": "LGPL-3",
"application": False,
"installable": True,
"preloadable": True,
"external_dependencies": {
"python": [],
"bin": [],
},
"depends": [
"project",
],
"data": [
"data/ir_sequence.xml",
"views/project_project.xml",
],
}
12 changes: 12 additions & 0 deletions project_sequence/data/ir_sequence.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2023 Moduon Team S.L.
License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0) -->
<data noupdate="1">
<record id="seq_project_sequence" model="ir.sequence">
<field name="name">Project sequence</field>
<field name="code">project.sequence</field>
<field name="prefix">%(y)s-</field>
<field name="padding">5</field>
<field name="company_id" eval="False" />
</record>
</data>
Empty file added project_sequence/i18n/.empty
Empty file.
1 change: 1 addition & 0 deletions project_sequence/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import project_project
40 changes: 40 additions & 0 deletions project_sequence/models/project_project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright 2023 Moduon Team S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0)


from odoo import api, fields, models


class ProjectProject(models.Model):
_inherit = "project.project"

code = fields.Char(
readonly=True,
copy=False,
default=lambda self: self.env["ir.sequence"].next_by_code("project.sequence"),
)
name = fields.Char(required=False)
display_name = fields.Char(
compute="_compute_display_name_project", store=True, index=True
)

@api.depends("name", "code")
def _compute_display_name_project(self):
for rec in self:
rec.display_name = rec.name
if rec.name != rec.code:
rec.display_name = "{} - {}".format(rec.code, rec.name)

@api.model
def create(self, vals):
res = super().create(vals)
if not res.name:
res.name = res.code
return res

def write(self, vals):
res = super().write(vals)
for rec in self:
if not rec.name:
rec.name = rec.code
return res
2 changes: 2 additions & 0 deletions project_sequence/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Andrea Cattalani (`Moduon <https://www.moduon.team/>`__)
* Jairo Llopis (`Moduon <https://www.moduon.team/>`__)
6 changes: 6 additions & 0 deletions project_sequence/readme/CREDITS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.. This file is optional and contains additional credits, other than
authors, contributors, and maintainers.
The development of this module has been financially supported by:

* Moduon
4 changes: 4 additions & 0 deletions project_sequence/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.. This file must be max 2-3 paragraphs, and is required.
It should explain *why* this module exists.
Add a sequence field to projects, filled automatically and add a code sequence filter in tree view project.
15 changes: 15 additions & 0 deletions project_sequence/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.. This file must be present. It contains the usage instructions
for end-users. As all other rst files included in the README,
it MUST NOT contain reStructuredText sections
only body text (paragraphs, lists, tables, etc). Should you need
a more elaborate structure to explain the addon, please create a
Sphinx documentation (which may include this file as a "quick start"
section).
To use this module, you need to:

#. Go in the project icon.
#. Click the button "create" for create a new project
#. Fill the field Project name and click create button
#. Now in the kanban view see the project name when you are created
#. Repeat this operation creating other project without name.
Binary file added project_sequence/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
79 changes: 79 additions & 0 deletions project_sequence/static/description/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions project_sequence/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_project_sequence
37 changes: 37 additions & 0 deletions project_sequence/tests/test_project_sequence.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright 2023 Moduon Team S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0)

from freezegun import freeze_time

from odoo.tests.common import Form, SavepointCase, new_test_user, users


@freeze_time("2023-01-01 12:00:00", tick=True)
class TestProjectSequence(SavepointCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
new_test_user(cls.env, "manager", "project.group_project_manager")
cls.pjr_seq = cls.env["ir.sequence"].search([("code", "=", "project.sequence")])
cls.pjr_seq.number_next = 11

@users("manager")
def test_sequence_after_creation(self):
"""Sequence is applied only after project creation."""
prj_f = Form(self.env["project.project"])
self.assertFalse(prj_f.name)
# self.assertFalse(prj_f.code)
proj = prj_f.save()
self.assertTrue(proj.code)
self.assertEqual(proj.name, proj.code)
self.assertEqual(proj.code, "23-00012")

@users("manager")
def test_sequence_copied_to_name_if_emptied(self):
"""Sequence is copied to project name if user removes it."""
proj = self.env["project.project"].create({"name": "whatever"})
self.assertEqual(proj.name, "whatever")
self.assertEqual(proj.code, "23-00013")
with Form(proj) as prj_f:
prj_f.name = False
self.assertEqual(proj.name, "23-00013")
50 changes: 50 additions & 0 deletions project_sequence/views/project_project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2023 Moduon Team S.L.
License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0) -->
<data>

<record id="project_sequence_form_edit_project" model="ir.ui.view">
<field name="name">Project.sequence.project.edit</field>
<field name="model">project.project</field>
<field name="inherit_id" ref="project.edit_project" />
<field name="arch" type="xml">
<xpath expr="//field[@name='partner_id']" position="after">
<field name="code" />
</xpath>
</field>
</record>
<record id="project_sequence_form_view_project" model="ir.ui.view">
<field name="name">Project_sequence_project_view</field>
<field name="model">project.project</field>
<field name="inherit_id" ref="project.view_project" />
<field name="arch" type="xml">
<xpath expr="//field[@name='name']" position="replace">
<field name="display_name" />
<field name="code" optional="hide" />
</xpath>
</field>
</record>
<record id="project_sequence_form_kanban_project" model="ir.ui.view">
<field name="name">Project.sequence.project.kanban</field>
<field name="model">project.project</field>
<field name="inherit_id" ref="project.view_project_kanban" />
<field name="arch" type="xml">
<field name="name" position="after">
<field name="display_name" />
</field>
<xpath expr="//t[@t-esc='record.name.value']" position="replace">
<t t-esc="record.display_name.value" />
</xpath>
</field>
</record>
<record id="project_sequence_form_view_project_search" model="ir.ui.view">
<field name="name">Project_sequence_project_view_search</field>
<field name="model">project.project</field>
<field name="inherit_id" ref="project.view_project_project_filter" />
<field name="arch" type="xml">
<xpath expr="//field[@name='partner_id']" position="after">
<field name="code" />
</xpath>
</field>
</record>
</data>
1 change: 1 addition & 0 deletions setup/project_sequence/odoo/addons/project_sequence
6 changes: 6 additions & 0 deletions setup/project_sequence/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit 4072367

Please sign in to comment.