-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] sale_pricelist_display_surcharge
- Loading branch information
1 parent
c52b9a2
commit 2fe603f
Showing
12 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
13
sale_pricelist_display_surcharge/models/product_pricelist_item.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
39
sale_pricelist_display_surcharge/models/sale_order_line.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
|
||
if base_price != 0: # Avoid division by zero | ||
line.discount = (base_price - pricelist_price) / base_price * 100 | ||
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() | ||
return res |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* David Jiménez <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). |
12 changes: 12 additions & 0 deletions
12
sale_pricelist_display_surcharge/views/product_pricelist_item_views.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
1 change: 1 addition & 0 deletions
1
setup/sale_pricelist_display_surcharge/odoo/addons/sale_pricelist_display_surcharge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../sale_pricelist_display_surcharge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |