From 81acb0ba97138114cdc43503e874d77b12bb3f80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Didderen?= Date: Mon, 23 Oct 2023 23:19:30 +0200 Subject: [PATCH] [MIG] mrp_attachment_mgmt: Migration to 16.0 --- mrp_attachment_mgmt/__manifest__.py | 2 +- mrp_attachment_mgmt/models/mrp_bom.py | 24 ++++++++++----------- mrp_attachment_mgmt/models/mrp_workorder.py | 3 ++- mrp_attachment_mgmt/tests/common.py | 22 +++++++++++-------- mrp_attachment_mgmt/views/product_views.xml | 2 ++ 5 files changed, 30 insertions(+), 23 deletions(-) diff --git a/mrp_attachment_mgmt/__manifest__.py b/mrp_attachment_mgmt/__manifest__.py index f829c5d78..ea86ea177 100644 --- a/mrp_attachment_mgmt/__manifest__.py +++ b/mrp_attachment_mgmt/__manifest__.py @@ -2,7 +2,7 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). { "name": "Mrp Attachment Mgmt", - "version": "14.0.1.3.0", + "version": "16.0.1.0.0", "category": "Manufacturing", "website": "https://github.com/OCA/manufacture", "author": "Tecnativa, Odoo Community Association (OCA)", diff --git a/mrp_attachment_mgmt/models/mrp_bom.py b/mrp_attachment_mgmt/models/mrp_bom.py index 6926417ed..d26b95e91 100644 --- a/mrp_attachment_mgmt/models/mrp_bom.py +++ b/mrp_attachment_mgmt/models/mrp_bom.py @@ -8,26 +8,26 @@ class MrpBom(models.Model): _inherit = "mrp.bom" @api.model - def _get_components_ids(self, product_tmpl=None, product=None, recursive=False): + 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 = [] - bom = super()._bom_find(product_tmpl=product_tmpl, product=product) - 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( - product_tmpl=bom_line_id.product_id.product_tmpl_id, - product=bom_line_id.product_id, - recursive=recursive, - ) - product_ids.extend(subcomponents) + 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_tmpl_id, self.product_id, True + 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() diff --git a/mrp_attachment_mgmt/models/mrp_workorder.py b/mrp_attachment_mgmt/models/mrp_workorder.py index e21c624bb..04edb7836 100644 --- a/mrp_attachment_mgmt/models/mrp_workorder.py +++ b/mrp_attachment_mgmt/models/mrp_workorder.py @@ -18,6 +18,7 @@ class MrpWorkorder(models.Model): error.append(product.display_name) if error: raise UserError( - _("%d Product(s) without drawing:\n%s") % (len(error), "\n".join(error)) + _("%(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() diff --git a/mrp_attachment_mgmt/tests/common.py b/mrp_attachment_mgmt/tests/common.py index 53dbc6b17..ccc3fa51d 100644 --- a/mrp_attachment_mgmt/tests/common.py +++ b/mrp_attachment_mgmt/tests/common.py @@ -6,7 +6,7 @@ from odoo import fields from odoo.tests import Form, common -class TestMrpAttachmentMgmtBase(common.SavepointCase): +class TestMrpAttachmentMgmtBase(common.TransactionCase): @classmethod def setUpClass(cls): super().setUpClass() @@ -68,14 +68,18 @@ class TestMrpAttachmentMgmtBase(common.SavepointCase): def _create_mrp_bom(self, product, components): mrp_bom_form = Form(self.env["mrp.bom"]) mrp_bom_form.product_tmpl_id = product.product_tmpl_id - for component in components: - with mrp_bom_form.bom_line_ids.new() as line_form: - line_form.product_id = component[0] - line_form.product_qty = component[1] - with mrp_bom_form.operation_ids.new() as operation_form: - operation_form.name = "Operation 1" - operation_form.workcenter_id = self.workcenter - return mrp_bom_form.save() + bom_with_attachments = mrp_bom_form.save() + self.env.user.groups_id += self.env.ref("mrp.group_mrp_routings") + with Form(bom_with_attachments) as bom: + for component in components: + with bom.bom_line_ids.new() as line_form: + line_form.product_id = component[0] + line_form.product_qty = component[1] + with bom.operation_ids.new() as operation_form: + operation_form.name = "Operation 1" + operation_form.workcenter_id = self.workcenter + operation_form.bom_id = bom_with_attachments + return bom_with_attachments def _create_attachment(self, product, name=False): name = name if name else "Test file %s" % product.name diff --git a/mrp_attachment_mgmt/views/product_views.xml b/mrp_attachment_mgmt/views/product_views.xml index 0d34c6f03..faf92f4e7 100644 --- a/mrp_attachment_mgmt/views/product_views.xml +++ b/mrp_attachment_mgmt/views/product_views.xml @@ -12,6 +12,7 @@ type="object" icon="fa-files-o" string="Bom Attachments" + groups="mrp.group_mrp_user" attrs="{'invisible': [('bom_count','!=',1)]}" /> @@ -29,6 +30,7 @@ type="object" icon="fa-files-o" string="Bom Attachments" + groups="mrp.group_mrp_user" attrs="{'invisible': [('bom_count','!=',1)]}" />