Skip to content

Commit

Permalink
[ADD] sale_pricelist_display_surcharge
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidJForgeFlow committed Feb 3, 2025
1 parent c52b9a2 commit 2fe603f
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 0 deletions.
Empty file.
1 change: 1 addition & 0 deletions sale_pricelist_display_surcharge/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
14 changes: 14 additions & 0 deletions sale_pricelist_display_surcharge/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2023 ForgeFlow S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Sale Pricelist Display Surcharge",
"summary": """
This module shows to the customer the surcharges if wanted.""",
"version": "16.0.1.0.0",
"license": "AGPL-3",
"author": "ForgeFlow, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/sale-workflow",
"depends": ["sale"],
"data": ["views/product_pricelist_item_views.xml"],
}
2 changes: 2 additions & 0 deletions sale_pricelist_display_surcharge/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import sale_order_line
from . import product_pricelist_item
13 changes: 13 additions & 0 deletions sale_pricelist_display_surcharge/models/product_pricelist_item.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2023 ForgeFlow S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields, models


class PricelistItem(models.Model):
_inherit = "product.pricelist.item"

show_surcharge = fields.Boolean(
default=False,
help="If enabled, when the price is computed will show the customer the surcharge.",
)
39 changes: 39 additions & 0 deletions sale_pricelist_display_surcharge/models/sale_order_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright 2023 ForgeFlow S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, models


class SaleOrderLine(models.Model):

_inherit = "sale.order.line"

@api.depends("product_id", "product_uom", "product_uom_qty")
def _compute_discount(self):
res = super()._compute_discount()
for line in self:
if (
not line.discount
and (
line.order_id.pricelist_id
and line.order_id.pricelist_id.discount_policy == "without_discount"
)
and line.pricelist_item_id
and line.pricelist_item_id.show_surcharge
):
pricelist_price = line._get_pricelist_price()
base_price = line._get_pricelist_price_before_discount()

Check warning on line 25 in sale_pricelist_display_surcharge/models/sale_order_line.py

View check run for this annotation

Codecov / codecov/patch

sale_pricelist_display_surcharge/models/sale_order_line.py#L24-L25

Added lines #L24 - L25 were not covered by tests

if base_price != 0: # Avoid division by zero
line.discount = (base_price - pricelist_price) / base_price * 100

Check warning on line 28 in sale_pricelist_display_surcharge/models/sale_order_line.py

View check run for this annotation

Codecov / codecov/patch

sale_pricelist_display_surcharge/models/sale_order_line.py#L28

Added line #L28 was not covered by tests
return res

def _get_display_price(self):
res = super()._get_display_price()
if (
self.order_id.pricelist_id.discount_policy == "without_discount"
and self.pricelist_item_id
and self.pricelist_item_id.show_surcharge
):
return self._get_pricelist_price_before_discount()

Check warning on line 38 in sale_pricelist_display_surcharge/models/sale_order_line.py

View check run for this annotation

Codecov / codecov/patch

sale_pricelist_display_surcharge/models/sale_order_line.py#L38

Added line #L38 was not covered by tests
return res
1 change: 1 addition & 0 deletions sale_pricelist_display_surcharge/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* David Jiménez <[email protected]>
3 changes: 3 additions & 0 deletions sale_pricelist_display_surcharge/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
In standard Odoo the discount is only displayed if it benefits the customer.
In the case of wanting to always show the discount (for example a surcharge),
this module allows to choose whether to show or not.
6 changes: 6 additions & 0 deletions sale_pricelist_display_surcharge/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

To use this module, you need to:

#. Go on a pricelist
#. Set a pricelist rule
#. Check the "Show Surcharge" box, from now when using this rule the discount will be always displayed (if the pricelist is checked as show to customers).
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<odoo>
<record id="product_pricelist_item_form_view_surcharge" model="ir.ui.view">
<field name="name">product.pricelist.item.form - surcharge</field>
<field name="model">product.pricelist.item</field>
<field name="inherit_id" ref="product.product_pricelist_item_form_view" />
<field name="arch" type="xml">
<group name="pricelist_rule_limits" position="inside">
<field name="show_surcharge" />
</group>
</field>
</record>
</odoo>
6 changes: 6 additions & 0 deletions setup/sale_pricelist_display_surcharge/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,
)

0 comments on commit 2fe603f

Please sign in to comment.