mirror of
https://github.com/bringout/oca-ocb-sale.git
synced 2026-04-27 13:12:07 +02:00
Initial commit: Sale packages
This commit is contained in:
commit
14e3d26998
6469 changed files with 2479670 additions and 0 deletions
|
|
@ -0,0 +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
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from datetime import timedelta
|
||||
|
||||
from odoo.fields import Datetime
|
||||
from odoo.tests.common import TransactionCase
|
||||
|
||||
|
||||
class TestWebsiteEventSaleCommon(TransactionCase):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(TestWebsiteEventSaleCommon, cls).setUpClass()
|
||||
|
||||
cls.env.company.country_id = cls.env.ref('base.us')
|
||||
cls.currency_test = cls.env['res.currency'].create({
|
||||
'name': 'eventX',
|
||||
'rounding': 0.01,
|
||||
'symbol': 'EX',
|
||||
})
|
||||
cls.partner = cls.env['res.partner'].create({'name': 'test'})
|
||||
cls.env['res.currency.rate'].search([]).unlink()
|
||||
cls.rate = cls.env['res.currency.rate'].create({
|
||||
'company_id': cls.env.company.id,
|
||||
'currency_id': cls.currency_test.id,
|
||||
'name': '2022-01-01',
|
||||
'rate': 10,
|
||||
})
|
||||
cls.zero_tax = cls.env['account.tax'].sudo().create({
|
||||
'name': 'Tax 0',
|
||||
'amount': 0,
|
||||
})
|
||||
cls.product_event = cls.env['product.product'].create({
|
||||
'detailed_type': 'event',
|
||||
'list_price': 100,
|
||||
'name': 'Event Registration No Company Assigned',
|
||||
'taxes_id': [(6, 0, cls.zero_tax.ids)],
|
||||
})
|
||||
|
||||
cls.event = cls.env['event.event'].create({
|
||||
'date_begin': (Datetime.today() + timedelta(days=5)).strftime('%Y-%m-%d 07:00:00'),
|
||||
'date_end': (Datetime.today() + timedelta(days=5)).strftime('%Y-%m-%d 16:30:00'),
|
||||
'name': 'Pycon',
|
||||
'user_id': cls.env.ref('base.user_admin').id,
|
||||
'website_published': True,
|
||||
})
|
||||
cls.ticket = cls.env['event.event.ticket'].create([{
|
||||
'event_id': cls.event.id,
|
||||
'name': 'Standard',
|
||||
'product_id': cls.product_event.id,
|
||||
'price': 100,
|
||||
}])
|
||||
|
||||
cls.current_website = cls.env['website'].get_current_website()
|
||||
cls.pricelist = cls.current_website.get_current_pricelist()
|
||||
|
||||
cls.so = cls.env['sale.order'].create({
|
||||
'company_id': cls.env.company.id,
|
||||
'partner_id': cls.partner.id,
|
||||
'pricelist_id': cls.pricelist.id,
|
||||
})
|
||||
|
||||
def create_pricelist(currency, name, policy):
|
||||
return cls.env['product.pricelist'].create({
|
||||
'currency_id': currency.id,
|
||||
'discount_policy': policy,
|
||||
'item_ids': [(5, 0, 0), (0, 0, {
|
||||
'applied_on': '3_global',
|
||||
'compute_price': 'percentage',
|
||||
'percent_price': 10,
|
||||
})],
|
||||
'name': name,
|
||||
'selectable': True,
|
||||
})
|
||||
|
||||
cls.pricelist_with_discount = create_pricelist(currency=cls.env.company.currency_id, name='EUR With Discount Included', policy='with_discount')
|
||||
cls.pricelist_without_discount = create_pricelist(currency=cls.env.company.currency_id, name='EUR Without Discount Included', policy='without_discount')
|
||||
cls.ex_pricelist_with_discount = create_pricelist(currency=cls.currency_test, name='EX With Discount Included', policy='with_discount')
|
||||
cls.ex_pricelist_without_discount = create_pricelist(currency=cls.currency_test, name='EX Without Discount Included', policy='without_discount')
|
||||
|
|
@ -0,0 +1,130 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
import odoo.tests
|
||||
|
||||
from datetime import timedelta
|
||||
|
||||
from odoo.addons.base.tests.common import HttpCaseWithUserDemo
|
||||
from odoo.addons.website_event_sale.tests.common import TestWebsiteEventSaleCommon
|
||||
from odoo.fields import Datetime
|
||||
|
||||
|
||||
@odoo.tests.common.tagged('post_install', '-at_install')
|
||||
class TestUi(HttpCaseWithUserDemo, TestWebsiteEventSaleCommon):
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
if self.env['ir.module.module']._get('payment_custom').state != 'installed':
|
||||
self.skipTest("Transfer provider is not installed")
|
||||
|
||||
self.env.ref('payment.payment_provider_transfer').write({
|
||||
'state': 'enabled',
|
||||
'is_published': True,
|
||||
})
|
||||
|
||||
self.event_2 = self.env['event.event'].create({
|
||||
'name': 'Conference for Architects TEST',
|
||||
'user_id': self.env.ref('base.user_admin').id,
|
||||
'date_begin': (Datetime.today() + timedelta(days=5)).strftime('%Y-%m-%d 07:00:00'),
|
||||
'date_end': (Datetime.today() + timedelta(days=5)).strftime('%Y-%m-%d 16:30:00'),
|
||||
'website_published': True,
|
||||
})
|
||||
|
||||
self.env['event.event.ticket'].create([{
|
||||
'name': 'Standard',
|
||||
'event_id': self.event_2.id,
|
||||
'product_id': self.env.ref('event_sale.product_product_event').id,
|
||||
'start_sale_datetime': (Datetime.today() - timedelta(days=5)).strftime('%Y-%m-%d 07:00:00'),
|
||||
'end_sale_datetime': (Datetime.today() + timedelta(90)).strftime('%Y-%m-%d'),
|
||||
'price': 1000.0,
|
||||
}, {
|
||||
'name': 'VIP',
|
||||
'event_id': self.event_2.id,
|
||||
'product_id': self.env.ref('event_sale.product_product_event').id,
|
||||
'end_sale_datetime': (Datetime.today() + timedelta(90)).strftime('%Y-%m-%d'),
|
||||
'price': 1500.0,
|
||||
}])
|
||||
|
||||
self.event_3 = self.env['event.event'].create({
|
||||
'name': 'Last ticket test',
|
||||
'user_id': self.env.ref('base.user_admin').id,
|
||||
'date_begin': (Datetime.today() + timedelta(days=5)).strftime('%Y-%m-%d 07:00:00'),
|
||||
'date_end': (Datetime.today() + timedelta(days=5)).strftime('%Y-%m-%d 16:30:00'),
|
||||
'website_published': True,
|
||||
})
|
||||
|
||||
self.env['event.event.ticket'].create([{
|
||||
'name': 'VIP',
|
||||
'event_id': self.event_3.id,
|
||||
'product_id': self.env.ref('event_sale.product_product_event').id,
|
||||
'end_sale_datetime': (Datetime.today() + timedelta(90)).strftime('%Y-%m-%d'),
|
||||
'price': 1500.0,
|
||||
'seats_max': 2,
|
||||
}])
|
||||
|
||||
# flush event to ensure having tickets available in the tests
|
||||
self.env.flush_all()
|
||||
|
||||
(self.env.ref('base.partner_admin') + self.partner_demo).write({
|
||||
'street': '215 Vine St',
|
||||
'city': 'Scranton',
|
||||
'zip': '18503',
|
||||
'country_id': self.env.ref('base.us').id,
|
||||
'state_id': self.env.ref('base.state_us_39').id,
|
||||
'phone': '+1 555-555-5555',
|
||||
'email': 'admin@yourcompany.example.com',
|
||||
})
|
||||
|
||||
self.env['account.journal'].create({'name': 'Cash - Test', 'type': 'cash', 'code': 'CASH - Test'})
|
||||
|
||||
def test_admin(self):
|
||||
if self.env['ir.module.module']._get('payment_custom').state != 'installed':
|
||||
self.skipTest("Transfer provider is not installed")
|
||||
|
||||
# Seen that:
|
||||
# - this test relies on demo data that are entirely in USD (pricelists)
|
||||
# - that main demo company is gelocated in US
|
||||
# - that this test awaits for hardcoded USDs amount
|
||||
# we have to force company currency as USDs only for this test
|
||||
self.cr.execute("UPDATE res_company SET currency_id = %s WHERE id = %s", [self.env.ref('base.USD').id, self.env.ref('base.main_company').id])
|
||||
|
||||
transfer_provider = self.env.ref('payment.payment_provider_transfer')
|
||||
transfer_provider.write({
|
||||
'state': 'enabled',
|
||||
'is_published': True,
|
||||
})
|
||||
transfer_provider._transfer_ensure_pending_msg_is_set()
|
||||
|
||||
self.start_tour("/", 'event_buy_tickets', login="admin")
|
||||
|
||||
def test_demo(self):
|
||||
if self.env['ir.module.module']._get('payment_custom').state != 'installed':
|
||||
self.skipTest("Transfer provider is not installed")
|
||||
|
||||
transfer_provider = self.env.ref('payment.payment_provider_transfer')
|
||||
transfer_provider.write({
|
||||
'state': 'enabled',
|
||||
'is_published': True,
|
||||
})
|
||||
transfer_provider._transfer_ensure_pending_msg_is_set()
|
||||
|
||||
self.start_tour("/", 'event_buy_tickets', login="demo")
|
||||
|
||||
def test_buy_last_ticket(self):
|
||||
if self.env['ir.module.module']._get('payment_custom').state != 'installed':
|
||||
self.skipTest("Transfer provider is not installed")
|
||||
|
||||
transfer_provider = self.env.ref('payment.payment_provider_transfer')
|
||||
transfer_provider.write({
|
||||
'state': 'enabled',
|
||||
'is_published': True,
|
||||
})
|
||||
transfer_provider._transfer_ensure_pending_msg_is_set()
|
||||
|
||||
self.start_tour("/", 'event_buy_last_ticket')
|
||||
|
||||
def test_pricelists_different_currencies(self):
|
||||
self.start_tour("/", 'event_sale_pricelists_different_currencies', login='admin')
|
||||
# TO DO - add public test with new address when convert to web.tour format.
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
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):
|
||||
def test_sold_out_event_cart_reminder(self):
|
||||
"""Check that abandoned cart emails aren't sent for sold out tickets."""
|
||||
cart1, cart2 = carts = self.so1before + self.so2before
|
||||
carts.order_line.unlink()
|
||||
carts.website_id.send_abandoned_cart_email = True
|
||||
|
||||
self.event.auto_confirm = True
|
||||
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,0 +1,69 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo.addons.website_sale.controllers.main import WebsiteSale
|
||||
from odoo.addons.website.tools import MockRequest
|
||||
from odoo.addons.website_event_sale.tests.common import TestWebsiteEventSaleCommon
|
||||
from odoo.tests import tagged
|
||||
|
||||
|
||||
@tagged('post_install', '-at_install')
|
||||
class TestWebsiteEventPriceList(TestWebsiteEventSaleCommon):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(TestWebsiteEventPriceList, cls).setUpClass()
|
||||
|
||||
cls.WebsiteSaleController = WebsiteSale()
|
||||
|
||||
def test_pricelist_different_currency(self):
|
||||
|
||||
so_line = self.env['sale.order.line'].create({
|
||||
'event_id': self.event.id,
|
||||
'event_ticket_id': self.ticket.id,
|
||||
'name': self.event.name,
|
||||
'order_id': self.so.id,
|
||||
'product_id': self.ticket.product_id.id,
|
||||
'product_uom_qty': 1,
|
||||
})
|
||||
# set pricelist to 0 - currency: company
|
||||
self.pricelist.write({
|
||||
'currency_id': self.env.company.currency_id.id,
|
||||
'discount_policy': 'with_discount',
|
||||
'item_ids': [(5, 0, 0), (0, 0, {
|
||||
'applied_on': '3_global',
|
||||
'compute_price': 'percentage',
|
||||
'percent_price': 0,
|
||||
})],
|
||||
'name': 'With Discount Included',
|
||||
})
|
||||
with MockRequest(self.env, sale_order_id=self.so.id, website=self.current_website):
|
||||
self.WebsiteSaleController.pricelist(promo=None)
|
||||
self.so._cart_update(line_id=so_line.id, product_id=self.ticket.product_id.id, set_qty=1)
|
||||
self.assertEqual(so_line.price_reduce, 100)
|
||||
|
||||
# set pricelist to 10% - without discount
|
||||
self.pricelist.write({
|
||||
'currency_id': self.currency_test.id,
|
||||
'discount_policy': 'without_discount',
|
||||
'item_ids': [(5, 0, 0), (0, 0, {
|
||||
'applied_on': '3_global',
|
||||
'compute_price': 'percentage',
|
||||
'percent_price': 10,
|
||||
})],
|
||||
'name': 'Without Discount Included',
|
||||
})
|
||||
with MockRequest(self.env, sale_order_id=self.so.id, website=self.current_website):
|
||||
self.WebsiteSaleController.pricelist(promo=None)
|
||||
self.so._cart_update(line_id=so_line.id, product_id=self.ticket.product_id.id, set_qty=1)
|
||||
self.assertEqual(so_line.price_reduce, 900, 'Incorrect amount based on the pricelist and its currency.')
|
||||
|
||||
# set pricelist to 10% - with discount
|
||||
self.pricelist.write({
|
||||
'discount_policy': 'with_discount',
|
||||
'name': 'With Discount Included',
|
||||
})
|
||||
with MockRequest(self.env, sale_order_id=self.so.id, website=self.current_website):
|
||||
self.WebsiteSaleController.pricelist(promo=None)
|
||||
self.so._cart_update(line_id=so_line.id, product_id=self.ticket.product_id.id, set_qty=1)
|
||||
self.assertEqual(so_line.price_reduce, 900, 'Incorrect amount based on the pricelist and its currency.')
|
||||
Loading…
Add table
Add a link
Reference in a new issue