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

[FIX] event_sale: failed payment on soldout events #1281

Open
wants to merge 1 commit into
base: 15.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions addons/event_sale/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
'views/event_registration_views.xml',
'views/event_views.xml',
'views/sale_order_views.xml',
'views/templates.xml',
'data/event_sale_data.xml',
'data/mail_data.xml',
'report/event_event_templates.xml',
Expand Down
16 changes: 16 additions & 0 deletions addons/event_sale/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class SaleOrder(models.Model):
_inherit = "sale.order"

attendee_count = fields.Integer('Attendee Count', compute='_compute_attendee_count')
has_soldout_event = fields.Boolean(compute="_compute_has_soldout_event")

def write(self, vals):
""" Synchronize partner from SO to registrations. This is done notably
Expand Down Expand Up @@ -52,6 +53,21 @@ def _compute_attendee_count(self):
for sale_order in self:
sale_order.attendee_count = attendee_count_data.get(sale_order.id, 0)

def _compute_has_soldout_event(self):
"""Meant to be used in the portal to prevent customers from paying for an event
that is sold out. Not only because we'd overbook the event, but also because it
will probably crash on the confirmation of the order when the registrations
are created."""
self.has_soldout_event = False
for order in self.filtered(lambda x: x.state in ["draft", "sent"]):
order.has_soldout_event = bool(order.order_line.event_id.filtered(
lambda x: x.seats_limited and x.seats_max and x.seats_available <= 0
))

def has_to_be_paid(self, include_draft=False):
has_to_be_paid = super().has_to_be_paid(include_draft=include_draft)
return has_to_be_paid and not self.has_soldout_event

def unlink(self):
self.order_line._unlink_associated_registrations()
return super(SaleOrder, self).unlink()
Expand Down
11 changes: 11 additions & 0 deletions addons/event_sale/views/templates.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="sale_order_portal_template" inherit_id="sale.sale_order_portal_template" name="Event sale order portal">
<xpath expr="//div[@t-if='sale_order.is_expired']" position="before">
<div t-if="sale_order.has_soldout_event" class="alert alert-warning alert-dismissable d-print-none" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"></button>
<strong>The event is sold out!</strong> <a role="button" href="#discussion"><i class="fa fa-comment"/> Contact us for more information.</a>
</div>
</xpath>
</template>
</odoo>