[MIG] mrp_attachment_mgmt: Migration to 16.0

This commit is contained in:
Jérémy Didderen
2023-10-23 23:19:30 +02:00
parent ac71457789
commit 81acb0ba97
5 changed files with 30 additions and 23 deletions

View File

@@ -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)",

View File

@@ -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()

View File

@@ -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()

View File

@@ -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

View File

@@ -12,6 +12,7 @@
type="object"
icon="fa-files-o"
string="Bom Attachments"
groups="mrp.group_mrp_user"
attrs="{'invisible': [('bom_count','!=',1)]}"
/>
</xpath>
@@ -29,6 +30,7 @@
type="object"
icon="fa-files-o"
string="Bom Attachments"
groups="mrp.group_mrp_user"
attrs="{'invisible': [('bom_count','!=',1)]}"
/>
</xpath>