Skip to content

Commit

Permalink
[MIG] event_project: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rrebollo committed Jan 9, 2025
1 parent 7e0e463 commit c488185
Show file tree
Hide file tree
Showing 13 changed files with 195 additions and 127 deletions.
31 changes: 19 additions & 12 deletions event_project/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ Event project
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fevent-lightgray.png?logo=github
:target: https://github.com/OCA/event/tree/16.0/event_project
:target: https://github.com/OCA/event/tree/17.0/event_project
:alt: OCA/event
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/event-16-0/event-16-0-event_project
:target: https://translation.odoo-community.org/projects/event-17-0/event-17-0-event_project
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/event&target_branch=16.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/event&target_branch=17.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand All @@ -47,22 +47,25 @@ Fields inherited from event:
Usage
=====

To use this module, you need to:
To use this module, the logged-in user must be a member of the
**Administrator** group for Events App:

1. Go to an event or create a brand new one and assign a project or
create a new one.
2. After saving, the event will be updated with the name of the event
and date.
3. Modify those fields and check propagation: Namem, Date begin, Date
end, Organizer and Note
1. Go to an event or create a new one, then assign a project or create a
new one. |Event Form View|
2. After saving the event, some fields will be updated on the related
project.
3. Modify the following fields and check for propagation: Name, Start
Date, End Date, Organizer, and Note.

.. |Event Form View| image:: https://raw.githubusercontent.com/OCA/event/17.0/event_project/static/images/event_form_view.png

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/event/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/event/issues/new?body=module:%20event_project%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/event/issues/new?body=module:%20event_project%0Aversion:%2017.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.

Expand Down Expand Up @@ -92,6 +95,10 @@ Contributors

- Eduardo de Miguel (`Moduon <https://www.moduon.team>`__)

- `Binhex <https://binhex.cloud>`__:

- Rolando Pérez <rolando.perez@binhex.cloud>

Maintainers
-----------

Expand All @@ -116,6 +123,6 @@ Current `maintainers <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-Shide| |maintainer-rafaelbn|

This module is part of the `OCA/event <https://github.com/OCA/event/tree/16.0/event_project>`_ project on GitHub.
This module is part of the `OCA/event <https://github.com/OCA/event/tree/17.0/event_project>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion event_project/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Event project",
"version": "16.0.1.0.1",
"version": "17.0.1.0.0",
"author": "Tecnativa, Moduon, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/event",
"license": "AGPL-3",
Expand Down
66 changes: 34 additions & 32 deletions event_project/models/event_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@ class EventEvent(models.Model):
project_id = fields.Many2one(
comodel_name="project.project",
string="Related project",
domain=[("event_id", "=", False)],
help="Project end date will be updated with event start date.",
)

task_ids = fields.One2many(
comodel_name="project.task",
inverse_name="event_id",
string="Tasks",
readonly=True,
)

count_tasks = fields.Integer(
string="Task number",
compute="_compute_count_tasks",
Expand All @@ -29,45 +32,44 @@ def _compute_count_tasks(self):
for event in self:
event.count_tasks = len(event.task_ids)

def project_data_update(self, vals):
"""Update data in the linked project. To be called after calling
create/write super."""
def _set_event_to_linked_project(self):
for event in self.filtered("project_id"):
event.project_id.event_id = event.id

_sql_constraints = [
(
"project_id_uniq",
"unique(project_id)",
"You can't link two events to the same project.",
),
]

@api.model_create_multi
def create(self, vals_list):
events = super().create(vals_list)
events._set_event_to_linked_project()
return events

def _get_project_vals(event):
return {
"name": event.display_name,
"date_start": event.date_begin,
"date": event.date_end,
"event_id": event.id,
"partner_id": event.organizer_id.id,
"description": event.note,
}
def write(self, vals):
# If project is removed, remove event from project
if vals.get("project_id") is False:
self.mapped("project_id").update({"event_id": False})

Check warning on line 56 in event_project/models/event_event.py

View check run for this annotation

Codecov / codecov/patch

event_project/models/event_event.py#L56

Added line #L56 was not covered by tests
res = super().write(vals)
# If project is set, set event to project
if vals.get("project_id"):
self._set_event_to_linked_project()
elif any([f in vals for f in self._fields_to_sync_to_project()]):
self.mapped("project_id")._sync_from_related_event()
return res

@api.model
def _fields_to_sync_to_project(self):
fields_to_check = {
"name",
"date_begin",
"date_end",
"project_id",
"organizer_id",
"note",
}
if not any([f in vals for f in fields_to_check]):
return

for event in self:
if not event.project_id:
continue
event.project_id.write(_get_project_vals(event))

@api.model
def create(self, vals):
events = super().create(vals)
events.project_data_update(vals)
return events

def write(self, vals):
if vals.get("project_id") is False:
self.mapped("project_id").write({"event_id": False})
res = super().write(vals)
self.project_data_update(vals)
return res
return fields_to_check
27 changes: 26 additions & 1 deletion event_project/models/project_project.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2024 Moduon Team S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import fields, models
from odoo import api, fields, models


class Project(models.Model):
Expand All @@ -10,3 +10,28 @@ class Project(models.Model):
event_id = fields.Many2one(
comodel_name="event.event", string="Related event", readonly=True
)

def _sync_from_related_event(self):
for record in self.filtered("event_id"):
event = record.event_id
record.write(
{
"name": event.display_name,
"date_start": event.date_begin,
"date": event.date_end,
"partner_id": event.organizer_id and event.organizer_id.id or None,
"description": event.note,
}
)

@api.model_create_multi
def create(self, vals_list):
projects = super().create(vals_list)
projects._sync_from_related_event()
return projects

def write(self, vals):
res = super().write(vals)
if vals.get("event_id"):
self._sync_from_related_event()
return res
3 changes: 3 additions & 0 deletions event_project/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
4 changes: 4 additions & 0 deletions event_project/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@
- Ernesto Tejeda

- Eduardo de Miguel ([Moduon](https://www.moduon.team))

- [Binhex](https://binhex.cloud):

- Rolando Pérez \<<rolando.perez@binhex.cloud>\>
10 changes: 5 additions & 5 deletions event_project/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
To use this module, you need to:
To use this module, the logged-in user must be a member of the **Administrator** group for Events App:

1. Go to an event or create a brand new one and assign a project or create a new one.
2. After saving, the event will be updated with the name of the event and date.
3. Modify those fields and check propagation: Namem, Date begin, Date end, Organizer
and Note
1. Go to an event or create a new one, then assign a project or create a new one.
![Event Form View](../static/images/event_form_view.png)
2. After saving the event, some fields will be updated on the related project.
3. Modify the following fields and check for propagation: Name, Start Date, End Date, Organizer, and Note.
36 changes: 22 additions & 14 deletions event_project/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
Expand Down Expand Up @@ -274,7 +275,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: grey; } /* line numbers */
pre.code .ln { color: gray; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
Expand All @@ -300,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -368,7 +369,7 @@ <h1 class="title">Event project</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:43b55b332c7b2fa54fbf04e01e06798cf09891bb789deac6c53f9c35f247dde7
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/event/tree/16.0/event_project"><img alt="OCA/event" src="https://img.shields.io/badge/github-OCA%2Fevent-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/event-16-0/event-16-0-event_project"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/event&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/event/tree/17.0/event_project"><img alt="OCA/event" src="https://img.shields.io/badge/github-OCA%2Fevent-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/event-17-0/event-17-0-event_project"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/event&amp;target_branch=17.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module allows you to assign a project to an event. This project
will inherit its event’s fields.</p>
<p>Fields inherited from event:</p>
Expand All @@ -394,22 +395,23 @@ <h1 class="title">Event project</h1>
</div>
<div class="section" id="usage">
<h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
<p>To use this module, you need to:</p>
<p>To use this module, the logged-in user must be a member of the
<strong>Administrator</strong> group for Events App:</p>
<ol class="arabic simple">
<li>Go to an event or create a brand new one and assign a project or
create a new one.</li>
<li>After saving, the event will be updated with the name of the event
and date.</li>
<li>Modify those fields and check propagation: Namem, Date begin, Date
end, Organizer and Note</li>
<li>Go to an event or create a new one, then assign a project or create a
new one. <img alt="Event Form View" src="https://raw.githubusercontent.com/OCA/event/17.0/event_project/static/images/event_form_view.png" /></li>
<li>After saving the event, some fields will be updated on the related
project.</li>
<li>Modify the following fields and check for propagation: Name, Start
Date, End Date, Organizer, and Note.</li>
</ol>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/event/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/event/issues/new?body=module:%20event_project%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/event/issues/new?body=module:%20event_project%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand All @@ -435,18 +437,24 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
</ul>
</li>
<li>Eduardo de Miguel (<a class="reference external" href="https://www.moduon.team">Moduon</a>)</li>
<li><a class="reference external" href="https://binhex.cloud">Binhex</a>:<ul>
<li>Rolando Pérez &lt;<a class="reference external" href="mailto:rolando.perez&#64;binhex.cloud">rolando.perez&#64;binhex.cloud</a>&gt;</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>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.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainers</a>:</p>
<p><a class="reference external image-reference" href="https://github.com/Shide"><img alt="Shide" src="https://github.com/Shide.png?size=40px" /></a> <a class="reference external image-reference" href="https://github.com/rafaelbn"><img alt="rafaelbn" src="https://github.com/rafaelbn.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/event/tree/16.0/event_project">OCA/event</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/event/tree/17.0/event_project">OCA/event</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
Binary file added event_project/static/images/event_form_view.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit c488185

Please sign in to comment.