8000 [FW][FIX] website_event_sale: don't remind people of unavailable tickets by fw-bot · Pull Request #210500 · odoo/odoo · GitHub
[go: up one dir, main page]

Skip to content

[FW][FIX] website_event_sale: don't remind peo 8000 ple of unavailable tickets #210500

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

Closed
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
7 changes: 5 additions & 2 deletions addons/event/models/event_ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,13 @@ def _compute_seats(self):
ticket.seats_available = ticket.seats_max - (ticket.seats_reserved + ticket.seats_used)
ticket.seats_taken = ticket.seats_reserved + ticket.seats_used

@api.depends('seats_limited', 'seats_available')
@api.depends('seats_limited', 'seats_available', 'event_id.event_registrations_sold_out')
def _compute_is_sold_out(self):
for ticket in self:
ticket.is_sold_out = ticket.seats_limited and not ticket.seats_available
ticket.is_sold_out = (
(ticket.seats_limited and not ticket.seats_available)
or ticket.event_id.event_registrations_sold_out
)

@api.constrains('start_sale_datetime', 'end_sale_datetime')
def _constrains_dates_coherency(self):
Expand Down
6 changes: 6 additions & 0 deletions addons/website_event_sale/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ def _cart_update_order_line(self, order_line, quantity, **kwargs):

return updated_line

def _filter_can_send_abandoned_cart_mail(self):
# Prevent carts with expired/sold out tickets from being subject of reminder emails
return super()._filter_can_send_abandoned_cart_mail().filtered(
lambda so: all(ticket.sale_available for ticket in so.order_line.event_ticket_id),
)


class SaleOrderLine(models.Model):
_inherit = "sale.order.line"
Expand Down
2 changes: 1 addition & 1 deletion addons/website_event_sale/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from . import common
from . import test_frontend_buy_tickets
from . import test_website_event_sale_cart
from . import test_website_event_sale_pricelist
from . import test_website_event_sale
70 changes: 70 additions & 0 deletions addons/website_event_sale/tests/test_website_event_sale_cart.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
from datetime import datetime, timedelta

from odoo import Command
from odoo.tests import tagged

from odoo.addons.website_event_sale.tests.common import TestWebsiteEventSaleCommon
from odoo.addons.website_sale.tests.test_website_sale_cart_abandoned import (
TestWebsiteSaleCartAbandonedCommon,
)


@tagged('post_install', '-at_install')
class TestWebsiteEventSaleCart(TestWebsiteEventSaleCommon, TestWebsiteSaleCartAbandonedCommon):

@classmethod
def setUpClass(cls):
super().setUpClass()

cls.website.write({
'send_abandoned_cart_email': True,
'cart_abandoned_delay': 1.0, # 1 hour
})
cls.website.send_abandoned_cart_email_activation_time -= timedelta(weeks=1)

cls.partner_admin = cls.env.ref('base.partner_admin')
if not cls.partner_admin.email:
cls.partner_admin.email = 'base@partner.admin'

def test_sold_out_event_cart_reminder(self):
"""Check that abandoned cart emails aren't sent for sold out tickets."""
cart1, cart2 = self.env['sale.order'].create([{
'partner_id': partner.id,
'website_id': self.website.id,
'date_order': datetime.now() - timedelta(hours=2),
} for partner in (self.partner_admin, self.partner_portal)])

self.ticket.write({
'seats_limited': True,
'seats_max': 1,
})

create_order_line = [Command.create({
'product_id': self.product_event.id,
'event_id': self.event.id,
'event_ticket_id': self.ticket.id,
})]
cart1.order_line = create_order_line
cart2.order_line = create_order_line
self.assertTrue(
self.send_mail_patched(cart1.id),
"Abandoned cart email should be sent for availlable tickets",
)

# Create registrations & confirm first order
editor = self.env['registration.editor'].new()
editor.with_context(default_sale_order_id=cart1.id).action_make_registration()
cart1.action_confirm()
self.assertEqual(self.ticket.seats_available, 0)
self.assertFalse(
self.send_mail_patched(cart2.id),
"Abandoned cart email should not be sent when ticket has no seats available",
)

# Reset sent state, increase seat limit, and try again
cart2.cart_recovery_email_sent = False
self.ticket.seats_max = 2
self.assertTrue(
self.send_mail_patched(cart2.id),
"Abandoned cart email can be sent after increasing seat count",
)
0