Merge PR #1203 into 16.0

Signed-off-by LoisRForgeFlow
This commit is contained in:
OCA-git-bot
2024-06-17 09:01:19 +00:00
7 changed files with 113 additions and 106 deletions

View File

@@ -7,7 +7,7 @@ MRP BoM Hierarchy
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:f82342db68fac74511be10345e468d4de88b2c5cd1040c7bda76482629ac03c4
!! source digest: sha256:0056b6f5f7c205257b3021d59fc6e40b3ad4143fa7c916ad432a4dbcc0f101f9
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
@@ -68,6 +68,7 @@ Contributors
* Jordi Ballester Alomar <jordi.ballester@forgeflow.com>
* Miquel Raïch Regué <miquel.raich@forgeflow.com>
* Quentin Dupont <quentin.dupont@grap.coop>
Maintainers
~~~~~~~~~~~

View File

@@ -6,12 +6,13 @@
"summary": "Make it easy to navigate through BoM hierarchy.",
"version": "16.0.1.0.1",
"author": "ForgeFlow, Odoo Community Association (OCA)",
"contributors": "Grap",
"category": "Manufacturing",
"depends": ["mrp"],
"website": "https://github.com/OCA/manufacture",
"license": "AGPL-3",
"data": [
"view/mrp.xml",
"view/mrp_bom.xml",
],
"installable": True,
"auto_install": False,

View File

@@ -1 +1,2 @@
from . import mrp_bom
from . import mrp_bom_line

View File

@@ -88,7 +88,7 @@ class MrpBom(models.Model):
"product_id.product_tmpl_id.default_code",
"product_tmpl_id.default_code",
)
def _compute_internal_reference(self):
def _compute_product_default_code(self):
for bom in self:
bom.product_default_code = (
bom.product_id.default_code
@@ -114,7 +114,7 @@ class MrpBom(models.Model):
)
product_default_code = fields.Char(
string="Internal Reference",
compute="_compute_internal_reference",
compute="_compute_product_default_code",
store="True",
)
@@ -164,105 +164,3 @@ class MrpBom(models.Model):
"[('id', 'in', [" + ",".join(map(str, product_bom_ids.ids)) + "])]"
)
return res
class MrpBomLine(models.Model):
_inherit = "mrp.bom.line"
has_bom = fields.Boolean(
string="Has sub BoM",
compute="_compute_child_bom_id",
)
@api.depends("product_id", "bom_id")
def _compute_child_bom_id(self):
res = super()._compute_child_bom_id()
for line in self:
line.has_bom = bool(line.child_bom_id)
return res
def action_open_product_bom_tree_view(self):
self.ensure_one()
res = self.env["ir.actions.actions"]._for_xml_id("mrp.mrp_bom_form_action")
if len(self.child_bom_id) == 1:
res["res_id"] = self.child_bom_id[0].id
res["views"] = [(False, "form")]
else:
res["domain"] = (
"[('id', 'in', [" + ",".join(map(str, self.child_bom_id.ids)) + "])]"
)
return res
@api.model
def _bom_line_find_domain(
self,
product_tmpl=None,
product=None,
picking_type=None,
company_id=False,
bom_type=False,
):
if product:
if not product_tmpl:
product_tmpl = product.product_tmpl_id
domain = [
"|",
("product_id", "=", product.id),
"&",
("product_id", "=", False),
("product_tmpl_id", "=", product_tmpl.id),
]
elif product_tmpl:
domain = [("product_tmpl_id", "=", product_tmpl.id)]
else:
# neither product nor template, makes no sense to search
raise UserError(
_(
"You should provide either a product or "
"a product template to search a BoM Line"
)
)
if picking_type:
domain += [
"|",
("bom_id.picking_type_id", "=", picking_type.id),
("bom_id.picking_type_id", "=", False),
]
if company_id or self.env.context.get("company_id"):
domain = domain + [
"|",
("company_id", "=", False),
("company_id", "=", company_id or self.env.context.get("company_id")),
]
if bom_type:
domain += [("bom_id.type", "=", bom_type)]
# order to prioritize bom line with product_id over the one without
return domain
@api.model
def _bom_line_find(
self,
product_tmpl=None,
product=None,
picking_type=None,
company_id=False,
bom_type=False,
):
"""Finds BoM lines for particular product, picking and company"""
if (
product
and product.type == "service"
or product_tmpl
and product_tmpl.type == "service"
):
return self.env["mrp.bom.line"]
domain = self._bom_line_find_domain(
product_tmpl=product_tmpl,
product=product,
picking_type=picking_type,
company_id=company_id,
bom_type=bom_type,
)
if domain is False:
return self.env["mrp.bom.line"]
return self.search(domain, order="sequence, product_id")

View File

@@ -0,0 +1,105 @@
# Copyright 2015-22 ForgeFlow S.L. (https://www.forgeflow.com)
# Copyright (C) 2023 - Today: GRAP (http://www.grap.coop)
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo import _, api, fields, models
from odoo.exceptions import UserError
class MrpBomLine(models.Model):
_inherit = "mrp.bom.line"
has_bom = fields.Boolean(
string="Has sub BoM",
compute="_compute_has_bom",
)
@api.depends("product_id", "bom_id")
def _compute_has_bom(self):
# mrp.bom.line _compute_child_bom_id get child bom or return False
res = super()._compute_child_bom_id()
for line in self:
line.has_bom = bool(line.child_bom_id)
return res
def action_open_product_bom_tree_view(self):
self.ensure_one()
res = self.env["ir.actions.actions"]._for_xml_id("mrp.mrp_bom_form_action")
res["domain"] = (
"[('id', 'in', [" + ",".join(map(str, self.child_bom_id.ids)) + "])]"
)
return res
@api.model
def _bom_line_find_domain(
self,
product_tmpl=None,
product=None,
picking_type=None,
company_id=False,
bom_type=False,
):
if product:
if not product_tmpl:
product_tmpl = product.product_tmpl_id
domain = [
"|",
("product_id", "=", product.id),
"&",
("product_id", "=", False),
("product_tmpl_id", "=", product_tmpl.id),
]
elif product_tmpl:
domain = [("product_tmpl_id", "=", product_tmpl.id)]
else:
# neither product nor template, makes no sense to search
raise UserError(
_(
"You should provide either a product or "
"a product template to search a BoM Line"
)
)
if picking_type:
domain += [
"|",
("bom_id.picking_type_id", "=", picking_type.id),
("bom_id.picking_type_id", "=", False),
]
if company_id or self.env.context.get("company_id"):
domain = domain + [
"|",
("company_id", "=", False),
("company_id", "=", company_id or self.env.context.get("company_id")),
]
if bom_type:
domain += [("bom_id.type", "=", bom_type)]
# order to prioritize bom line with product_id over the one without
return domain
@api.model
def _bom_line_find(
self,
product_tmpl=None,
product=None,
picking_type=None,
company_id=False,
bom_type=False,
):
"""Finds BoM lines for particular product, picking and company"""
if (
product
and product.type == "service"
or product_tmpl
and product_tmpl.type == "service"
):
return self.env["mrp.bom.line"]
domain = self._bom_line_find_domain(
product_tmpl=product_tmpl,
product=product,
picking_type=picking_type,
company_id=company_id,
bom_type=bom_type,
)
if domain is False:
return self.env["mrp.bom.line"]
return self.search(domain, order="sequence, product_id")

View File

@@ -1,2 +1,3 @@
* Jordi Ballester Alomar <jordi.ballester@forgeflow.com>
* Miquel Raïch Regué <miquel.raich@forgeflow.com>
* Quentin Dupont <quentin.dupont@grap.coop>