Skip to content

Commit

Permalink
[MIG] resource_booking: Finish migration
Browse files Browse the repository at this point in the history
Changes done:
- Squash administrative commits.
- Purge translations.
- Remove duplicate partner_ids field (similar to v15). Remove partner_id field from tree and form views (similar to v15).
- Fix tests and/or remove warnings.
- Remove migration scripts from 15.0
- Remove unnecesary pre-migration script from 16.0

TT45643
  • Loading branch information
victoralmau committed Mar 11, 2024
1 parent 91c49b4 commit 971b788
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 135 deletions.
6 changes: 0 additions & 6 deletions resource_booking/i18n/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -1349,9 +1349,3 @@ msgstr ""
#: model_terms:ir.ui.view,arch_db:resource_booking.message_combination_assigned
msgid "because you belong to the chosen resource combination:"
msgstr ""

#~ msgid "Next Activity Resource Booking"
#~ msgstr "Siguiente actividad de reserva de recursos"

#~ msgid "Who requested this booking?"
#~ msgstr "¿Quién solicitó esta reserva/cita?"
9 changes: 0 additions & 9 deletions resource_booking/i18n/fr_FR.po
Original file line number Diff line number Diff line change
Expand Up @@ -1360,12 +1360,3 @@ msgstr ""
#: model_terms:ir.ui.view,arch_db:resource_booking.message_combination_assigned
msgid "because you belong to the chosen resource combination:"
msgstr ""

#~ msgid "Who requested this booking?"
#~ msgstr "Qui a demandé cette réservation ?"

#~ msgid "SMS Delivery error"
#~ msgstr "Erreur de livraison SMS"

#~ msgid "Followers (Channels)"
#~ msgstr "Abonnés (Chaînes)"
19 changes: 0 additions & 19 deletions resource_booking/migrations/15.0.1.4.0/post-migration.py

This file was deleted.

10 changes: 0 additions & 10 deletions resource_booking/migrations/15.0.1.4.0/pre-migration.py

This file was deleted.

33 changes: 0 additions & 33 deletions resource_booking/migrations/16.0.1.0.0/pre-migration.py

This file was deleted.

8 changes: 6 additions & 2 deletions resource_booking/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ class ResPartner(models.Model):
)

def _compute_resource_booking_count(self):
for p in self:
p.resource_booking_count = len(p.resource_booking_ids)
booking_data = self.env["resource.booking"].read_group(

Check warning on line 15 in resource_booking/models/res_partner.py

View check run for this annotation

Codecov / codecov/patch

resource_booking/models/res_partner.py#L15

Added line #L15 was not covered by tests
[("partner_id", "in", self.ids)], ["partner_id"], ["partner_id"]
)
data = {x["partner_id"][0]: x["partner_id_count"] for x in booking_data}
for record in self:
record.resource_booking_count = data.get(record.id, 0)

Check warning on line 20 in resource_booking/models/res_partner.py

View check run for this annotation

Codecov / codecov/patch

resource_booking/models/res_partner.py#L20

Added line #L20 was not covered by tests

def action_view_resource_booking(self):
self.ensure_one()
Expand Down
17 changes: 0 additions & 17 deletions resource_booking/models/resource_booking.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,6 @@ class ResourceBooking(models.Model):
tracking=True,
help="Who will attend this booking?",
)
partner_ids = fields.Many2many(
"res.partner",
string="Contacts",
store=True,
compute="_compute_partner_ids",
inverse="_inverse_partner_ids",
help="E.g. multiple people in a room. Used by sale_resource_booking_period",
)
user_id = fields.Many2one(
comodel_name="res.users",
default=lambda self: self._default_user_id(),
Expand Down Expand Up @@ -405,15 +397,6 @@ def _compute_stop(self):
# Either value is False: no stop date
record.stop = False

@api.depends("partner_id")
def _compute_partner_ids(self):
for record in self:
if record.partner_id:
record.partner_ids = [(6, 0, [record.partner_id.id])]

def _inverse_partner_ids(self):
pass

@api.depends("meeting_id.user_id")
def _compute_user_id(self):
"""Get user from related meeting, if available."""
Expand Down
29 changes: 15 additions & 14 deletions resource_booking/tests/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,9 @@ def test_location(self):
self.assertEqual(rb.location, "Office 3")

def test_videocall_location(self):
"""Videocall location across records works as expected."""
"""Videocall location across records works as expected.
We need to set dummy urls to prevent the _set_videocall_location() method
of calendar from doing so."""
rbt2 = self.rbt.copy({"videocall_location": "Videocall Office 2"})
rb_f = Form(self.env["resource.booking"])
rb_f.partner_ids.add(self.partner)
Expand All @@ -638,29 +640,28 @@ def test_videocall_location(self):
self.assertEqual(rb.videocall_location, "Videocall Office 2")
# Still can change it independently
with Form(rb) as rb_f:
rb_f.videocall_location = "Videocall Office 1"
self.assertEqual(rb.videocall_location, "Videocall Office 1")
rb_f.videocall_location = "https://Videocall Office 1"
self.assertEqual(rb.videocall_location, "https://Videocall Office 1")
self.assertEqual(rbt2.videocall_location, "Videocall Office 2")
# Schedule the booking, meeting inherits videocall location from it
with Form(rb) as rb_f:
rb_f.start = "2021-03-01 08:00:00"
self.assertEqual(rb.state, "scheduled")
self.assertEqual(rb.videocall_location, "Videocall Office 1")
self.assertEqual(rb.meeting_id.videocall_location, "Videocall Office 1")
# Changing meeting videocall location changes videocall location of booking
self.assertEqual(rb.videocall_location, "https://Videocall Office 1")
self.assertEqual(rb.meeting_id.videocall_location, "https://Videocall Office 1")
with Form(rb.meeting_id) as meeting_f:
meeting_f.videocall_location = "Videocall Office 2"
self.assertEqual(rb.videocall_location, "Videocall Office 2")
self.assertEqual(rb.meeting_id.videocall_location, "Videocall Office 2")
meeting_f.videocall_location = "https://Videocall Office 2"
self.assertEqual(rb.videocall_location, "https://Videocall Office 2")
self.assertEqual(rb.meeting_id.videocall_location, "https://Videocall Office 2")
# Changing booking videocall location changes meeting location
with Form(rb) as rb_f:
rb_f.videocall_location = "Videocall Office 3"
self.assertEqual(rb.meeting_id.videocall_location, "Videocall Office 3")
self.assertEqual(rb.videocall_location, "Videocall Office 3")
rb_f.videocall_location = "https://Videocall Office 3"
self.assertEqual(rb.videocall_location, "https://Videocall Office 3")
self.assertEqual(rb.meeting_id.videocall_location, "https://Videocall Office 3")
# When unscheduled, it keeps videocall location untouched
rb.action_unschedule()
self.assertFalse(rb.meeting_id)
self.assertEqual(rb.videocall_location, "Videocall Office 3")
self.assertEqual(rb.videocall_location, "https://Videocall Office 3")

def test_organizer_sync(self):
"""Resource booking and meeting organizers are properly synced."""
Expand Down Expand Up @@ -777,7 +778,7 @@ def test_suggested_and_subscribed_recipients(self):
# Requester and combination must be suggested
self.assertEqual(
rb._message_get_suggested_recipients(),
{rb.id: [(rb.partner_id.id, "some customer", None, "Requester")]},
{rb.id: [(rb.partner_ids.id, "some customer", None, "Attendees")]},
)

def test_creating_rbt_has_tags(self):
Expand Down
37 changes: 16 additions & 21 deletions resource_booking/tests/test_portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,28 @@
from freezegun import freeze_time
from lxml.html import fromstring

from odoo.tests import new_test_user, tagged
from odoo.tests.common import HttpCase

from .common import create_test_data


@freeze_time("2021-02-26 09:00:00", tick=True)
@tagged("post_install", "-at_install")
class PortalCase(HttpCase):
def setUp(self):
super().setUp()
create_test_data(self)
self.user_portal, self.user_manager = self.env["res.users"].create(
[
{
"name": "portal",
"login": "ptl",
"password": "ptl",
"groups_id": [(4, self.env.ref("base.group_portal").id, 0)],
},
{
"name": "manager",
"login": "mgr",
"password": "mgr",
"groups_id": [
(4, self.env.ref("resource_booking.group_manager").id, 0)
],
},
]
@classmethod
def setUpClass(cls):
super().setUpClass()
create_test_data(cls)

cls.user_portal = new_test_user(
cls.env, login="ptl", password="ptl", groups="base.group_portal"
)
cls.user_manager = new_test_user(
cls.env,
login="mgr",
password="mgr",
groups="resource_booking.group_manager",
)

def _url_xml(self, url, data=None, timeout=10):
Expand Down Expand Up @@ -195,7 +190,7 @@ def test_portal_scheduling_conflict(self):
)
)
# Public guy's booking and related meeting are OK in backend
booking_public.invalidate_cache(ids=booking_public.ids)
booking_public.invalidate_model()
self.assertEqual(booking_public.state, "confirmed")
self.assertEqual(len(booking_public.meeting_id.attendee_ids), 2)
for attendee in booking_public.meeting_id.attendee_ids:
Expand Down
4 changes: 2 additions & 2 deletions resource_booking/views/menus.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@
groups="group_manager"
/>
<menuitem
id="resource_resource_menu"
id="menu_resource_resource"
parent="resource_booking_type_configuration_menu"
action="resource.action_resource_resource_tree"
sequence="100"
/>
<menuitem
id="resource_calendar_menu"
id="menu_resource_calendar"
parent="resource_booking_type_configuration_menu"
action="resource.action_resource_calendar_form"
sequence="200"
Expand Down
2 changes: 0 additions & 2 deletions resource_booking/views/resource_booking_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
<tree>
<field name="name" />
<field name="partner_ids" widget="many2many_tags" optional="hide" />
<field name="partner_id" />
<field name="type_id" />
<field name="combination_id" />
<field name="state" />
Expand Down Expand Up @@ -136,7 +135,6 @@
</div>
<group name="main">
<group name="booking">
<field name="partner_id" />
<field name="partner_ids" widget="many2many_tags" />
<field name="type_id" />
<label for="combination_id" />
Expand Down

0 comments on commit 971b788

Please sign in to comment.