mirror of
https://github.com/bringout/oca-mrp.git
synced 2026-04-25 14:12:06 +02:00
Initial commit: OCA Mrp packages (117 packages)
This commit is contained in:
commit
277e84fd7a
4403 changed files with 395154 additions and 0 deletions
|
|
@ -0,0 +1,3 @@
|
|||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
|
||||
|
||||
from . import test_mrp_attachment_mgmt
|
||||
|
|
@ -0,0 +1,104 @@
|
|||
# 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.TransactionCase):
|
||||
@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
|
||||
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
|
||||
return self.attachment_model.create(
|
||||
{
|
||||
"name": name,
|
||||
"res_model": product._name,
|
||||
"res_id": product.id,
|
||||
"datas": base64.b64encode(b"\xff data"),
|
||||
}
|
||||
)
|
||||
|
||||
def _create_bom_attachment(self, bom, name=False):
|
||||
name = name if name else "Test file %s" % bom.display_name
|
||||
return self.attachment_model.create(
|
||||
{
|
||||
"name": name,
|
||||
"res_model": "mrp.bom",
|
||||
"res_id": bom.id,
|
||||
"datas": base64.b64encode(b"\xff data"),
|
||||
}
|
||||
)
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
# Copyright 2022 Tecnativa - Víctor Martínez
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
from .common import TestMrpAttachmentMgmtBase
|
||||
|
||||
|
||||
class TestMrpAttachmentMgmt(TestMrpAttachmentMgmtBase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
|
||||
def test_misc_bom_documents(self):
|
||||
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()
|
||||
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()
|
||||
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()
|
||||
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.attachment_model.search(action["domain"]).ids)
|
||||
|
||||
bom_attachment = self._create_bom_attachment(self.bom)
|
||||
action = self.workorder.action_see_workorder_bom_attachments()
|
||||
self.assertIn(
|
||||
bom_attachment.id, self.attachment_model.search(action["domain"]).ids
|
||||
)
|
||||
|
||||
def test_mrp_production_attachments(self):
|
||||
attachment = self._create_attachment(self.product)
|
||||
action = self.mrp_production.action_show_attachments()
|
||||
self.assertIn(attachment.id, self.attachment_model.search(action["domain"]).ids)
|
||||
|
||||
bom_attachment = self._create_bom_attachment(self.bom)
|
||||
action = self.mrp_production.action_show_bom_attachments()
|
||||
self.assertIn(
|
||||
bom_attachment.id, self.attachment_model.search(action["domain"]).ids
|
||||
)
|
||||
|
||||
def test_mrp_bom_attachments(self):
|
||||
product_attachment = self._create_attachment(self.product.product_tmpl_id)
|
||||
action = self.bom.action_show_product_attachments()
|
||||
self.assertIn(
|
||||
product_attachment.id, self.attachment_model.search(action["domain"]).ids
|
||||
)
|
||||
|
||||
def test_product_attachments(self):
|
||||
bom_attachment = self._create_bom_attachment(self.bom)
|
||||
action = self.product.action_see_bom_attachments()
|
||||
self.assertIn(
|
||||
bom_attachment.id, self.attachment_model.search(action["domain"]).ids
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue