Initial commit: Odoo 18.0-20251222 extra-addons
Some checks failed
pre-commit / pre-commit (push) Has been cancelled
tests / Detect unreleased dependencies (push) Has been cancelled
tests / test with OCB (push) Has been cancelled
tests / test with Odoo (push) Has been cancelled

This commit is contained in:
tocmo0nlord
2026-03-13 20:43:25 +00:00
parent 36e847a7df
commit adbe430761
9472 changed files with 1265727 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from . import product_product
from . import product_template
from . import res_partner
from . import sale_order
from . import sale_order_line

View File

@@ -0,0 +1,12 @@
# Copyright 2021 - Pierre Verkest
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models
class ProductProduct(models.Model):
_inherit = "product.product"
bypass_general_discount = fields.Boolean(
help="If this checkbox is not ticked, it means changing general discount on "
"sale order will impact sale order lines with this related product.",
)

View File

@@ -0,0 +1,36 @@
# Copyright 2021 - Pierre Verkest
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
class ProductTemplate(models.Model):
_inherit = "product.template"
bypass_general_discount = fields.Boolean(
compute="_compute_bypass_general_discount",
inverse="_inverse_bypass_general_discount",
search="_search_bypass_general_discount",
help="If this checkbox is not ticked, it means changing general discount on "
"sale order will impact sale order lines with this related product.",
)
def _search_bypass_general_discount(self, operator, value):
templates = self.with_context(active_test=False).search(
[("product_variant_ids.bypass_general_discount", operator, value)]
)
return [("id", "in", templates.ids)]
@api.depends("product_variant_ids.bypass_general_discount")
def _compute_bypass_general_discount(self):
self.bypass_general_discount = False
for template in self:
if len(template.product_variant_ids) == 1:
template.bypass_general_discount = (
template.product_variant_ids.bypass_general_discount
)
def _inverse_bypass_general_discount(self):
if len(self.product_variant_ids) == 1:
self.product_variant_ids.bypass_general_discount = (
self.bypass_general_discount
)

View File

@@ -0,0 +1,17 @@
# Copyright 2018 Tecnativa - Sergio Teruel
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
class ResPartner(models.Model):
_inherit = "res.partner"
sale_discount = fields.Float(
digits="Discount",
company_dependent=True,
)
@api.model
def _commercial_fields(self):
return super()._commercial_fields() + ["sale_discount"]

View File

@@ -0,0 +1,44 @@
# Copyright 2018 Tecnativa - Sergio Teruel
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from lxml import etree
from odoo import api, fields, models
class SaleOrder(models.Model):
_inherit = "sale.order"
general_discount = fields.Float(
compute="_compute_general_discount",
store=True,
readonly=False,
digits="Discount",
)
@api.depends("partner_id")
def _compute_general_discount(self):
for so in self:
so.general_discount = so.partner_id.sale_discount
@api.model
def get_view(self, view_id=None, view_type="form", **options):
"""The purpose of this is to write a context on "order_line" field
respecting other contexts on this field.
There is a PR (https://github.com/odoo/odoo/pull/26607) to odoo for
avoiding this. If merged, remove this method and add the attribute
in the field.
"""
res = super().get_view(view_id=view_id, view_type=view_type, **options)
if view_type == "form":
order_xml = etree.XML(res["arch"])
order_line_fields = order_xml.xpath("//field[@name='order_line']")
if order_line_fields:
order_line_field = order_line_fields[0]
context = order_line_field.attrib.get("context", "{}").replace(
"{",
"{'default_discount': general_discount, ",
1,
)
order_line_field.attrib["context"] = context
res["arch"] = etree.tostring(order_xml)
return res

View File

@@ -0,0 +1,29 @@
# Copyright 2018 Tecnativa - Sergio Teruel
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
class SaleOrderLine(models.Model):
_inherit = "sale.order.line"
discount = fields.Float(
compute="_compute_discount",
store=True,
readonly=False,
)
@api.depends("order_id", "order_id.general_discount")
def _compute_discount(self):
res = super()._compute_discount()
for line in self:
# We check the value of general_discount on origin too to cover
# the case where a discount was set to a value != 0 and then
# set again to 0 to remove the discount on all the lines at the same
# time
if not line.product_id.bypass_general_discount and (
line.order_id.general_discount or line.order_id._origin.general_discount
):
line.discount = line.order_id.general_discount
else:
line.discount = 0
return res