Skip to content

Commit

Permalink
[16.0][MIG] partner_event: Migration to version 16.0
Browse files Browse the repository at this point in the history
Biggest change is that _onchange_partner_id was removed in v16 core code so we no longer super it here. Instead, we call the _synchronize_partner_values method, which was the main job of the old _onchange_partner_id.
  • Loading branch information
kwoychesko authored and carolinafernandez-tecnativa committed Oct 4, 2023
1 parent 54b0f3d commit a58b570
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 54 deletions.
5 changes: 3 additions & 2 deletions partner_event/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@
# Copyright 2017 Tecnativa S.L. - David Vidal
# Copyright 2018 Jupical Technologies Pvt. Ltd. - Anil Kesariya
# Copyright 2020 Tecnativa S.L. - Víctor Martínez
# Copyright 2023 Tecnativa S.L. - Carolina Fernandez
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

{
"name": "Link partner to events",
"version": "15.0.1.0.0",
"version": "16.0.1.0.0",
"category": "Marketing",
"author": "Tecnativa," "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/event",
"development_status": "Production/Stable",
"license": "AGPL-3",
"depends": ["event"],
"depends": ["event", "website"],
"data": [
"security/ir.model.access.csv",
"views/res_partner_view.xml",
Expand Down
28 changes: 18 additions & 10 deletions partner_event/models/event_registration.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# Copyright 2014 Tecnativa S.L. - Pedro M. Baeza
# Copyright 2015 Tecnativa S.L. - Javier Iniesta
# Copyright 2016 Tecnativa S.L. - Antonio Espinosa
# Copyright 2016 Tecnativa S.L. - Vicent Cubells
# Copyright 2020 Tecnativa S.L. - Víctor Martínez
# Copyright 2015 Tecnativa - Javier Iniesta
# Copyright 2016 Tecnativa - Antonio Espinosa
# Copyright 2016 Tecnativa - Vicent Cubells
# Copyright 2018 Jupical Technologies Pvt. Ltd. - Anil Kesariya
# Copyright 2020 Tecnativa - Víctor Martínez
# Copyright 2014-2023 Tecnativa - Pedro M. Baeza
# Copyright 2023 Tecnativa - Carolina Fernandez
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import api, fields, models


Expand All @@ -17,6 +18,7 @@ class EventRegistration(models.Model):
string="Attendee Partner",
ondelete="restrict",
copy=False,
index=True,
)

def _prepare_partner(self, vals):
Expand Down Expand Up @@ -64,7 +66,13 @@ def _onchange_partner_id(self):
get_attendee_partner_address = {

Check warning on line 66 in partner_event/models/event_registration.py

View check run for this annotation

Codecov / codecov/patch

partner_event/models/event_registration.py#L65-L66

Added lines #L65 - L66 were not covered by tests
"get_attendee_partner_address": self.attendee_partner_id,
}
return super(
EventRegistration, self.with_context(**get_attendee_partner_address)
)._onchange_partner_id()
return super(EventRegistration, self)._onchange_partner_id()
# onchange for partner_id removed in v16 core - including functionality here
self = self.with_context(**get_attendee_partner_address)

Check warning on line 70 in partner_event/models/event_registration.py

View check run for this annotation

Codecov / codecov/patch

partner_event/models/event_registration.py#L70

Added line #L70 was not covered by tests
for registration in self:
if registration.partner_id:
registration.update(

Check warning on line 73 in partner_event/models/event_registration.py

View check run for this annotation

Codecov / codecov/patch

partner_event/models/event_registration.py#L73

Added line #L73 was not covered by tests
registration._synchronize_partner_values(
registration.partner_id
)
)
return {}

Check warning on line 78 in partner_event/models/event_registration.py

View check run for this annotation

Codecov / codecov/patch

partner_event/models/event_registration.py#L78

Added line #L78 was not covered by tests
1 change: 1 addition & 0 deletions partner_event/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Rafael Blasco
* Víctor Martínez
* Stefan Ungureanu
* Carolina Fernandez

* `Antiun <https://antiun.com/>`__:

Expand Down
1 change: 1 addition & 0 deletions partner_event/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ <h2><a class="toc-backref" href="#id5">Contributors</a></h2>
<li>Rafael Blasco</li>
<li>Víctor Martínez</li>
<li>Stefan Ungureanu</li>
<li>Carolina Fernandez/li>
</ul>
</li>
<li><a class="reference external" href="https://antiun.com/">Antiun</a>:<ul>
Expand Down
10 changes: 5 additions & 5 deletions partner_event/tests/test_event_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ def test_count_registrations(self):
event_1 = self.event_0.copy()
self.assertEqual(self.partner_01.registration_count, 0)
self.registration_01.state = "open"
self.partner_01.invalidate_cache()
self.partner_01.invalidate_recordset()
self.assertEqual(self.partner_01.registration_count, 1)
self.registration_02.state = "done"
self.registration_02.attendee_partner_id = self.partner_01
self.registration_02.event_id = event_1
self.partner_01.invalidate_cache()
self.partner_01.invalidate_recordset()
self.assertEqual(self.partner_01.registration_count, 2)

def test_button_register(self):
Expand All @@ -81,16 +81,16 @@ def test_data_update(self):
event_2 = self.event_0.copy()
self.yesterday = datetime.now() - timedelta(days=1)
self.tomorrow = datetime.now() + timedelta(days=1)
self.last_moth = datetime.now() - timedelta(days=30)
self.last_month = datetime.now() - timedelta(days=30)
# Set an old event
event_2.write({"date_begin": self.last_moth})
event_2.write({"date_begin": self.last_month})
event_2.write({"date_end": self.yesterday})
self.registration_02.event_id = event_2
self.registration_02.attendee_partner_id = self.partner_01
# Update partner for an old event
self.partner_01.write({"email": "new@test.com"})
self.assertNotEqual(event_2.registration_ids.email, "new@test.com")
# Update partner for an current event
# Update partner for a current event
event_2.write({"date_end": self.tomorrow})
self.partner_01.write({"email": "new@test.com"})
self.assertEqual(event_2.registration_ids.email, "new@test.com")
Expand Down
41 changes: 15 additions & 26 deletions partner_event/wizard/res_partner_register_event.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
# Copyright 2014 Tecnativa S.L. - Pedro M. Baeza
# Copyright 2015 Tecnativa S.L. - Javier Iniesta
# Copyright 2016 Tecnativa S.L. - Antonio Espinosa
# Copyright 2016 Tecnativa S.L. - Vicent Cubells
# Copyright 2015 Tecnativa - Javier Iniesta
# Copyright 2016 Tecnativa - Antonio Espinosa
# Copyright 2016 Tecnativa - Vicent Cubells
# Copyright 2018 Jupical Technologies Pvt. Ltd. - Anil Kesariya
# Copyright 2020 Tecnativa S.L. - Víctor Martínez
# Copyright 2020 Tecnativa - Víctor Martínez
# Copyright 2014-2023 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import fields, models


class ResPartnerRegisterEvent(models.TransientModel):
_name = "res.partner.register.event"

_description = "Register partner for event"

event = fields.Many2one(
comodel_name="event.event", required=True, ondelete="cascade"
)
errors = fields.Text(readonly=True)

def _prepare_registration(self, partner):
return {
Expand All @@ -27,28 +25,19 @@ def _prepare_registration(self, partner):
"name": partner.name,
"email": partner.email,
"phone": partner.phone,
"date_open": fields.Datetime.now(),
}

def button_register(self):
registration_obj = self.env["event.registration"]
errors = []
vals_list = []
Registration = self.env["event.registration"]
for partner in self.env["res.partner"].browse(
self.env.context.get("active_ids", [])
):
try:
with self.env.cr.savepoint():
registration_obj.create(self._prepare_registration(partner))
except Exception:
errors.append(partner.name)
if errors:
self.errors = "\n".join(errors)
data_obj = self.env.ref("partner_event." "res_partner_register_event_view")
return {
"type": "ir.actions.act_window",
"res_model": self._name,
"view_mode": "form",
"view_id": [data_obj.id],
"res_id": self.id,
"target": "new",
}
if not Registration.search(
[
("event_id", "=", self.event.id),
("attendee_partner_id", "=", partner.id),
]
):
vals_list.append(self._prepare_registration(partner))
self.env["event.registration"].create(vals_list)
15 changes: 4 additions & 11 deletions partner_event/wizard/res_partner_register_event_view.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2016 Tecnativa S.L. - Vicent Cubells
<!-- Copyright 2016 Tecnativa - Vicent Cubells
Copyright 2023 Tecnativa - Pedro M. Baeza
Copyright 2018 Jupical Technologies Pvt. Ltd. - Anil kesariya
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -->
<odoo>
Expand All @@ -8,22 +9,14 @@
<field name="model">res.partner.register.event</field>
<field name="arch" type="xml">
<form string="Select event to register">
<group attrs="{'invisible': [('errors', '!=', False)]}">
<group>
<field
name="event"
options="{'no_create': True, 'no_create_edit':True}"
/>
</group>
<group attrs="{'invisible': [('errors', '=', False)]}">
<separator
colspan="4"
string="These partners haven't been registered because they\'re already
registered or other error occurred"
/>
<field nolabel="1" name="errors" colspan="4" />
</group>
<footer>
<div attrs="{'invisible': [('errors', '!=', False)]}">
<div>
<button
name="button_register"
type="object"
Expand Down

0 comments on commit a58b570

Please sign in to comment.