mirror of
https://github.com/OCA/manufacture.git
synced 2025-01-28 16:37:15 +02:00
[IMP] mrp_attachment_mgmt: Show in the smart-button of the bom the attachments (ir.attachment) uploaded from bom and the attachments of the components.
TT33396
This commit is contained in:
@@ -10,7 +10,6 @@
|
||||
"depends": ["mrp"],
|
||||
"installable": True,
|
||||
"data": [
|
||||
"template/assets.xml",
|
||||
"views/mrp_bom_view.xml",
|
||||
"views/product_views.xml",
|
||||
"views/workorder_attachments_views.xml",
|
||||
|
||||
@@ -8,16 +8,17 @@ class MrpBom(models.Model):
|
||||
|
||||
def _action_see_bom_documents_products(self, products):
|
||||
domain = [
|
||||
# ("res_field", "=", False),
|
||||
"|",
|
||||
"&",
|
||||
("ir_attachment_id.res_model", "=", "product.product"),
|
||||
("ir_attachment_id.res_id", "in", products.ids),
|
||||
("res_model", "=", "product.product"),
|
||||
("res_id", "in", products.ids),
|
||||
"&",
|
||||
("ir_attachment_id.res_model", "=", "product.template"),
|
||||
("ir_attachment_id.res_id", "in", products.mapped("product_tmpl_id").ids),
|
||||
("res_model", "=", "product.template"),
|
||||
("res_id", "in", products.mapped("product_tmpl_id").ids),
|
||||
]
|
||||
res = self.env["mrp.bom.line"].action_see_attachments()
|
||||
ctx = {"hide_upload": True, "edit": False, "delete": False}
|
||||
res = self.env.ref("base.action_attachment").read()[0]
|
||||
ctx = {"create": False, "edit": False}
|
||||
res.update({"domain": domain, "context": ctx})
|
||||
return res
|
||||
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
odoo.define("mrp_attachment_mgmt.controllerMixin", function (require) {
|
||||
"use strict";
|
||||
var MrpDocumentsKanbanController = require("mrp.MrpDocumentsKanbanController");
|
||||
MrpDocumentsKanbanController.include({
|
||||
renderButtons: function () {
|
||||
const context = this.model.get(this.handle).getContext();
|
||||
if (!context.hide_upload) {
|
||||
this._super(...arguments);
|
||||
}
|
||||
},
|
||||
});
|
||||
});
|
||||
@@ -1,15 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
<template
|
||||
id="assets_backend"
|
||||
name="mrp_attachment_mgmt_assets"
|
||||
inherit_id="web.assets_backend"
|
||||
>
|
||||
<xpath expr="//script[1]" position="after">
|
||||
<script
|
||||
type="text/javascript"
|
||||
src="/mrp_attachment_mgmt/static/src/js/mrp_documents_controller_mixin.js"
|
||||
/>
|
||||
</xpath>
|
||||
</template>
|
||||
</odoo>
|
||||
@@ -11,12 +11,24 @@ class TestMrpAttachmentMgmt(common.SavepointCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
cls.component = cls.env["product.product"].create(
|
||||
cls.component_a = cls.env["product.product"].create(
|
||||
{
|
||||
"name": "Test Component A",
|
||||
"type": "product",
|
||||
}
|
||||
)
|
||||
cls.component_b = cls.env["product.product"].create(
|
||||
{
|
||||
"name": "Test Component B",
|
||||
"type": "product",
|
||||
}
|
||||
)
|
||||
cls.component_c = cls.env["product.product"].create(
|
||||
{
|
||||
"name": "Test Component C",
|
||||
"type": "product",
|
||||
}
|
||||
)
|
||||
cls.product = cls.env["product.product"].create(
|
||||
{
|
||||
"name": "Test Product",
|
||||
@@ -31,17 +43,25 @@ class TestMrpAttachmentMgmt(common.SavepointCase):
|
||||
).id,
|
||||
}
|
||||
)
|
||||
cls.bom = cls._create_mrp_bom(cls, cls.product, [(cls.component, 1)])
|
||||
cls.mrp_production = cls._create_mrp_production(cls)
|
||||
cls.bom = cls._create_mrp_bom(
|
||||
cls,
|
||||
cls.product,
|
||||
[(cls.component_a, 1), (cls.component_b, 1), (cls.component_c, 1)],
|
||||
)
|
||||
cls.mrp_production = cls._create_mrp_production(
|
||||
cls, [(cls.component_a, 1), (cls.component_b, 1), (cls.component_c, 1)]
|
||||
)
|
||||
cls.workorder = fields.first(cls.mrp_production.workorder_ids)
|
||||
cls.attachment_model = cls.env["ir.attachment"]
|
||||
|
||||
def _create_mrp_production(self):
|
||||
def _create_mrp_production(self, components):
|
||||
mrp_production_form = Form(self.env["mrp.production"])
|
||||
mrp_production_form.product_id = self.product
|
||||
mrp_production_form.bom_id = self.bom
|
||||
with mrp_production_form.move_raw_ids.new() as move_form:
|
||||
move_form.product_id = self.component
|
||||
move_form.product_uom_qty = 1
|
||||
for component in components:
|
||||
with mrp_production_form.move_raw_ids.new() as move_form:
|
||||
move_form.product_id = component[0]
|
||||
move_form.product_uom_qty = component[1]
|
||||
mrp_production = mrp_production_form.save()
|
||||
mrp_production.action_confirm()
|
||||
return mrp_production
|
||||
@@ -59,7 +79,7 @@ class TestMrpAttachmentMgmt(common.SavepointCase):
|
||||
return mrp_bom_form.save()
|
||||
|
||||
def _create_attachment(self, product):
|
||||
return self.env["ir.attachment"].create(
|
||||
return self.attachment_model.create(
|
||||
{
|
||||
"name": "Test file %s" % product.name,
|
||||
"res_model": product._name,
|
||||
@@ -69,26 +89,25 @@ class TestMrpAttachmentMgmt(common.SavepointCase):
|
||||
)
|
||||
|
||||
def test_misc_bom_documents(self):
|
||||
attachment = self._create_attachment(self.component)
|
||||
document = self.env["mrp.document"].create({"ir_attachment_id": attachment.id})
|
||||
attachment_a = self._create_attachment(self.component_a)
|
||||
self.env["mrp.document"].create({"ir_attachment_id": attachment_a.id})
|
||||
attachment_b = self._create_attachment(self.component_b)
|
||||
action = self.bom.action_see_bom_documents()
|
||||
self.assertIn(
|
||||
document.id, self.env["mrp.document"].search(action["domain"]).ids
|
||||
)
|
||||
attachment_bom_items = self.attachment_model.search(action["domain"])
|
||||
self.assertEqual(len(attachment_bom_items), 2)
|
||||
self.assertIn(attachment_a.id, attachment_bom_items.ids)
|
||||
self.assertIn(attachment_b.id, attachment_bom_items.ids)
|
||||
self.assertNotIn(self.component_c.id, attachment_bom_items.mapped("res_id"))
|
||||
action = self.product.action_see_bom_documents()
|
||||
self.assertIn(
|
||||
document.id, self.env["mrp.document"].search(action["domain"]).ids
|
||||
)
|
||||
attachment_product_items = self.attachment_model.search(action["domain"])
|
||||
self.assertEqual(attachment_bom_items, attachment_product_items)
|
||||
action = self.product.product_tmpl_id.action_see_bom_documents()
|
||||
self.assertIn(
|
||||
document.id, self.env["mrp.document"].search(action["domain"]).ids
|
||||
)
|
||||
attachment_template_items = self.attachment_model.search(action["domain"])
|
||||
self.assertEqual(attachment_template_items, attachment_product_items)
|
||||
|
||||
def test_mrp_workorder_attachments(self):
|
||||
with self.assertRaises(UserError):
|
||||
self.workorder.action_see_workorder_attachments()
|
||||
attachment = self._create_attachment(self.product)
|
||||
action = self.workorder.action_see_workorder_attachments()
|
||||
self.assertIn(
|
||||
attachment.id, self.env["ir.attachment"].search(action["domain"]).ids
|
||||
)
|
||||
self.assertIn(attachment.id, self.attachment_model.search(action["domain"]).ids)
|
||||
|
||||
Reference in New Issue
Block a user