Initial commit: Odoo 18.0-20251222 extra-addons
This commit is contained in:
2
product_form_sale_link/models/__init__.py
Executable file
2
product_form_sale_link/models/__init__.py
Executable file
@@ -0,0 +1,2 @@
|
||||
from . import product_template
|
||||
from . import product_product
|
||||
31
product_form_sale_link/models/product_product.py
Executable file
31
product_form_sale_link/models/product_product.py
Executable file
@@ -0,0 +1,31 @@
|
||||
# Copyright 2022 ForgeFlow S.L. (https://www.forgeflow.com)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class ProductProduct(models.Model):
|
||||
_inherit = "product.product"
|
||||
|
||||
sale_lines_count = fields.Integer(compute="_compute_sale_lines_count")
|
||||
|
||||
def _compute_sale_lines_count(self):
|
||||
if (
|
||||
not self.env.user.has_group("sales_team.group_sale_salesman")
|
||||
or not self.ids
|
||||
):
|
||||
self.sale_lines_count = 0.0
|
||||
return
|
||||
domain = [
|
||||
("state", "in", ["sale", "done"]),
|
||||
("product_id", "in", self.ids),
|
||||
("company_id", "in", self.env.companies.ids),
|
||||
]
|
||||
sale_line_data = self.env["sale.order.line"].read_group(
|
||||
domain, ["product_id"], ["product_id"]
|
||||
)
|
||||
mapped_data = {
|
||||
m["product_id"][0]: m["product_id_count"] for m in sale_line_data
|
||||
}
|
||||
for product in self:
|
||||
product.sale_lines_count = mapped_data.get(product.id, 0)
|
||||
18
product_form_sale_link/models/product_template.py
Executable file
18
product_form_sale_link/models/product_template.py
Executable file
@@ -0,0 +1,18 @@
|
||||
# Copyright 2022 ForgeFlow S.L. (https://www.forgeflow.com)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class ProductTemplate(models.Model):
|
||||
_inherit = "product.template"
|
||||
|
||||
sale_lines_count = fields.Float(compute="_compute_sale_lines_count")
|
||||
|
||||
@api.depends("product_variant_ids.sale_lines_count")
|
||||
def _compute_sale_lines_count(self):
|
||||
for product in self:
|
||||
product.sale_lines_count = sum(
|
||||
p.sale_lines_count
|
||||
for p in product.with_context(active_test=False).product_variant_ids
|
||||
)
|
||||
Reference in New Issue
Block a user