| 1 |
from odoo import http |
| 2 |
from odoo.addons.base.tests.common import HttpCaseWithUserPortal |
| 3 |
from odoo.addons.website_event_sale.tests.common import TestWebsiteEventSaleCommon |
| 4 |
|
| 5 |
|
| 6 |
class TestWebsiteEventSale(HttpCaseWithUserPortal, TestWebsiteEventSaleCommon): |
| 7 |
|
| 8 |
def test_website_event_sale_free_tickets(self): |
| 9 |
""" Test saleorder is not created for tickets free tickets """ |
| 10 |
self.authenticate(None, None) |
| 11 |
free_ticket = self.env['event.event.ticket'].create({ |
| 12 |
'event_id': self.event.id, |
| 13 |
'name': 'Free', |
| 14 |
'product_id': self.product_event.id, |
| 15 |
'price': 0, |
| 16 |
}) |
| 17 |
event_questions = self.event.question_ids |
| 18 |
event_registration_count = len(self.event.registration_ids) |
| 19 |
name_question = event_questions.filtered(lambda q: q.question_type == 'name') |
| 20 |
email_question = event_questions.filtered(lambda q: q.question_type == 'email') |
| 21 |
phone_question = event_questions.filtered(lambda q: q.question_type == 'phone') |
| 22 |
existing_so = self.env['sale.order'].search([]) |
| 23 |
self.url_open(f'/event/{self.event.id}/registration/confirm', data={ |
| 24 |
f'1-name-{name_question.id}': 'Bob', |
| 25 |
f'1-email-{email_question.id}': '[email protected]', |
| 26 |
f'1-phone-{phone_question.id}': '8989898989', |
| 27 |
'1-event_ticket_id': free_ticket.id, |
| 28 |
'csrf_token': http.Request.csrf_token(self), |
| 29 |
}) |
| 30 |
self.assertEqual(self.env['sale.order'].search([]), existing_so, "Sale order should not be created for the free tickets") |
| 31 |
self.assertEqual(len(self.event.registration_ids), event_registration_count + 1) |
| 32 |
|
| 33 |
def test_website_event_sale_free_paid_mix(self): |
| 34 |
""" Test saleorder is created if paid ticket selected """ |
| 35 |
self.authenticate(None, None) |
| 36 |
free_ticket = self.env['event.event.ticket'].create({ |
| 37 |
'event_id': self.event.id, |
| 38 |
'name': 'Free', |
| 39 |
'product_id': self.product_event.id, |
| 40 |
'price': 0, |
| 41 |
}) |
| 42 |
event_questions = self.event.question_ids |
| 43 |
event_registration_count = len(self.event.registration_ids) |
| 44 |
name_question = event_questions.filtered(lambda q: q.question_type == 'name') |
| 45 |
email_question = event_questions.filtered(lambda q: q.question_type == 'email') |
| 46 |
phone_question = event_questions.filtered(lambda q: q.question_type == 'phone') |
| 47 |
self.url_open(f'/event/{self.event.id}/registration/confirm', data={ |
| 48 |
f'1-name-{name_question.id}': 'Bob', |
| 49 |
f'1-email-{email_question.id}': '[email protected]', |
| 50 |
f'1-phone-{phone_question.id}': '8989898989', |
| 51 |
'1-event_ticket_id': self.ticket.id, |
| 52 |
f'2-name-{name_question.id}': 'joe', |
| 53 |
f'2-email-{email_question.id}': '[email protected]', |
| 54 |
f'2-phone-{phone_question.id}': '8989898988', |
| 55 |
'2-event_ticket_id': free_ticket.id, |
| 56 |
'csrf_token': http.Request.csrf_token(self), |
| 57 |
}) |
| 58 |
|
| 59 |
self.assertEqual(len(self.event.registration_ids), event_registration_count + 2) |
| 60 |
self.assertTrue(self.env['sale.order'].search([ |
| 61 |
('order_line.event_ticket_id', '=', self.ticket.id), |
| 62 |
('order_line.event_ticket_id', '=', free_ticket.id) |
| 63 |
]), "Sale order should be created for the free/paid tickets mix") |