Skip to content

Commit dc0eaee

Browse files
committed
[FIX] website_event_sale: fix strikethrough price display in cart
Since d2fd106, in the eCommerce cart, the strikethrough price loses its classes when `website_event_sale` is installed. closes odoo#219604 Related: odoo/upgrade#8094 Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
1 parent 049ad8e commit dc0eaee

File tree

8 files changed

+43
-36
lines changed

8 files changed

+43
-36
lines changed
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
# -*- coding: utf-8 -*-
2-
31
from . import product
42
from . import product_pricelist
53
from . import sale_order
4+
from . import sale_order_line

addons/website_event_sale/models/sale_order.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Part of Odoo. See LICENSE file for full copyright and licensing details.
22

3-
from odoo import _, api, models
3+
from odoo import _, models
44
from odoo.exceptions import UserError
55

66

@@ -125,17 +125,3 @@ def _filter_can_send_abandoned_cart_mail(self):
125125
return super()._filter_can_send_abandoned_cart_mail().filtered(
126126
lambda so: all(ticket.sale_available for ticket in so.order_line.event_ticket_id),
127127
)
128-
129-
130-
class SaleOrderLine(models.Model):
131-
_inherit = "sale.order.line"
132-
133-
@api.depends('product_id.display_name', 'event_ticket_id.display_name')
134-
def _compute_name_short(self):
135-
""" If the sale order line concerns a ticket, we don't want the product name, but the ticket name instead.
136-
"""
137-
super(SaleOrderLine, self)._compute_name_short()
138-
139-
for record in self:
140-
if record.event_ticket_id:
141-
record.name_short = record.event_ticket_id.display_name
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Part of Odoo. See LICENSE file for full copyright and licensing details.
2+
3+
from odoo import api, models
4+
5+
6+
class SaleOrderLine(models.Model):
7+
_inherit = 'sale.order.line'
8+
9+
@api.depends('product_id.display_name', 'event_ticket_id.display_name')
10+
def _compute_name_short(self):
11+
""" Override of `website_sale` to replace the product name with the ticket name. """
12+
super()._compute_name_short()
13+
14+
for line in self:
15+
if line.event_ticket_id:
16+
line.name_short = line.event_ticket_id.display_name
17+
18+
def _should_show_strikethrough_price(self):
19+
""" Override of `website_sale` to hide the strikethrough price for events. """
20+
return super()._should_show_strikethrough_price() and not self.event_id

addons/website_event_sale/views/website_sale_templates.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@
2020
</template>
2121

2222
<!-- If the sale order line concerns an event, we want to show an additional line with the event name even on small screens -->
23-
<template id="cart_lines_inherit_website_event_sale" inherit_id="website_sale.cart_lines_price" name="Event Shopping Cart Lines">
24-
<xpath expr="//del" position="attributes">
25-
<attribute name="t-attf-class" separator=" " add="#{line.event_id and 'd-none' or ''}"/>
26-
</xpath>
27-
</template>
28-
2923
<template id="cart_summary_inherit_website_event_sale" inherit_id="website_sale.cart_summary_content">
3024
<xpath expr="//td[@name='website_sale_cart_summary_product_name']/span" position="after">
3125
<span t-if="line.event_slot_id" class="text-muted" t-out="line.event_slot_id.display_name"/>

addons/website_sale/models/sale_order_line.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,14 @@ def _check_validity(self):
9090
raise UserError(self.env._(
9191
"The given product does not have a price therefore it cannot be added to cart.",
9292
))
93+
94+
def _should_show_strikethrough_price(self):
95+
""" Compute whether the strikethrough price should be shown.
96+
97+
The strikethrough price should be shown if there is a discount on a sellable line for
98+
which a price unit is non-zero.
99+
100+
:return: Whether the strikethrough price should be shown.
101+
:rtype: bool
102+
"""
103+
return self.discount and self._is_sellable() and self._get_displayed_unit_price()

addons/website_sale/views/templates.xml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2926,13 +2926,12 @@
29262926
class="d-flex flex-column flex-md-row align-items-end align-items-md-start justify-content-md-end mb-1"
29272927
name="website_sale_cart_line_price"
29282928
>
2929-
<t t-if="line.discount and line._is_sellable() and line._get_displayed_unit_price()">
2930-
<del
2931-
class="me-md-2 text-muted text-nowrap opacity-50"
2932-
t-out="line._get_displayed_unit_price() * line.product_uom_qty"
2933-
t-options="{'widget': 'monetary', 'display_currency': website.currency_id}"
2934-
/>
2935-
</t>
2929+
<del
2930+
t-if="line._should_show_strikethrough_price()"
2931+
class="me-md-2 text-muted text-nowrap opacity-50"
2932+
t-out="line._get_displayed_unit_price() * line.product_uom_qty"
2933+
t-options="{'widget': 'monetary', 'display_currency': website.currency_id}"
2934+
/>
29362935
<t t-set="product_price" t-value="line._get_cart_display_price()"/>
29372936
<t t-call="website_sale.cart_product_price"/>
29382937
</h6>

addons/website_sale_loyalty/models/sale_order_line.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,7 @@ def unlink(self):
2626
for order, rewards in disabled_rewards_per_order.items():
2727
order.disabled_auto_rewards += rewards
2828
return super().unlink()
29+
30+
def _should_show_strikethrough_price(self):
31+
""" Override of `website_sale` to hide the strikethrough price for rewards. """
32+
return super()._should_show_strikethrough_price() and not self.is_reward_line

addons/website_sale_loyalty/views/website_sale_templates.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,6 @@
153153
</xpath>
154154
</template>
155155

156-
<template id="website_sale_coupon_cart_hide_qty" inherit_id="website_sale.cart_lines_price">
157-
<xpath expr="//del" position="attributes">
158-
<attribute name="t-if">not line.is_reward_line</attribute>
159-
</xpath>
160-
</template>
161-
162156
<template id="layout" inherit_id="website.layout">
163157
<xpath expr="//*[@id='wrapwrap']" position="inside">
164158
<t t-set="coupon_error" t-value="request.params.get('coupon_error')"/>

0 commit comments

Comments
 (0)