Initial commit: Odoo 18.0-20251222 extra-addons
This commit is contained in:
4
sale_discount_display_amount/models/__init__.py
Executable file
4
sale_discount_display_amount/models/__init__.py
Executable file
@@ -0,0 +1,4 @@
|
||||
from . import res_company
|
||||
from . import res_config_settings
|
||||
from . import sale_order
|
||||
from . import sale_order_line
|
||||
8
sale_discount_display_amount/models/res_company.py
Executable file
8
sale_discount_display_amount/models/res_company.py
Executable file
@@ -0,0 +1,8 @@
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class ResCompany(models.Model):
|
||||
_inherit = "res.company"
|
||||
|
||||
display_discount_with_tax = fields.Boolean(string="Show the Discount with TAX")
|
||||
report_total_without_discount = fields.Boolean()
|
||||
18
sale_discount_display_amount/models/res_config_settings.py
Executable file
18
sale_discount_display_amount/models/res_config_settings.py
Executable file
@@ -0,0 +1,18 @@
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class ResConfigSettings(models.TransientModel):
|
||||
_inherit = "res.config.settings"
|
||||
|
||||
display_discount_with_tax = fields.Boolean(
|
||||
string="Show the Discount with TAX",
|
||||
help="Check this field to show the Discount with TAX",
|
||||
related="company_id.display_discount_with_tax",
|
||||
readonly=False,
|
||||
)
|
||||
report_total_without_discount = fields.Boolean(
|
||||
string="Report Total Without Discount",
|
||||
help='Display "Total without discount" in report',
|
||||
related="company_id.report_total_without_discount",
|
||||
readonly=False,
|
||||
)
|
||||
67
sale_discount_display_amount/models/sale_order.py
Executable file
67
sale_discount_display_amount/models/sale_order.py
Executable file
@@ -0,0 +1,67 @@
|
||||
# Copyright 2018 ACSONE SA/NV
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class SaleOrder(models.Model):
|
||||
_inherit = "sale.order"
|
||||
|
||||
display_discount_with_tax = fields.Boolean(
|
||||
name="Show the Discount with TAX",
|
||||
help="Check this field to show the Discount with TAX",
|
||||
related="company_id.display_discount_with_tax",
|
||||
)
|
||||
discount_total = fields.Monetary(
|
||||
compute="_compute_discount_total",
|
||||
name="Discount total",
|
||||
currency_field="currency_id",
|
||||
store=True,
|
||||
)
|
||||
discount_subtotal = fields.Monetary(
|
||||
compute="_compute_discount_total",
|
||||
name="Discount Subtotal",
|
||||
currency_field="currency_id",
|
||||
store=True,
|
||||
)
|
||||
price_subtotal_no_discount = fields.Monetary(
|
||||
compute="_compute_discount_total",
|
||||
name="Subtotal Without Discount",
|
||||
currency_field="currency_id",
|
||||
store=True,
|
||||
)
|
||||
price_total_no_discount = fields.Monetary(
|
||||
compute="_compute_discount_total",
|
||||
name="Total Without Discount",
|
||||
currency_field="currency_id",
|
||||
store=True,
|
||||
)
|
||||
|
||||
@api.model
|
||||
def _get_compute_discount_total_depends(self):
|
||||
return [
|
||||
"order_line.discount_total",
|
||||
"order_line.discount_subtotal",
|
||||
"order_line.price_subtotal_no_discount",
|
||||
"order_line.price_total_no_discount",
|
||||
]
|
||||
|
||||
@api.depends(lambda self: self._get_compute_discount_total_depends())
|
||||
def _compute_discount_total(self):
|
||||
for order in self:
|
||||
discount_total = sum(order.order_line.mapped("discount_total"))
|
||||
discount_subtotal = sum(order.order_line.mapped("discount_subtotal"))
|
||||
price_subtotal_no_discount = sum(
|
||||
order.order_line.mapped("price_subtotal_no_discount")
|
||||
)
|
||||
price_total_no_discount = sum(
|
||||
order.order_line.mapped("price_total_no_discount")
|
||||
)
|
||||
order.update(
|
||||
{
|
||||
"discount_total": discount_total,
|
||||
"discount_subtotal": discount_subtotal,
|
||||
"price_subtotal_no_discount": price_subtotal_no_discount,
|
||||
"price_total_no_discount": price_total_no_discount,
|
||||
}
|
||||
)
|
||||
73
sale_discount_display_amount/models/sale_order_line.py
Executable file
73
sale_discount_display_amount/models/sale_order_line.py
Executable file
@@ -0,0 +1,73 @@
|
||||
# Copyright 2018 ACSONE SA/NV
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class SaleOrderLine(models.Model):
|
||||
_inherit = "sale.order.line"
|
||||
|
||||
discount_total = fields.Monetary(
|
||||
compute="_compute_amount",
|
||||
store=True,
|
||||
precompute=True,
|
||||
)
|
||||
discount_subtotal = fields.Monetary(
|
||||
compute="_compute_amount",
|
||||
store=True,
|
||||
precompute=True,
|
||||
)
|
||||
price_subtotal_no_discount = fields.Monetary(
|
||||
compute="_compute_amount",
|
||||
string="Subtotal Without Discount",
|
||||
store=True,
|
||||
precompute=True,
|
||||
)
|
||||
price_total_no_discount = fields.Monetary(
|
||||
compute="_compute_amount",
|
||||
string="Total Without Discount",
|
||||
store=True,
|
||||
precompute=True,
|
||||
)
|
||||
|
||||
def _update_discount_display_fields(self):
|
||||
for line in self:
|
||||
line.price_subtotal_no_discount = 0
|
||||
line.price_total_no_discount = 0
|
||||
line.discount_total = 0
|
||||
if not line.discount:
|
||||
line.price_subtotal_no_discount = line.price_subtotal
|
||||
line.price_total_no_discount = line.price_total
|
||||
continue
|
||||
price = line.price_unit
|
||||
taxes = line.tax_id.compute_all(
|
||||
price,
|
||||
line.order_id.currency_id,
|
||||
line.product_uom_qty,
|
||||
product=line.product_id,
|
||||
partner=line.order_id.partner_shipping_id,
|
||||
)
|
||||
|
||||
price_subtotal_no_discount = taxes["total_excluded"]
|
||||
price_total_no_discount = taxes["total_included"]
|
||||
discount_total = price_total_no_discount - line.price_total
|
||||
discount_subtotal = price_subtotal_no_discount - line.price_subtotal
|
||||
|
||||
line.update(
|
||||
{
|
||||
"discount_total": discount_total,
|
||||
"discount_subtotal": discount_subtotal,
|
||||
"price_subtotal_no_discount": price_subtotal_no_discount,
|
||||
"price_total_no_discount": price_total_no_discount,
|
||||
}
|
||||
)
|
||||
|
||||
@api.model
|
||||
def _get_compute_amount_depends(self):
|
||||
return ["product_uom_qty", "discount", "price_unit", "tax_id"]
|
||||
|
||||
@api.depends(lambda self: self._get_compute_amount_depends())
|
||||
def _compute_amount(self):
|
||||
res = super()._compute_amount()
|
||||
self._update_discount_display_fields()
|
||||
return res
|
||||
Reference in New Issue
Block a user