Initial commit: OCA Mrp packages (117 packages)

This commit is contained in:
Ernad Husremovic 2025-08-29 15:43:05 +02:00
commit 277e84fd7a
4403 changed files with 395154 additions and 0 deletions

View file

@ -0,0 +1,4 @@
from . import mrp_bom
from . import mrp_production
from . import mrp_workorder
from . import product

View file

@ -0,0 +1,53 @@
# Copyright 2022 Tecnativa - Víctor Martínez
# Copyright 2023 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import api, models
from odoo.tools.safe_eval import safe_eval
class MrpBom(models.Model):
_inherit = "mrp.bom"
@api.model
def _get_components_ids(self, products, recursive=False):
"""Gets an objet with the ids of the components, within two arrays:
'product_template_ids' and 'product_product_ids'.
Set recursive to get ids of child boms."""
product_ids = []
boms_per_product = super()._bom_find(products)
for bom in boms_per_product.values():
for bom_line_id in bom.bom_line_ids:
product_ids.append(bom_line_id.product_id.id)
if recursive:
subcomponents = self._get_components_ids(
bom_line_id.product_id,
recursive=recursive,
)
product_ids.extend(subcomponents)
return product_ids
def action_see_bom_documents(self):
product_ids = self._get_components_ids(
self.product_id or self.product_tmpl_id.product_variant_ids, True
)
products = self.env["product.product"].search([("id", "in", product_ids)])
return products._action_show_attachments()
def action_show_product_attachments(self):
if self.product_id:
return self.product_id._action_show_attachments()
return self.product_tmpl_id._action_show_attachments()
def _action_show_attachments(self):
"""Returns the action to show the attachments linked to the bom record."""
domain = [
("res_model", "=", "mrp.bom"),
("res_id", "in", self.ids),
]
action = self.env["ir.actions.actions"]._for_xml_id("base.action_attachment")
context = action.get("context", "{}")
context = safe_eval(context)
context["create"] = False
context["edit"] = False
action.update({"domain": domain, "context": context})
return action

View file

@ -0,0 +1,13 @@
# Copyright 2023 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import models
class MrpProduction(models.Model):
_inherit = "mrp.production"
def action_show_attachments(self):
return self.product_id._action_show_attachments()
def action_show_bom_attachments(self):
return self.bom_id._action_show_attachments()

View file

@ -0,0 +1,27 @@
# Copyright 2021 Tecnativa - Víctor Martínez
# Copyright 2023 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import _, models
from odoo.exceptions import UserError
class MrpWorkorder(models.Model):
_inherit = "mrp.workorder"
def action_see_workorder_attachments(self):
error = []
for product in self.mapped("product_id"):
if (
product.message_attachment_count == 0
and product.product_tmpl_id.message_attachment_count == 0
):
error.append(product.display_name)
if error:
raise UserError(
_("%(error_count)d Product(s) without drawing:\n%(error_msg)s")
% {"error_count": len(error), "error_msg": "\n".join(error)}
)
return self.product_id._action_show_attachments()
def action_see_workorder_bom_attachments(self):
return self.production_id.bom_id._action_show_attachments()

View file

@ -0,0 +1,53 @@
# Copyright 2022 Tecnativa - Víctor Martínez
# Copyright 2023 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import fields, models
class ProductTemplate(models.Model):
_inherit = "product.template"
def action_see_bom_documents(self):
return fields.first(self.bom_ids).action_see_bom_documents()
def action_see_bom_attachments(self):
return self.bom_ids._action_show_attachments()
def _action_show_attachments(self):
"""Returns the action to show the attachments linked to the products
recordset or to their templates.
"""
domain = [
("res_model", "=", "product.template"),
("res_id", "in", self.ids),
]
action = self.env["ir.actions.actions"]._for_xml_id("base.action_attachment")
action.update({"domain": domain})
return action
class ProductProduct(models.Model):
_inherit = "product.product"
def action_see_bom_documents(self):
return fields.first(self.bom_ids).action_see_bom_documents()
def action_see_bom_attachments(self):
return self.bom_ids._action_show_attachments()
def _action_show_attachments(self):
"""Returns the action to show the attachments linked to the products
recordset or to their templates.
"""
domain = [
"|",
"&",
("res_model", "=", "product.product"),
("res_id", "in", self.ids),
"&",
("res_model", "=", "product.template"),
("res_id", "in", self.product_tmpl_id.ids),
]
action = self.env["ir.actions.actions"]._for_xml_id("base.action_attachment")
action.update({"domain": domain})
return action