diff --git a/addons/event_booth_sale/models/event_booth_category.py b/addons/event_booth_sale/models/event_booth_category.py index 5abb7f6bcb2ef..b7529fbcbdf9f 100644 --- a/addons/event_booth_sale/models/event_booth_category.py +++ b/addons/event_booth_sale/models/event_booth_category.py @@ -46,8 +46,14 @@ def _compute_price(self): def _compute_price_reduce(self): for category in self: product = category.product_id - list_price = product.list_price + product.price_extra - discount = (list_price - product.price) / list_price if list_price else 0.0 + pricelist = self.env['product.pricelist'].browse(self._context.get('pricelist')) + lst_price = product.currency_id._convert( + product.lst_price, + pricelist.currency_id, + self.env.company, + fields.Datetime.now() + ) + discount = (lst_price - product.price) / lst_price if lst_price else 0.0 category.price_reduce = (1.0 - discount) * category.price @api.depends_context('pricelist', 'quantity') diff --git a/addons/event_sale/models/event_ticket.py b/addons/event_sale/models/event_ticket.py index 278cd105cca19..6190eb05c8ec3 100644 --- a/addons/event_sale/models/event_ticket.py +++ b/addons/event_sale/models/event_ticket.py @@ -43,11 +43,19 @@ def _compute_description(self): if not ticket.description: ticket.description = False + @api.depends_context('pricelist', 'quantity') @api.depends('product_id', 'price') def _compute_price_reduce(self): for ticket in self: product = ticket.product_id - discount = (product.lst_price - product.price) / product.lst_price if product.lst_price else 0.0 + pricelist = self.env['product.pricelist'].browse(self._context.get('pricelist')) + lst_price = product.currency_id._convert( + product.lst_price, + pricelist.currency_id, + self.env.company, + fields.Datetime.now() + ) + discount = (lst_price - product.price) / lst_price if lst_price else 0.0 ticket.price_reduce = (1.0 - discount) * ticket.price def _init_column(self, column_name): diff --git a/addons/website_event_booth_sale/models/sale_order.py b/addons/website_event_booth_sale/models/sale_order.py index 71fa6d880af58..969b71e1470d0 100644 --- a/addons/website_event_booth_sale/models/sale_order.py +++ b/addons/website_event_booth_sale/models/sale_order.py @@ -2,7 +2,7 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from odoo import Command -from odoo import models, _ +from odoo import fields, models, _ class SaleOrder(models.Model): @@ -42,9 +42,48 @@ def _website_product_id_change(self, order_id, product_id, qty=0, **kwargs): event_booth_registrations_command = new_registrations_commands values['event_booth_registration_ids'] = event_booth_registrations_command + discount = 0 + order = self.env['sale.order'].sudo().browse(order_id) + booth_currency = booths.product_id.currency_id + pricelist_currency = order.pricelist_id.currency_id + price_reduce = sum(booth.booth_category_id.price_reduce for booth in booths) + if booth_currency != pricelist_currency: + price_reduce = booth_currency._convert( + price_reduce, + pricelist_currency, + order.company_id, + order.date_order or fields.Datetime.now() + ) + if order.pricelist_id.discount_policy == 'without_discount': + price = sum(booth.booth_category_id.price for booth in booths) + if price != 0: + if booth_currency != pricelist_currency: + price = booth_currency._convert( + price, + pricelist_currency, + order.company_id, + order.date_order or fields.Datetime.now() + ) + discount = (price - price_reduce) / price * 100 + price_unit = price + if discount < 0: + discount = 0 + price_unit = price_reduce + else: + price_unit = price_reduce + + else: + price_unit = price_reduce + + if order.pricelist_id and order.partner_id: + order_line = order._cart_find_product_line(booths.product_id.id) + if order_line: + price_unit = self.env['account.tax']._fix_tax_included_price_company(price_unit, booths.product_id.taxes_id, order_line[0].tax_id, self.company_id) + values.update( event_id=booths.event_id.id, - price_unit=sum(booth.booth_category_id.price_reduce for booth in booths), + discount=discount, + price_unit=price_unit, name=booths._get_booth_multiline_description, ) diff --git a/addons/website_event_booth_sale/tests/__init__.py b/addons/website_event_booth_sale/tests/__init__.py index 63f5c3df6494f..3fa0f6951855a 100644 --- a/addons/website_event_booth_sale/tests/__init__.py +++ b/addons/website_event_booth_sale/tests/__init__.py @@ -2,3 +2,4 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from . import test_event_booth_sale +from . import test_website_event_booth_sale_pricelist diff --git a/addons/website_event_booth_sale/tests/test_website_event_booth_sale_pricelist.py b/addons/website_event_booth_sale/tests/test_website_event_booth_sale_pricelist.py new file mode 100644 index 0000000000000..7b020973b9244 --- /dev/null +++ b/addons/website_event_booth_sale/tests/test_website_event_booth_sale_pricelist.py @@ -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.') diff --git a/addons/website_event_booth_sale/views/event_booth_templates.xml b/addons/website_event_booth_sale/views/event_booth_templates.xml index 985b2af36062a..426d3377ea80a 100644 --- a/addons/website_event_booth_sale/views/event_booth_templates.xml +++ b/addons/website_event_booth_sale/views/event_booth_templates.xml @@ -4,11 +4,16 @@