Skip to content

Commit

Permalink
[ADD] website_sale_product_pricelist_alternative
Browse files Browse the repository at this point in the history
  • Loading branch information
santostelmo committed Dec 6, 2024
1 parent 5a188cc commit c08d55a
Show file tree
Hide file tree
Showing 13 changed files with 651 additions and 0 deletions.
6 changes: 6 additions & 0 deletions setup/website_sale_product_pricelist_alternative/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
79 changes: 79 additions & 0 deletions website_sale_product_pricelist_alternative/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
==========================================
Website Sale Product Pricelist Alternative
==========================================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fwebsite-lightgray.png?logo=github
:target: https://github.com/OCA/website/tree/16.0/website_sale_product_pricelist_alternative
:alt: OCA/website
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/website-16-0/website-16-0-website_sale_product_pricelist_alternative
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/webui/builds.html?repo=OCA/website&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

Based on `product_pricelist_alternative` (https://github.com/OCA/product-attribute/tree/16.0/product_pricelist_alternative), it allows you to show in the website alternative vs original product prices.

**Table of contents**

.. contents::
:local:

Usage
=====

In product pricelist select discount policy as `Show public price and discount to the customer`.
In the pricelist used in the website, you can set the alternative pricelist with the discounted price.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/website/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/website/issues/new?body=module:%20website_sale_product_pricelist_alternative%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* Camptocamp

Contributors
~~~~~~~~~~~~

* Telmo Santos <telmo.santos@camptocamp.com>

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

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/website <https://github.com/OCA/website/tree/16.0/website_sale_product_pricelist_alternative>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions website_sale_product_pricelist_alternative/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
20 changes: 20 additions & 0 deletions website_sale_product_pricelist_alternative/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2024 Camptocamp (<https://www.camptocamp.com>).
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

{
"name": "Website Sale Product Pricelist Alternative",
"version": "16.0.1.0.0",
"development_status": "Beta",
"category": "Website",
"summary": "Show product alternative price versus original price on website cart",
"author": "Camptocamp, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/website",
"license": "AGPL-3",
"depends": [
"website_sale",
"product_pricelist_alternative",
],
"data": [],
"installable": True,
"auto_install": False,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import product_template
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Copyright 2024 Camptocamp (<https://www.camptocamp.com>).
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import models


class ProductTemplate(models.Model):
_inherit = "product.template"

def _get_sales_prices(self, pricelist):
if (
pricelist
and pricelist.discount_policy == "without_discount"
and self.env.context.get("website_id")
):
pricelist = pricelist.with_context(skip_alternative_pricelist=True)
res = super()._get_sales_prices(pricelist)
for product_id in res:
res[product_id]["base_price"] = res[product_id]["price_reduce"]
pricelist = pricelist.with_context(skip_alternative_pricelist=False)
product = self.env["product.template"].browse(product_id)
res[product_id]["price_reduce"] = pricelist._get_product_price(
product, 1.0
)
return res
return super()._get_sales_prices(pricelist)

Check warning on line 26 in website_sale_product_pricelist_alternative/models/product_template.py

View check run for this annotation

Codecov / codecov/patch

website_sale_product_pricelist_alternative/models/product_template.py#L26

Added line #L26 was not covered by tests

def _get_combination_info(
self,
combination=False,
product_id=False,
add_qty=1,
pricelist=False,
parent_combination=False,
only_template=False,
):
if (
pricelist
and pricelist.discount_policy == "without_discount"
and self.env.context.get("website_id")
):
# Compute original price
pricelist = pricelist.with_context(skip_alternative_pricelist=True)
combination_info = super(ProductTemplate, self)._get_combination_info(
combination,
product_id,
add_qty,
pricelist,
parent_combination,
only_template,
)
combination_info["list_price"] = combination_info["price"]
combination_info["base_price"] = combination_info["price"]
# Compute alternative price
pricelist = pricelist.with_context(skip_alternative_pricelist=False)
product = self.env["product.product"].browse(combination_info["product_id"])
combination_info["price"] = pricelist._get_product_price(
product, quantity=self.env.context.get("quantity", add_qty)
)
combination_info["has_discounted_price"] = (
pricelist.currency_id.compare_amounts(combination_info["list_price"], combination_info["price"]) == 1
)
return combination_info
return super()._get_combination_info(

Check warning on line 64 in website_sale_product_pricelist_alternative/models/product_template.py

View check run for this annotation

Codecov / codecov/patch

website_sale_product_pricelist_alternative/models/product_template.py#L64

Added line #L64 was not covered by tests
combination,
product_id,
add_qty,
pricelist,
parent_combination,
only_template,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Telmo Santos <telmo.santos@camptocamp.com>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Based on `product_pricelist_alternative` (https://github.com/OCA/product-attribute/tree/16.0/product_pricelist_alternative), it allows you to show in the website alternative vs original product prices.
2 changes: 2 additions & 0 deletions website_sale_product_pricelist_alternative/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
In product pricelist select discount policy as `Show public price and discount to the customer`.
In the pricelist used in the website, you can set the alternative pricelist with the discounted price.
Loading

0 comments on commit c08d55a

Please sign in to comment.