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
[10.0][NEW] event_registration_multi_qty: New module for allow registration writing quantities. #78
Conversation
d910e61
to
c03af50
Compare
There was a problem hiding this 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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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/', |
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
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' |
There was a problem hiding this comment.
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}) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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') |
There was a problem hiding this comment.
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.
c03af50
to
4354e48
Compare
@yajo Changes done, no changes in module name |
event.seats_unconfirmed + event.seats_reserved + | ||
event.seats_used) | ||
|
||
@api.multi |
There was a problem hiding this comment.
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 ' |
There was a problem hiding this comment.
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' |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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
Check Travis too please |
4354e48
to
cea2926
Compare
@yajo Changes done |
878199e
to
ab16f62
Compare
<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"/> |
There was a problem hiding this comment.
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?
@chienandalu changes done |
|
||
To use this module, you need to: | ||
|
||
#. Go to *Events* and create one. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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.')) |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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):
There was a problem hiding this comment.
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. 👍
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Broken link.
340a7b3
to
c455f10
Compare
c455f10
to
4c8bd0c
Compare
@yajo, please give your final blessing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome 👍
There was a problem hiding this 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 😃
cc @Tecnativa