mirror of
https://github.com/OCA/manufacture.git
synced 2025-01-28 16:37:15 +02:00
[MIG] quality_control_stock_oca: Migration to 16.0
TT47858
This commit is contained in:
@@ -22,5 +22,6 @@
|
||||
<field name="code">qc.inspection</field>
|
||||
<field name="prefix">QC-</field>
|
||||
<field name="padding">6</field>
|
||||
<field name="company_id" eval="False" />
|
||||
</record>
|
||||
</odoo>
|
||||
|
||||
@@ -6,38 +6,48 @@
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import exceptions
|
||||
from odoo.tests.common import TransactionCase
|
||||
|
||||
from odoo.addons.base.tests.common import BaseCommon
|
||||
|
||||
from ..models.qc_trigger_line import _filter_trigger_lines
|
||||
|
||||
|
||||
class TestQualityControl(TransactionCase):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.inspection_model = self.env["qc.inspection"]
|
||||
self.category_model = self.env["qc.test.category"]
|
||||
self.question_model = self.env["qc.test.question"]
|
||||
self.wizard_model = self.env["qc.inspection.set.test"]
|
||||
self.qc_trigger = self.env["qc.trigger"].create(
|
||||
{"name": "Test Trigger", "active": True}
|
||||
)
|
||||
self.test = self.env.ref("quality_control_oca.qc_test_1")
|
||||
self.val_ok = self.env.ref("quality_control_oca.qc_test_question_value_1")
|
||||
self.val_ko = self.env.ref("quality_control_oca.qc_test_question_value_2")
|
||||
self.qn_question = self.env.ref("quality_control_oca.qc_test_question_2")
|
||||
self.cat_generic = self.env.ref(
|
||||
class TestQualityControlOcaBase(BaseCommon):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
cls.inspection_model = cls.env["qc.inspection"]
|
||||
cls.category_model = cls.env["qc.test.category"]
|
||||
cls.question_model = cls.env["qc.test.question"]
|
||||
cls.wizard_model = cls.env["qc.inspection.set.test"]
|
||||
cls.qc_trigger = cls.env["qc.trigger"].create({"name": "Test Trigger"})
|
||||
cls.test = cls.env.ref("quality_control_oca.qc_test_1")
|
||||
cls.val_ok = cls.env.ref("quality_control_oca.qc_test_question_value_1")
|
||||
cls.val_ko = cls.env.ref("quality_control_oca.qc_test_question_value_2")
|
||||
cls.qn_question = cls.env.ref("quality_control_oca.qc_test_question_2")
|
||||
cls.cat_generic = cls.env.ref(
|
||||
"quality_control_oca.qc_test_template_category_generic"
|
||||
)
|
||||
self.product = self.env.ref("product.product_product_11")
|
||||
inspection_lines = self.inspection_model._prepare_inspection_lines(self.test)
|
||||
self.inspection1 = self.inspection_model.create(
|
||||
{"name": "Test Inspection", "inspection_lines": inspection_lines}
|
||||
cls.product = cls.env["product.product"].create({"name": "Test product"})
|
||||
cls.inspection1 = cls.inspection_model.create(
|
||||
{
|
||||
"name": "Test Inspection",
|
||||
"inspection_lines": cls.inspection_model._prepare_inspection_lines(
|
||||
cls.test
|
||||
),
|
||||
}
|
||||
)
|
||||
self.wizard = self.wizard_model.with_context(
|
||||
active_id=self.inspection1.id
|
||||
).create({"test": self.test.id})
|
||||
self.wizard.action_create_test()
|
||||
self.inspection1.action_todo()
|
||||
|
||||
|
||||
class TestQualityControlOca(TestQualityControlOcaBase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
cls.wizard = cls.wizard_model.with_context(active_id=cls.inspection1.id).create(
|
||||
{"test": cls.test.id}
|
||||
)
|
||||
cls.wizard.action_create_test()
|
||||
cls.inspection1.action_todo()
|
||||
|
||||
def test_inspection_correct(self):
|
||||
for line in self.inspection1.inspection_lines:
|
||||
|
||||
@@ -29,12 +29,11 @@ class QcInspection(models.Model):
|
||||
|
||||
@api.depends("object_id")
|
||||
def _compute_picking(self):
|
||||
for inspection in self:
|
||||
if inspection.object_id:
|
||||
if inspection.object_id._name == "stock.move":
|
||||
inspection.picking_id = inspection.object_id.picking_id
|
||||
elif inspection.object_id._name == "stock.picking":
|
||||
inspection.picking_id = inspection.object_id
|
||||
for inspection in self.filtered("object_id"):
|
||||
if inspection.object_id._name == "stock.move":
|
||||
inspection.picking_id = inspection.object_id.picking_id
|
||||
elif inspection.object_id._name == "stock.picking":
|
||||
inspection.picking_id = inspection.object_id
|
||||
|
||||
@api.depends("object_id")
|
||||
def _compute_lot(self):
|
||||
@@ -44,17 +43,13 @@ class QcInspection(models.Model):
|
||||
move_lines = self.env["stock.move.line"].search(
|
||||
[("lot_id", "!=", False), ("move_id", "in", [move.id for move in moves])]
|
||||
)
|
||||
|
||||
for inspection in self:
|
||||
if inspection.object_id:
|
||||
if inspection.object_id._name == "stock.move":
|
||||
inspection.lot_id = first(
|
||||
move_lines.filtered(
|
||||
lambda line: line.move_id == inspection.object_id
|
||||
)
|
||||
).lot_id
|
||||
elif inspection.object_id._name == "stock.lot":
|
||||
inspection.lot_id = inspection.object_id
|
||||
for inspection in self.filtered("object_id"):
|
||||
if inspection.object_id._name == "stock.move":
|
||||
inspection.lot_id = first(
|
||||
move_lines.filtered(lambda x: x.move_id == inspection.object_id)
|
||||
).lot_id
|
||||
elif inspection.object_id._name == "stock.lot":
|
||||
inspection.lot_id = inspection.object_id
|
||||
|
||||
@api.depends("object_id")
|
||||
def _compute_product_id(self):
|
||||
@@ -69,7 +64,7 @@ class QcInspection(models.Model):
|
||||
|
||||
@api.onchange("object_id")
|
||||
def onchange_object_id(self):
|
||||
if self.object_id._name == "stock.move":
|
||||
if self.object_id and self.object_id._name == "stock.move":
|
||||
self.qty = self.object_id.product_qty
|
||||
|
||||
def _prepare_inspection_header(self, object_ref, trigger_line):
|
||||
|
||||
@@ -8,15 +8,20 @@ from odoo import api, models
|
||||
class StockPickingType(models.Model):
|
||||
_inherit = "stock.picking.type"
|
||||
|
||||
def _prepare_qc_trigger_vals(self):
|
||||
self.ensure_one()
|
||||
return {
|
||||
"name": self.display_name,
|
||||
"company_id": self.warehouse_id.company_id.id,
|
||||
"picking_type_id": self.id,
|
||||
"partner_selectable": True,
|
||||
}
|
||||
|
||||
def _create_qc_trigger(self):
|
||||
values = []
|
||||
for picking_type in self:
|
||||
qc_trigger = {
|
||||
"name": picking_type.display_name,
|
||||
"company_id": picking_type.warehouse_id.company_id.id,
|
||||
"picking_type_id": picking_type.id,
|
||||
"partner_selectable": True,
|
||||
}
|
||||
self.env["qc.trigger"].sudo().create(qc_trigger)
|
||||
values.append(picking_type._prepare_qc_trigger_vals())
|
||||
self.env["qc.trigger"].sudo().create(values)
|
||||
|
||||
@api.model_create_multi
|
||||
def create(self, val_list):
|
||||
@@ -32,5 +37,5 @@ class StockPickingType(models.Model):
|
||||
qc_triggers = qc_trigger_model.search(
|
||||
[("picking_type_id", "=", rec.id)]
|
||||
)
|
||||
qc_triggers.write({"name": rec.name})
|
||||
qc_triggers.write({"name": rec.display_name})
|
||||
return res
|
||||
|
||||
@@ -1,113 +1,66 @@
|
||||
# Copyright 2015 Oihane Crucelaegui - AvanzOSC
|
||||
# Copyright 2018 Simone Rubino - Agile Business Group
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
from odoo.tests import Form, new_test_user
|
||||
from odoo.tools import mute_logger
|
||||
|
||||
from odoo.tests.common import TransactionCase
|
||||
from odoo.addons.quality_control_oca.tests.test_quality_control import (
|
||||
TestQualityControlOcaBase,
|
||||
)
|
||||
|
||||
|
||||
class TestQualityControl(TransactionCase):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.users_model = self.env["res.users"]
|
||||
self.picking_model = self.env["stock.picking"]
|
||||
self.inspection_model = self.env["qc.inspection"]
|
||||
self.qc_trigger_model = self.env["qc.trigger"]
|
||||
self.picking_type_model = self.env["stock.picking.type"]
|
||||
self.product = self.env.ref("product.product_product_2")
|
||||
self.partner1 = self.env.ref("base.res_partner_2")
|
||||
self.partner2 = self.env.ref("base.res_partner_4")
|
||||
self.test = self.env.ref("quality_control_oca.qc_test_1")
|
||||
self.picking_type = self.env.ref("stock.picking_type_out")
|
||||
self.location_dest = self.env.ref("stock.stock_location_customers")
|
||||
self.group_stock_user = self.env.ref("stock.group_stock_user")
|
||||
self.group_quality_control_user = self.env.ref(
|
||||
"quality_control_oca.group_quality_control_user"
|
||||
class TestQualityControlStockOca(TestQualityControlOcaBase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
cls.qc_trigger_model = cls.env["qc.trigger"]
|
||||
cls.picking_type_model = cls.env["stock.picking.type"]
|
||||
cls.partner1 = cls.env["res.partner"].create({"name": "Test partner 1"})
|
||||
cls.partner2 = cls.env["res.partner"].create({"name": "Test partner 2"})
|
||||
cls.picking_type = cls.env.ref("stock.picking_type_out")
|
||||
cls.location = cls.picking_type.default_location_src_id
|
||||
cls.location_dest = cls.picking_type.default_location_dest_id
|
||||
cls.trigger = cls.qc_trigger_model.search(
|
||||
[("picking_type_id", "=", cls.picking_type.id)]
|
||||
)
|
||||
self.company = self.env.ref("base.main_company")
|
||||
self.sequence = self.env["ir.sequence"].create(
|
||||
{"code": "out", "name": "outgoing_sequence"}
|
||||
)
|
||||
inspection_lines = self.inspection_model._prepare_inspection_lines(self.test)
|
||||
self.inspection1 = self.inspection_model.create(
|
||||
{"name": "Test Inspection", "inspection_lines": inspection_lines}
|
||||
)
|
||||
self.trigger = self.qc_trigger_model.search(
|
||||
[("picking_type_id", "=", self.picking_type.id)]
|
||||
)
|
||||
self.lot = self.env["stock.lot"].create(
|
||||
cls.lot = cls.env["stock.lot"].create(
|
||||
{
|
||||
"name": "Lot for tests",
|
||||
"product_id": self.product.id,
|
||||
"company_id": self.company.id,
|
||||
"product_id": cls.product.id,
|
||||
}
|
||||
)
|
||||
self.user1_id = self._create_user(
|
||||
"user_1",
|
||||
[self.group_stock_user, self.group_quality_control_user],
|
||||
self.company,
|
||||
)
|
||||
move_vals = {
|
||||
"name": self.product.name,
|
||||
"product_id": self.product.id,
|
||||
"product_uom": self.product.uom_id.id,
|
||||
"product_uom_qty": 2.0,
|
||||
"location_id": self.picking_type.default_location_src_id.id,
|
||||
"location_dest_id": self.location_dest.id,
|
||||
}
|
||||
self.picking1 = (
|
||||
self.picking_model.with_user(self.user1_id)
|
||||
.with_context(default_picking_type_id=self.picking_type.id)
|
||||
.create(
|
||||
{
|
||||
"partner_id": self.partner1.id,
|
||||
"picking_type_id": self.picking_type.id,
|
||||
"move_ids": [(0, 0, move_vals)],
|
||||
"location_dest_id": self.location_dest.id,
|
||||
}
|
||||
)
|
||||
)
|
||||
self.picking1.action_confirm()
|
||||
sequence = 10
|
||||
for line in self.picking1.move_ids.filtered(
|
||||
lambda r: r.product_id == self.product
|
||||
):
|
||||
line.write(
|
||||
{
|
||||
"move_line_ids": [
|
||||
(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
"lot_id": self.lot.id,
|
||||
"qty_done": 1.0,
|
||||
"product_uom_id": line.product_uom.id,
|
||||
"product_id": line.product_id.id,
|
||||
"location_id": line.location_id.id,
|
||||
"location_dest_id": line.location_dest_id.id,
|
||||
},
|
||||
)
|
||||
],
|
||||
"sequence": sequence,
|
||||
}
|
||||
)
|
||||
sequence += 10
|
||||
|
||||
def _create_user(self, login, groups, company):
|
||||
"""Create a user."""
|
||||
group_ids = [group.id for group in groups]
|
||||
user = self.users_model.with_context(no_reset_password=True).create(
|
||||
cls.product.detailed_type = "product"
|
||||
cls.env["stock.quant"].create(
|
||||
{
|
||||
"name": "Sale User",
|
||||
"login": login,
|
||||
"password": "test",
|
||||
"email": "test@yourcompany.com",
|
||||
"company_id": company.id,
|
||||
"company_ids": [(4, company.id)],
|
||||
"groups_id": [(6, 0, group_ids)],
|
||||
"product_id": cls.product.id,
|
||||
"location_id": cls.location.id,
|
||||
"quantity": 1,
|
||||
"lot_id": cls.lot.id,
|
||||
}
|
||||
)
|
||||
return user.id
|
||||
cls.user = new_test_user(
|
||||
cls.env,
|
||||
login="test_quality_control_stock_oca",
|
||||
groups="%s,%s"
|
||||
% (
|
||||
"stock.group_stock_user",
|
||||
"quality_control_oca.group_quality_control_user",
|
||||
),
|
||||
)
|
||||
picking_form = Form(
|
||||
cls.env["stock.picking"]
|
||||
.with_user(cls.user)
|
||||
.with_context(default_picking_type_id=cls.picking_type.id)
|
||||
)
|
||||
picking_form.partner_id = cls.partner1
|
||||
with picking_form.move_ids_without_package.new() as move_form:
|
||||
move_form.product_id = cls.product
|
||||
move_form.product_uom_qty = 2
|
||||
cls.picking1 = picking_form.save()
|
||||
cls.picking1.action_confirm()
|
||||
cls.picking1.move_ids.move_line_ids.qty_done = 1
|
||||
|
||||
@mute_logger("odoo.models.unlink")
|
||||
def test_inspection_create_for_product(self):
|
||||
self.product.qc_triggers = [
|
||||
(0, 0, {"trigger": self.trigger.id, "test": self.test.id})
|
||||
@@ -126,6 +79,7 @@ class TestQualityControl(TransactionCase):
|
||||
inspection.onchange_object_id()
|
||||
self.assertEqual(inspection.qty, self.picking1.move_ids.product_uom_qty)
|
||||
|
||||
@mute_logger("odoo.models.unlink")
|
||||
def test_inspection_create_for_template(self):
|
||||
self.product.product_tmpl_id.qc_triggers = [
|
||||
(0, 0, {"trigger": self.trigger.id, "test": self.test.id})
|
||||
@@ -140,6 +94,7 @@ class TestQualityControl(TransactionCase):
|
||||
"Wrong test picked when creating inspection.",
|
||||
)
|
||||
|
||||
@mute_logger("odoo.models.unlink")
|
||||
def test_inspection_create_for_category(self):
|
||||
self.product.categ_id.qc_triggers = [
|
||||
(0, 0, {"trigger": self.trigger.id, "test": self.test.id})
|
||||
@@ -154,6 +109,7 @@ class TestQualityControl(TransactionCase):
|
||||
"Wrong test picked when creating inspection.",
|
||||
)
|
||||
|
||||
@mute_logger("odoo.models.unlink")
|
||||
def test_inspection_create_for_product_partner(self):
|
||||
self.product.qc_triggers = [
|
||||
(
|
||||
@@ -176,6 +132,7 @@ class TestQualityControl(TransactionCase):
|
||||
"Wrong test picked when creating inspection.",
|
||||
)
|
||||
|
||||
@mute_logger("odoo.models.unlink")
|
||||
def test_inspection_create_for_template_partner(self):
|
||||
self.product.product_tmpl_id.qc_triggers = [
|
||||
(
|
||||
@@ -198,6 +155,7 @@ class TestQualityControl(TransactionCase):
|
||||
"Wrong test picked when creating inspection.",
|
||||
)
|
||||
|
||||
@mute_logger("odoo.models.unlink")
|
||||
def test_inspection_create_for_category_partner(self):
|
||||
self.product.categ_id.qc_triggers = [
|
||||
(
|
||||
@@ -220,6 +178,7 @@ class TestQualityControl(TransactionCase):
|
||||
"Wrong test picked when creating inspection.",
|
||||
)
|
||||
|
||||
@mute_logger("odoo.models.unlink")
|
||||
def test_inspection_create_for_product_wrong_partner(self):
|
||||
self.product.qc_triggers = [
|
||||
(
|
||||
@@ -237,6 +196,7 @@ class TestQualityControl(TransactionCase):
|
||||
self.picking1.created_inspections, 0, "No inspection must be created"
|
||||
)
|
||||
|
||||
@mute_logger("odoo.models.unlink")
|
||||
def test_inspection_create_for_template_wrong_partner(self):
|
||||
self.product.product_tmpl_id.qc_triggers = [
|
||||
(
|
||||
@@ -254,6 +214,7 @@ class TestQualityControl(TransactionCase):
|
||||
self.picking1.created_inspections, 0, "No inspection must be created"
|
||||
)
|
||||
|
||||
@mute_logger("odoo.models.unlink")
|
||||
def test_inspection_create_for_category_wrong_partner(self):
|
||||
self.product.categ_id.qc_triggers = [
|
||||
(
|
||||
@@ -271,6 +232,7 @@ class TestQualityControl(TransactionCase):
|
||||
self.picking1.created_inspections, 0, "No inspection must be created"
|
||||
)
|
||||
|
||||
@mute_logger("odoo.models.unlink")
|
||||
def test_inspection_create_only_one(self):
|
||||
self.product.qc_triggers = [
|
||||
(0, 0, {"trigger": self.trigger.id, "test": self.test.id})
|
||||
@@ -301,8 +263,8 @@ class TestQualityControl(TransactionCase):
|
||||
{
|
||||
"name": "Test Picking Type",
|
||||
"code": "outgoing",
|
||||
"sequence_code": "OUT",
|
||||
"sequence_id": self.sequence.id,
|
||||
"sequence_code": self.picking_type.sequence_code,
|
||||
"sequence_id": self.picking_type.sequence_id.id,
|
||||
}
|
||||
)
|
||||
trigger = self.qc_trigger_model.search(
|
||||
|
||||
Reference in New Issue
Block a user