Initial commit: Odoo 18.0-20251222 extra-addons
This commit is contained in:
2
sale_pricelist_display_surcharge/models/__init__.py
Executable file
2
sale_pricelist_display_surcharge/models/__init__.py
Executable file
@@ -0,0 +1,2 @@
|
||||
from . import sale_order_line
|
||||
from . import product_pricelist_item
|
||||
14
sale_pricelist_display_surcharge/models/product_pricelist_item.py
Executable file
14
sale_pricelist_display_surcharge/models/product_pricelist_item.py
Executable file
@@ -0,0 +1,14 @@
|
||||
# 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.",
|
||||
)
|
||||
31
sale_pricelist_display_surcharge/models/sale_order_line.py
Executable file
31
sale_pricelist_display_surcharge/models/sale_order_line.py
Executable file
@@ -0,0 +1,31 @@
|
||||
# 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.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.pricelist_item_id and self.pricelist_item_id.show_surcharge:
|
||||
return self._get_pricelist_price_before_discount()
|
||||
return res
|
||||
Reference in New Issue
Block a user