mirror of
https://github.com/OCA/manufacture.git
synced 2025-01-28 16:37:15 +02:00
@@ -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>
|
||||
89
mrp_attachment_mgmt/tests/common.py
Normal file
89
mrp_attachment_mgmt/tests/common.py
Normal file
@@ -0,0 +1,89 @@
|
||||
# Copyright 2022 Tecnativa - Víctor Martínez
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
import base64
|
||||
|
||||
from odoo import fields
|
||||
from odoo.tests import Form, common
|
||||
|
||||
|
||||
class TestMrpAttachmentMgmtBase(common.SavepointCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
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",
|
||||
"type": "product",
|
||||
}
|
||||
)
|
||||
cls.workcenter = cls.env["mrp.workcenter"].create(
|
||||
{
|
||||
"name": "Test workcenter",
|
||||
"resource_calendar_id": cls.env.ref(
|
||||
"resource.resource_calendar_std"
|
||||
).id,
|
||||
}
|
||||
)
|
||||
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, components):
|
||||
mrp_production_form = Form(self.env["mrp.production"])
|
||||
mrp_production_form.product_id = self.product
|
||||
mrp_production_form.bom_id = self.bom
|
||||
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
|
||||
|
||||
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()
|
||||
|
||||
def _create_attachment(self, product, name=False):
|
||||
name = name if name else "Test file %s" % product.name
|
||||
return self.attachment_model.create(
|
||||
{
|
||||
"name": name,
|
||||
"res_model": product._name,
|
||||
"res_id": product.id,
|
||||
"datas": base64.b64encode(b"\xff data"),
|
||||
}
|
||||
)
|
||||
@@ -1,94 +1,35 @@
|
||||
# Copyright 2022 Tecnativa - Víctor Martínez
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
import base64
|
||||
|
||||
from odoo import fields
|
||||
from odoo.exceptions import UserError
|
||||
from odoo.tests import Form, common
|
||||
|
||||
from .common import TestMrpAttachmentMgmtBase
|
||||
|
||||
|
||||
class TestMrpAttachmentMgmt(common.SavepointCase):
|
||||
class TestMrpAttachmentMgmt(TestMrpAttachmentMgmtBase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
cls.component = cls.env["product.product"].create(
|
||||
{
|
||||
"name": "Test Component A",
|
||||
"type": "product",
|
||||
}
|
||||
)
|
||||
cls.product = cls.env["product.product"].create(
|
||||
{
|
||||
"name": "Test Product",
|
||||
"type": "product",
|
||||
}
|
||||
)
|
||||
cls.workcenter = cls.env["mrp.workcenter"].create(
|
||||
{
|
||||
"name": "Test workcenter",
|
||||
"resource_calendar_id": cls.env.ref(
|
||||
"resource.resource_calendar_std"
|
||||
).id,
|
||||
}
|
||||
)
|
||||
cls.bom = cls._create_mrp_bom(cls, cls.product, [(cls.component, 1)])
|
||||
cls.mrp_production = cls._create_mrp_production(cls)
|
||||
cls.workorder = fields.first(cls.mrp_production.workorder_ids)
|
||||
|
||||
def _create_mrp_production(self):
|
||||
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
|
||||
mrp_production = mrp_production_form.save()
|
||||
mrp_production.action_confirm()
|
||||
return mrp_production
|
||||
|
||||
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()
|
||||
|
||||
def _create_attachment(self, product):
|
||||
return self.env["ir.attachment"].create(
|
||||
{
|
||||
"name": "Test file %s" % product.name,
|
||||
"res_model": product._name,
|
||||
"res_id": product.id,
|
||||
"datas": base64.b64encode(b"\xff data"),
|
||||
}
|
||||
)
|
||||
|
||||
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