summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornie <nie@odoo.com>2021-05-17 10:02:06 +0000
committernie <nie@odoo.com>2021-05-21 11:24:25 +0000
commitbee8ac5ccf8106b25566332e769b73e8f707d05b (patch)
tree3c8f3bd5757905e83ebe5ea96dd465726eab91d6
parented723be917637320fc4d2787bdf505e4a7a8216d (diff)
[FIX] event_sale: ticket price with pricelist
Steps: - Install Events - Go to Events / Configuration / Settings - Enable Tickets - Go to Sales / Configuration / Settings - Enable Multiple Sales Prices per Product - Go to Sales / Products - Edit Event Registration - Sales tab - Pricing - Pricelist: Public Pricelist (USD) - Price: $6 - Go to Sales - Create a new quotation - Pricelist: Public Pricelist (USD) - Product: Event Registration - Event: Design Fair - Ticket: VIP Bug: The pricelist is not taken into account. Unit price should be $900 but is $1500. Explanation: The original issue comes from this commit: https://github.com/odoo/odoo/commit/379f1490c93dc599a74add2d678c18fbba1efa62 The advertised amount was not the one showing up in the cart. This is because the pricelist was not taken into account anymore when entering the payment process. Using `price_reduce` instead of `price` enables all kinds of discounts on the final price. However, `price_reduce` relies on the context to find the current pricelist. This commit adds the context needed to compute the price of the tickets. This context is the same as the one in the sales module since pricelists are working fine there: https://github.com/odoo/odoo/blob/b208570ce8399bc6d3e4a8ba02eef6558e0a6ccc/addons/sale/models/sale.py#L1494 The currency conversion is done in `product.price`. It's therefore already done when calling `price_reduce`. opw:2519453 closes odoo/odoo#71114 X-original-commit: e92282f712d485ca97feb8a729abe3b975183451 Signed-off-by: backspac <backspac@users.noreply.github.com>
-rw-r--r--addons/event_sale/models/sale_order.py7
-rw-r--r--addons/event_sale/tests/test_event_sale.py56
2 files changed, 57 insertions, 6 deletions
diff --git a/addons/event_sale/models/sale_order.py b/addons/event_sale/models/sale_order.py
index 9f170b994ce..57d9c3ad140 100644
--- a/addons/event_sale/models/sale_order.py
+++ b/addons/event_sale/models/sale_order.py
@@ -137,11 +137,6 @@ class SaleOrderLine(models.Model):
def _get_display_price(self, product):
if self.event_ticket_id and self.event_id:
- company = self.event_id.company_id or self.env.company
- currency = company.currency_id
- return currency._convert(
- self.event_ticket_id.price, self.order_id.currency_id,
- self.order_id.company_id or self.env.company.id,
- self.order_id.date_order or fields.Date.today())
+ return self.event_ticket_id.with_context(pricelist=self.order_id.pricelist_id.id, uom=self.product_uom.id).price_reduce
else:
return super()._get_display_price(product)
diff --git a/addons/event_sale/tests/test_event_sale.py b/addons/event_sale/tests/test_event_sale.py
index f41949a5fb5..8b8ab6c7d92 100644
--- a/addons/event_sale/tests/test_event_sale.py
+++ b/addons/event_sale/tests/test_event_sale.py
@@ -50,6 +50,7 @@ class TestEventSale(TestEventSaleCommon):
'event_ticket_id': ticket1.id,
'product_id': ticket1.product_id.id,
'product_uom_qty': TICKET1_COUNT,
+ 'price_unit': 10,
}), (0, 0, {
'event_id': self.event_0.id,
'event_ticket_id': ticket2.id,
@@ -153,3 +154,58 @@ class TestEventSale(TestEventSaleCommon):
self.assertEqual(editor_action['type'], 'ir.actions.act_window')
self.assertEqual(editor_action['res_model'], 'registration.editor')
+
+ def test_ticket_price_with_pricelist_and_tax(self):
+ self.env.user.partner_id.country_id = False
+ pricelist = self.env['product.pricelist'].search([], limit=1)
+
+ tax = self.env['account.tax'].create({
+ 'name': "Tax 10",
+ 'amount': 10,
+ })
+
+ event_product = self.env['product.template'].create({
+ 'name': 'Event Product',
+ 'list_price': 10.0,
+ })
+
+ event_product.taxes_id = tax
+
+ event = self.env['event.event'].create({
+ 'name': 'New Event',
+ 'date_begin': '2020-02-02',
+ 'date_end': '2020-04-04',
+ })
+ event_ticket = self.env['event.event.ticket'].create({
+ 'name': 'VIP',
+ 'price': 1000.0,
+ 'event_id': event.id,
+ 'product_id': event_product.product_variant_id.id,
+ })
+
+ pricelist.item_ids = self.env['product.pricelist.item'].create({
+ 'applied_on': "1_product",
+ 'base': "list_price",
+ 'compute_price': "fixed",
+ 'fixed_price': 6.0,
+ 'product_tmpl_id': event_product.id,
+ })
+
+ pricelist.discount_policy = 'without_discount'
+
+ so = self.env['sale.order'].create({
+ 'partner_id': self.env.user.partner_id.id,
+ 'pricelist_id': pricelist.id,
+ })
+ sol = self.env['sale.order.line'].create({
+ 'name': event.name,
+ 'product_id': event_product.product_variant_id.id,
+ 'product_uom_qty': 1,
+ 'product_uom': event_product.uom_id.id,
+ 'price_unit': event_product.list_price,
+ 'order_id': so.id,
+ 'event_id': event.id,
+ 'event_ticket_id': event_ticket.id,
+ })
+ sol.product_id_change()
+ self.assertEqual(so.amount_total, 660.0, "Ticket is $1000 but the event product is on a pricelist 10 -> 6. So, $600 + a 10% tax.")