Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.0][NEW] event_registration_multi_qty: New module for allow registration writing quantities. #78

Merged
merged 2 commits into from Jun 22, 2017

Conversation

sergio-teruel
Copy link
Contributor

@sergio-teruel sergio-teruel commented Jun 2, 2017

@sergio-teruel sergio-teruel force-pushed the 10.0-PR-event_registration_multi_qty branch from d910e61 to c03af50 Compare June 2, 2017 09:22
Copy link
Member

@yajo yajo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a lot of suggested improvements, but none of them seem to be blocking. Code review OK.

PS: I guess this will have to be combined with a website_event_sale_registration_qty addon, right?

:alt: License: AGPL-3

============================
Event Registration Multi Qty
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO event_registration_qty should be enough. The same for this title.

@@ -0,0 +1,56 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:alt: License: AGPL-3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you update to latest template please?

Event Registration Multi Qty
============================

This module allows to make registration to events with more than one quantity.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"more than one quantity" -> "more than one attendee".

'author': 'Tecnativa, '
'Odoo Community Association (OCA)',
"license": "AGPL-3",
'website': 'https://odoo-community.org/',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_inherit = 'event.event'

registration_multi_qty = fields.Boolean(
string='Registration Multi Qty',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Allow multiple attendees per registration"


registration_multi_qty = fields.Boolean(
string='Registration Multi Qty',
help='Allow more than one registration'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the above string you do not need this help I think

@api.onchange('registration_multi_qty')
def _onchange_registration_multi_qty(self):
if not self.registration_multi_qty:
self.registration_ids.write({'qty': 1})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling write under an onchange is dangerous, because onchanges work in a draft record while write don't. You should call update instead.

Anyway, this does not seem to be a good choice. If somebody clicks here by mistake, he'd be overriding all qtys. I feel for this is better to add a constraint, so that if you already have registrations with qty != 1 you cannot check this box. The same constraint could be called when changing qty field in registrations.


Further reading showed me that after all, qty is ignored if disabled, so why even bother about this?

if not event.registration_multi_qty:
return super(EventEvent, self)._compute_seats()
event.seats_unconfirmed = event.seats_reserved = 0
event.seats_used = event.seats_available = 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In these 2 lines you are actually performing 4 writes to DB. Later below, each += call performs another write. How about working with simple variables that start with 0 and perform a single .write({...}) at the end? 🤔

default=1,
)
registration_multi_qty = fields.Boolean(
related='event_id.registration_multi_qty')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd add readonly=True here too.

@sergio-teruel sergio-teruel force-pushed the 10.0-PR-event_registration_multi_qty branch from c03af50 to 4354e48 Compare June 2, 2017 11:58
@sergio-teruel
Copy link
Contributor Author

@yajo Changes done, no changes in module name

event.seats_unconfirmed + event.seats_reserved +
event.seats_used)

@api.multi
Copy link
Member

@yajo yajo Jun 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK this is no more needed in v10. Not a requirement though.

if not event.registration_multi_qty and \
max(event.registration_ids.mapped('qty') or [0]) > 1:
raise ValidationError(
_('You can not inactive this option if there is '
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inactive > disable
is > are

max(registration.event_id.registration_ids.mapped(
'qty') or [0]) > 1:
raise ValidationError(
_('You can not add quantities if you not active the'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

active > activate

for registration in self:
if not registration.event_id.registration_multi_qty and \
max(registration.event_id.registration_ids.mapped(
'qty') or [0]) > 1:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is IMHO overloaded. While editing a registration, you don't need to check all others from the same event, since they don't changed.

if True in self.mapped("event_id.registration_multi_qty") and self.filtered(lambda reg: reg.qty != 1) should be enough

@yajo
Copy link
Member

yajo commented Jun 2, 2017

Check Travis too please

@sergio-teruel sergio-teruel force-pushed the 10.0-PR-event_registration_multi_qty branch from 4354e48 to cea2926 Compare June 2, 2017 14:34
@sergio-teruel
Copy link
Contributor Author

@yajo Changes done

@sergio-teruel sergio-teruel force-pushed the 10.0-PR-event_registration_multi_qty branch 2 times, most recently from 878199e to ab16f62 Compare June 2, 2017 14:43
<field name="inherit_id" ref="event.view_event_form"/>
<field name="arch" type="xml">
<field name="auto_confirm" position="after">
<field name="registration_multi_qty"/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a good hook since event_sale overrides it. Any better position?

@sergio-teruel
Copy link
Contributor Author

@chienandalu changes done

@OCA OCA deleted a comment from yajo Jun 9, 2017
@OCA OCA deleted a comment from yajo Jun 9, 2017

To use this module, you need to:

#. Go to *Events* and create one.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are configuration steps, not usage steps.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these are usage steps: you need to create an event to use this addon.

#. Go to *Events* and create one.
#. Go to *Registration tab* and check "Registration Multi Qty" to activate
this function.
#. Create an attendee for this event and you can write the quantities for this
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one should be kept here though.

@api.depends('seats_max', 'registration_ids.state',
'registration_ids.qty')
def _compute_seats(self):
for event in self:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better for performance reasons on super:

multi_qty_events = self.filtered('registration_multi_qty')
for event in multi_qty_events:
    ...
rest = self - multi_qty_events
super(EventEvent, rest)._compute_seats()

def _compute_seats(self):
for event in self:
if not event.registration_multi_qty:
return super(EventEvent, self)._compute_seats()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take care with this next time! (although now with the new code proposed this dissapears). This would end the computation in the middle if you find an event without multi qty.

max(event.registration_ids.mapped('qty') or [0]) > 1:
raise ValidationError(
_('You can not disable this option if there are '
'registrations with quantities grather than one.'))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/grather/greater (and change source translation also).

@api.multi
@api.constrains('registration_multi_qty')
def _check_attendees_qty(self):
for event in self:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for event in self.filtered(lambda x: not x.registration_multi_qty): and remove the condition inside the loop.

@api.multi
@api.constrains('qty')
def _check_attendees_qty(self):
for registration in self:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put directly:
if self.filtered(lambda x: not x.event_id.registration_multi_qty and registration.qty > 1):

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh well, thiking it twice... 🤔 @sergio-teruel is being more performant here, because the loop stops on the first match, so he better leaves this as it is. 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

"""Events Analysis"""
_inherit = "report.event.registration"

def _sub_select(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work if odoo/odoo#16633 is not merged, so we have to wait.


To use this module, you need to:

#. Go to *Events* and create one.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these are usage steps: you need to create an event to use this addon.


.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/199/10
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Broken link.

@pedrobaeza pedrobaeza force-pushed the 10.0-PR-event_registration_multi_qty branch from 340a7b3 to c455f10 Compare June 20, 2017 18:11
@pedrobaeza pedrobaeza force-pushed the 10.0-PR-event_registration_multi_qty branch from c455f10 to 4c8bd0c Compare June 20, 2017 18:27
@OCA OCA deleted a comment from yajo Jun 20, 2017
@OCA OCA deleted a comment from yajo Jun 20, 2017
@pedrobaeza
Copy link
Member

@yajo, please give your final blessing.

Copy link
Member

@yajo yajo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome 👍

Copy link
Member

@chienandalu chienandalu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reports don't count properly on runbot (new report query not yet propagated?). Tested locally with success 😃

@yajo yajo merged commit 9edaee8 into OCA:10.0 Jun 22, 2017
@yajo yajo deleted the 10.0-PR-event_registration_multi_qty branch June 22, 2017 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants