Skip to content

Commit

Permalink
[IMP] website_sale_hide_price: hide prices at website level
Browse files Browse the repository at this point in the history
  • Loading branch information
amkarthik committed Dec 29, 2023
1 parent c6dd746 commit 3984fee
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 23 deletions.
15 changes: 10 additions & 5 deletions website_sale_hide_price/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Website Sale Hide Price
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:2024f5968fe783275d5042d5cbe4031b434346af33881f33c0a2e390013a80a0
!! source digest: sha256:d43ba3760f368211c94b26ebdcd3ff06f965b92f55cd4766d6c95ca45cc0265c
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down Expand Up @@ -60,6 +60,11 @@ Hide prices at product level:
#. You can optionally set a message that will be displayed when the prices are
hidden.

If you want to hide prices at website level

#. Go to *Website > Configuration > Settings* and choose the website to hide the prices.
#. In the *Shop - Products* section you have the option *Hide prices on website*

Usage
=====

Expand All @@ -75,10 +80,6 @@ You shouldn't be able to either see the prices or buy any of the forbidden items
Known issues / Roadmap
======================

- This feature doesn't support multi website. The default behavior is to hide the prices
along every website. It could be modified the boolean field on the partner to a many2many
relation between res_partner and website_website, so that this price-hiding feature might
be made website-dependant.
- This module is incompatible with the website_sale_stock_force_block module because it
makes changes to the same attributes in the website_sale.products_add_to_cart template.

Expand Down Expand Up @@ -115,6 +116,10 @@ Contributors

* Pablo De Andrés <[email protected]>

* `Sodexis <https://sodexis.com>`:

* Karthik <[email protected]>

Maintainers
~~~~~~~~~~~

Expand Down
2 changes: 1 addition & 1 deletion website_sale_hide_price/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Website Sale Hide Price",
"version": "16.0.1.4.0",
"version": "16.0.1.5.0",
"category": "Website",
"author": "Tecnativa, " "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/e-commerce",
Expand Down
5 changes: 5 additions & 0 deletions website_sale_hide_price/models/res_config_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"

website_hide_price = fields.Boolean(
string="Hide prices on website",
related="website_id.website_hide_price",
readonly=False,
)
website_hide_price_default_message = fields.Char(
related="website_id.website_hide_price_default_message",
readonly=False,
Expand Down
10 changes: 9 additions & 1 deletion website_sale_hide_price/models/website.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
class Website(models.Model):
_inherit = "website"

website_hide_price = fields.Boolean(
string="Hide prices on website",
copy=False,
help="Hide price at website level",
)
website_show_price = fields.Boolean(compute="_compute_website_show_price")
website_hide_price_default_message = fields.Char(
string="Default Hidden price message",
Expand All @@ -18,4 +23,7 @@ class Website(models.Model):

def _compute_website_show_price(self):
for rec in self:
rec.website_show_price = request.env.user.partner_id.website_show_price
rec.website_show_price = (
not rec.website_hide_price
or request.env.user.partner_id.website_show_price
)
5 changes: 5 additions & 0 deletions website_sale_hide_price/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@ Hide prices at product level:
#. In the *Shop* section you have the option *Hide prices on website*.
#. You can optionally set a message that will be displayed when the prices are
hidden.

If you want to hide prices at website level

#. Go to *Website > Configuration > Settings* and choose the website to hide the prices.
#. In the *Shop - Products* section you have the option *Hide prices on website*
6 changes: 5 additions & 1 deletion website_sale_hide_price/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@

* `Factor Libre <https://factorlibre.com>`:

* Pablo De Andrés <[email protected]>
* Pablo De Andrés <[email protected]>

* `Sodexis <https://sodexis.com>`:

* Karthik <[email protected]>
4 changes: 0 additions & 4 deletions website_sale_hide_price/readme/ROADMAP.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
- This feature doesn't support multi website. The default behavior is to hide the prices
along every website. It could be modified the boolean field on the partner to a many2many
relation between res_partner and website_website, so that this price-hiding feature might
be made website-dependant.
- This module is incompatible with the website_sale_stock_force_block module because it
makes changes to the same attributes in the website_sale.products_add_to_cart template.
15 changes: 10 additions & 5 deletions website_sale_hide_price/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Website Sale Hide Price</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:2024f5968fe783275d5042d5cbe4031b434346af33881f33c0a2e390013a80a0
!! source digest: sha256:d43ba3760f368211c94b26ebdcd3ff06f965b92f55cd4766d6c95ca45cc0265c
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/e-commerce/tree/16.0/website_sale_hide_price"><img alt="OCA/e-commerce" src="https://img.shields.io/badge/github-OCA%2Fe--commerce-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/e-commerce-16-0/e-commerce-16-0-website_sale_hide_price"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/e-commerce&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module allows to have hidden product prices on the website store.</p>
Expand Down Expand Up @@ -410,6 +410,11 @@ <h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
<li>You can optionally set a message that will be displayed when the prices are
hidden.</li>
</ol>
<p>If you want to hide prices at website level</p>
<ol class="arabic simple">
<li>Go to <em>Website &gt; Configuration &gt; Settings</em> and choose the website to hide the prices.</li>
<li>In the <em>Shop - Products</em> section you have the option <em>Hide prices on website</em></li>
</ol>
</div>
<div class="section" id="usage">
<h1><a class="toc-backref" href="#toc-entry-2">Usage</a></h1>
Expand All @@ -425,10 +430,6 @@ <h1><a class="toc-backref" href="#toc-entry-2">Usage</a></h1>
<div class="section" id="known-issues-roadmap">
<h1><a class="toc-backref" href="#toc-entry-3">Known issues / Roadmap</a></h1>
<ul class="simple">
<li>This feature doesn’t support multi website. The default behavior is to hide the prices
along every website. It could be modified the boolean field on the partner to a many2many
relation between res_partner and website_website, so that this price-hiding feature might
be made website-dependant.</li>
<li>This module is incompatible with the website_sale_stock_force_block module because it
makes changes to the same attributes in the website_sale.products_add_to_cart template.</li>
</ul>
Expand Down Expand Up @@ -463,6 +464,10 @@ <h2><a class="toc-backref" href="#toc-entry-7">Contributors</a></h2>
<li>Pablo De Andrés &lt;<a class="reference external" href="mailto:pablo.deandres&#64;factorlibre.com">pablo.deandres&#64;factorlibre.com</a>&gt;</li>
</ul>
</li>
<li><cite>Sodexis &lt;https://sodexis.com&gt;</cite>:<ul>
<li>Karthik &lt;<a class="reference external" href="mailto:karthik&#64;sodexis.com">karthik&#64;sodexis.com</a>&gt;</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
17 changes: 16 additions & 1 deletion website_sale_hide_price/views/res_config_settings_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,25 @@
<div
class="col-12 col-lg-6 o_setting_box"
id="website_sale_hide_price"
title="Set a default text when hiding prices"
title="Hide prices at website level"
>
<div class="o_setting_left_pane">
<field name="website_hide_price" />
</div>
<div class="o_setting_right_pane">
<label for="website_hide_price" />
<div class="text-muted">
Hide the product prices for everyone only on this website
</div>
</div>
</div>

<div
class="col-12 col-lg-6 o_setting_box"
id="website_sale_hide_price_message"
title="Set a default text when hiding prices"
>
<div class="o_setting_left_pane">
</div>
<div class="o_setting_right_pane">
<label for="website_hide_price_default_message" />
Expand Down
30 changes: 25 additions & 5 deletions website_sale_hide_price/views/website_sale_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
>
<attribute
name="t-cache"
>pricelist,products,website,website.website_show_price</attribute>
add="website,website.website_show_price"
separator=","
/>
</xpath>
</template>
<template id="product_price" inherit_id="website_sale.product_price">
Expand All @@ -32,10 +34,15 @@
<!-- adding website, website.website_show_price and product.website_hide_price to t-cache in order to update cache if parameter modified
this is needed if you connect with a different user that should not see the prices
see https://github.com/OCA/e-commerce/issues/818 -->
<xpath expr="t[@t-cache='pricelist,product']" position="attributes">
<attribute
<xpath
expr="//t[starts-with(@t-cache, 'pricelist,product')]"
position="attributes"
>
<attribute
name="t-cache"
>pricelist,product,website,website.website_show_price,product.website_hide_price</attribute>
add="website,website.website_show_price,product.website_hide_price"
separator=","
/>
</xpath>
<xpath expr="//a[@id='add_to_cart']" position="before">
<t t-set="user_authenticated" t-value="user_id != website.user_id" />
Expand All @@ -51,7 +58,7 @@
<xpath expr="//a[@id='add_to_cart']" position="attributes">
<attribute name="t-if">
website and website.website_show_price and not product.website_hide_price
</attribute>
</attribute>
</xpath>
</template>
<template id="product_quantity" inherit_id="website_sale.product_quantity">
Expand Down Expand Up @@ -97,4 +104,17 @@
>website and website.website_show_price and not product.website_hide_price</attribute>
</xpath>
</template>
<template id="product_variants" inherit_id="website_sale.product_variants">
<xpath
expr="//span[hasclass('sign_badge_price_extra')]/.."
position="attributes"
>
<attribute
name="t-if"
separator=" and "
add="website.website_show_price and not combination_info['website_hide_price']"
/>
</xpath>
</template>

</odoo>

0 comments on commit 3984fee

Please sign in to comment.