forked from odoo/odoo
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX] website_event_booth_sale, website_event_sale: correct price
Steps to reproduce: - Create a price list with different currency and discount with "show price and discount to the customer" - On the website select this pricelist and register for the event. Issue: The price in the cart is shown in the main currency Solution: [website_event_sale] There is an initial issue which when it calls '_compute_price_reduce'. We compare, 'product.lst_price' (in product.currency) and 'product.price' (which has been converted to the pricelist.currency). In order to compare apples with apples, a conversion is applied to have the 'product.lst_price' in the same currency. After that, we have kind of a coherent behaviour in the sense that 'ticket.price_reduce' is in the same currency as 'ticket.price'. Thereafter, a conversion is applied (if the pricelist.currency is different) to get the expected amount. The same reasoning is applied to [website_event_booth_sale]. Note: 'list_price' has been changed to 'lst_price' in Booth to have the same logic between Event and Booth opw-2766997 closes odoo#85640 Signed-off-by: Nicolas Lempereur (nle) <nle@odoo.com>
- Loading branch information
Showing
11 changed files
with
331 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
addons/website_event_booth_sale/tests/test_website_event_booth_sale_pricelist.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# -*- coding: utf-8 -*- | ||
# Part of Odoo. See LICENSE file for full copyright and licensing details. | ||
|
||
from odoo.addons.event_booth_sale.tests.common import TestEventBoothSaleCommon | ||
from odoo.addons.website_event_sale.tests.common import TestWebsiteEventSaleCommon | ||
from odoo.addons.website_sale.controllers.main import WebsiteSale | ||
from odoo.addons.website.tools import MockRequest | ||
from odoo.tests import tagged | ||
|
||
|
||
@tagged('post_install', '-at_install') | ||
class TestWebsiteBoothPriceList(TestEventBoothSaleCommon, TestWebsiteEventSaleCommon): | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
super(TestWebsiteBoothPriceList, cls).setUpClass() | ||
|
||
cls.WebsiteSaleController = WebsiteSale() | ||
cls.booth_1 = cls.env['event.booth'].create({ | ||
'booth_category_id': cls.event_booth_category_1.id, | ||
'event_id': cls.event_0.id, | ||
'name': 'Test Booth 1', | ||
}) | ||
|
||
cls.booth_2 = cls.env['event.booth'].create({ | ||
'booth_category_id': cls.event_booth_category_1.id, | ||
'event_id': cls.event_0.id, | ||
'name': 'Test Booth 2', | ||
}) | ||
|
||
def test_pricelist_different_currency(self): | ||
so_line = self.env['sale.order.line'].create({ | ||
'event_booth_category_id': self.event_booth_category_1.id, | ||
'event_booth_pending_ids': (self.booth_1 + self.booth_2).ids, | ||
'event_id': self.event_0.id, | ||
'order_id': self.so.id, | ||
'product_id': self.event_booth_product.id, | ||
}) | ||
# set pricelist to 0 - currency: company | ||
self.pricelist.write({ | ||
'currency_id': self.new_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('With Discount Included') | ||
self.so._cart_update(line_id=so_line.id, product_id=self.event_booth_product.id, set_qty=1) | ||
self.assertEqual(so_line.price_reduce, 40) | ||
|
||
# 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('Without Discount Included') | ||
self.so._cart_update(line_id=so_line.id, product_id=self.event_booth_product.id, set_qty=1) | ||
self.assertEqual(so_line.price_reduce, 360, '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('With Discount Included') | ||
self.so._cart_update(line_id=so_line.id, product_id=self.event_booth_product.id, set_qty=1) | ||
self.assertEqual(so_line.price_reduce, 360, 'Incorrect amount based on the pricelist and its currency.') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
# -*- 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_pricelist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# -*- 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.product_event = cls.env['product.product'].create({ | ||
'base_unit_price': 100, | ||
'detailed_type': 'event', | ||
'name': 'Event Registration No Company Assigned', | ||
}) | ||
|
||
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.currency_test = cls.env['res.currency'].create({ | ||
'name': 'eventX', | ||
'rate': 10, | ||
'rounding': 0.01, | ||
'symbol': 'EX', | ||
}) | ||
cls.partner = cls.env['res.partner'].create({'name': 'test'}) | ||
cls.new_company = cls.env['res.company'].create({ | ||
'currency_id': cls.env.ref('base.EUR').id, | ||
'name': 'Great Company EUR', | ||
'partner_id': cls.partner.id, | ||
}) | ||
cls.env['res.currency.rate'].create({ | ||
'company_id': cls.new_company.id, | ||
'currency_id': cls.currency_test.id, | ||
'name': '2022-01-01', | ||
'rate': 10, | ||
}) | ||
|
||
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.new_company.id, | ||
'partner_id': cls.partner.id, | ||
'pricelist_id': cls.pricelist.id, | ||
}) |
69 changes: 69 additions & 0 deletions
69
addons/website_event_sale/tests/test_website_event_sale_pricelist.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.new_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('With Discount Included') | ||
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('Without Discount Included') | ||
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('With Discount Included') | ||
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.') |
Oops, something went wrong.