[IMP] quality_control_mrp: black, isort

This commit is contained in:
Carlos Roca
2021-02-23 16:33:38 +01:00
committed by Oihane Crucelaegui
parent c4123c866e
commit 1740b7ea89
8 changed files with 207 additions and 196 deletions

View File

@@ -12,17 +12,12 @@
"Serv. Tecnol. Avanzados - Pedro M. Baeza, "
"Agile Business Group, "
"Odoo Community Association (OCA)",
"website": "https://github.com/OCA/manufacture/tree/12.0/"
"quality_control_mrp",
"depends": [
"quality_control",
"quality_control_stock",
"mrp"
],
"website": "https://github.com/OCA/manufacture/tree/12.0/" "quality_control_mrp",
"depends": ["quality_control", "quality_control_stock", "mrp"],
"data": [
'data/quality_control_mrp_data.xml',
'views/qc_inspection_view.xml',
'views/mrp_production_view.xml'
"data/quality_control_mrp_data.xml",
"views/qc_inspection_view.xml",
"views/mrp_production_view.xml",
],
"installable": True,
"auto_install": True,

View File

@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8" ?>
<!-- Copyright 2018 Simone Rubino - Agile Business Group
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo>
<record model="qc.trigger" id="qc_trigger_mrp">
<field name="name">Production done</field>
<field name="company_id"/>
<field name="company_id" />
</record>
</odoo>

View File

@@ -1,10 +1,9 @@
from openupgradelib import openupgrade
field_renames = [
("mrp.production", "mrp_production", "qc_inspections",
"qc_inspections_ids"),
("mrp.production", "mrp_production", "qc_inspections", "qc_inspections_ids"),
("qc.inspection", "qc_inspection", "production", "production_id"),
("qc.inspection.line", "qc_inspection_line", "production", "production_id")
("qc.inspection.line", "qc_inspection_line", "production", "production_id"),
]

View File

@@ -3,43 +3,55 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
from odoo.addons.quality_control.models.qc_trigger_line import \
_filter_trigger_lines
from odoo.addons.quality_control.models.qc_trigger_line import _filter_trigger_lines
class MrpProduction(models.Model):
_inherit = 'mrp.production'
_inherit = "mrp.production"
@api.multi
@api.depends('qc_inspections_ids')
@api.depends("qc_inspections_ids")
def _count_inspections(self):
for production in self:
production.created_inspections = len(production.qc_inspections_ids)
qc_inspections_ids = fields.One2many(
comodel_name='qc.inspection', inverse_name='production_id', copy=False,
string='Inspections', help="Inspections related to this production.")
comodel_name="qc.inspection",
inverse_name="production_id",
copy=False,
string="Inspections",
help="Inspections related to this production.",
)
created_inspections = fields.Integer(
compute="_count_inspections", string="Created inspections")
compute="_count_inspections", string="Created inspections"
)
@api.multi
def post_inventory(self):
done_moves = self.mapped('move_finished_ids').filtered(
lambda r: r.state == 'done')
done_moves = self.mapped("move_finished_ids").filtered(
lambda r: r.state == "done"
)
res = super(MrpProduction, self).post_inventory()
inspection_model = self.env['qc.inspection']
new_done_moves = self.mapped('move_finished_ids').filtered(
lambda r: r.state == 'done') - done_moves
inspection_model = self.env["qc.inspection"]
new_done_moves = (
self.mapped("move_finished_ids").filtered(lambda r: r.state == "done")
- done_moves
)
if new_done_moves:
qc_trigger = self.env.ref('quality_control_mrp.qc_trigger_mrp')
qc_trigger = self.env.ref("quality_control_mrp.qc_trigger_mrp")
for move in new_done_moves:
trigger_lines = set()
for model in ['qc.trigger.product_category_line',
'qc.trigger.product_template_line',
'qc.trigger.product_line']:
for model in [
"qc.trigger.product_category_line",
"qc.trigger.product_template_line",
"qc.trigger.product_line",
]:
trigger_lines = trigger_lines.union(
self.env[model].get_trigger_line_for_product(
qc_trigger, move.product_id))
qc_trigger, move.product_id
)
)
for trigger_line in _filter_trigger_lines(trigger_lines):
inspection_model._make_inspection(move, trigger_line)
return res

View File

@@ -6,48 +6,52 @@ from odoo import api, fields, models
class QcInspection(models.Model):
_inherit = 'qc.inspection'
_inherit = "qc.inspection"
@api.multi
def _prepare_inspection_header(self, object_ref, trigger_line):
res = super(QcInspection, self)._prepare_inspection_header(
object_ref, trigger_line)
object_ref, trigger_line
)
# Fill qty when coming from pack operations
if object_ref and object_ref._name == 'mrp.production':
res['qty'] = object_ref.product_qty
if object_ref and object_ref._name == "mrp.production":
res["qty"] = object_ref.product_qty
return res
@api.depends('object_id')
@api.depends("object_id")
def get_production(self):
for inspection in self:
if inspection.object_id:
if inspection.object_id._name == 'stock.move':
if inspection.object_id._name == "stock.move":
inspection.production_id = inspection.object_id.production_id
elif inspection.object_id._name == 'mrp.production':
elif inspection.object_id._name == "mrp.production":
inspection.production_id = inspection.object_id
@api.depends('object_id')
@api.depends("object_id")
def _compute_product_id(self):
"""Overriden for getting the product from a manufacturing order."""
for inspection in self:
super(QcInspection, inspection)._compute_product_id()
if inspection.object_id and\
inspection.object_id._name == 'mrp.production':
if inspection.object_id and inspection.object_id._name == "mrp.production":
inspection.product_id = inspection.object_id.product_id
@api.multi
def object_selection_values(self):
objects = super(QcInspection, self).object_selection_values()
objects.append(('mrp.production', 'Manufacturing Order'))
objects.append(("mrp.production", "Manufacturing Order"))
return objects
production_id = fields.Many2one(
comodel_name="mrp.production", compute="get_production", store=True)
comodel_name="mrp.production", compute="get_production", store=True
)
class QcInspectionLine(models.Model):
_inherit = 'qc.inspection.line'
_inherit = "qc.inspection.line"
production_id = fields.Many2one(
comodel_name="mrp.production", related="inspection_id.production_id",
store=True, string="Production order")
comodel_name="mrp.production",
related="inspection_id.production_id",
store=True,
string="Production order",
)

View File

@@ -6,140 +6,141 @@ from odoo.tests.common import TransactionCase
class TestQualityControlMrp(TransactionCase):
def setUp(self):
super(TestQualityControlMrp, self).setUp()
self.production_model = self.env['mrp.production']
self.inspection_model = self.env['qc.inspection']
self.qc_trigger_model = self.env['qc.trigger']
self.product = self.env.ref('mrp.product_product_wood_panel')
self.test = self.env.ref('quality_control.qc_test_1')
self.trigger = self.env.ref('quality_control_mrp.qc_trigger_mrp')
self.bom = self.env['mrp.bom']._bom_find(product=self.product)
self.production1 = self.production_model.create({
'product_id': self.product.id,
'product_qty': 2.0,
'product_uom_id': self.product.uom_id.id,
'bom_id': self.bom.id
})
self.production_model = self.env["mrp.production"]
self.inspection_model = self.env["qc.inspection"]
self.qc_trigger_model = self.env["qc.trigger"]
self.product = self.env.ref("mrp.product_product_wood_panel")
self.test = self.env.ref("quality_control.qc_test_1")
self.trigger = self.env.ref("quality_control_mrp.qc_trigger_mrp")
self.bom = self.env["mrp.bom"]._bom_find(product=self.product)
self.production1 = self.production_model.create(
{
"product_id": self.product.id,
"product_qty": 2.0,
"product_uom_id": self.product.uom_id.id,
"bom_id": self.bom.id,
}
)
self.production1.action_assign()
inspection_lines = (
self.inspection_model._prepare_inspection_lines(self.test))
self.inspection1 = self.inspection_model.create({
'name': 'Test Inspection',
'inspection_lines': inspection_lines,
})
inspection_lines = self.inspection_model._prepare_inspection_lines(self.test)
self.inspection1 = self.inspection_model.create(
{"name": "Test Inspection", "inspection_lines": inspection_lines,}
)
def test_inspection_create_for_product(self):
self.product.qc_triggers = [(
0, 0, {
'trigger': self.trigger.id,
'test': self.test.id,
}
)]
produce_wizard = self.env['mrp.product.produce'].with_context({
'active_id': self.production1.id,
'active_ids': [self.production1.id],
}).create({
'product_qty': self.production1.product_qty
})
self.product.qc_triggers = [
(0, 0, {"trigger": self.trigger.id, "test": self.test.id,})
]
produce_wizard = (
self.env["mrp.product.produce"]
.with_context(
{"active_id": self.production1.id, "active_ids": [self.production1.id],}
)
.create({"product_qty": self.production1.product_qty})
)
produce_wizard.do_produce()
self.production1.post_inventory()
self.assertEqual(self.production1.created_inspections, 1,
'Only one inspection must be created')
self.assertEqual(
self.production1.created_inspections,
1,
"Only one inspection must be created",
)
def test_inspection_create_for_template(self):
self.product.product_tmpl_id.qc_triggers = [(
0, 0, {
'trigger': self.trigger.id,
'test': self.test.id,
}
)]
produce_wizard = self.env['mrp.product.produce'].with_context({
'active_id': self.production1.id,
'active_ids': [self.production1.id]
}).create({
'product_qty': self.production1.product_qty
})
self.product.product_tmpl_id.qc_triggers = [
(0, 0, {"trigger": self.trigger.id, "test": self.test.id,})
]
produce_wizard = (
self.env["mrp.product.produce"]
.with_context(
{"active_id": self.production1.id, "active_ids": [self.production1.id]}
)
.create({"product_qty": self.production1.product_qty})
)
produce_wizard.do_produce()
self.production1.post_inventory()
self.assertEqual(self.production1.created_inspections, 1,
'Only one inspection must be created')
self.assertEqual(
self.production1.created_inspections,
1,
"Only one inspection must be created",
)
def test_inspection_create_for_category(self):
self.product.categ_id.qc_triggers = [(
0, 0, {
'trigger': self.trigger.id,
'test': self.test.id,
}
)]
produce_wizard = self.env['mrp.product.produce'].with_context({
'active_id': self.production1.id,
'active_ids': [self.production1.id],
}).create({
'product_qty': self.production1.product_qty
})
self.product.categ_id.qc_triggers = [
(0, 0, {"trigger": self.trigger.id, "test": self.test.id,})
]
produce_wizard = (
self.env["mrp.product.produce"]
.with_context(
{"active_id": self.production1.id, "active_ids": [self.production1.id],}
)
.create({"product_qty": self.production1.product_qty})
)
produce_wizard.do_produce()
self.production1.post_inventory()
self.assertEqual(self.production1.created_inspections, 1,
'Only one inspection must be created')
self.assertEqual(
self.production1.created_inspections,
1,
"Only one inspection must be created",
)
def test_inspection_create_only_one(self):
self.product.qc_triggers = [(
0, 0, {
'trigger': self.trigger.id,
'test': self.test.id,
}
)]
self.product.categ_id.qc_triggers = [(
0, 0, {
'trigger': self.trigger.id,
'test': self.test.id,
}
)]
produce_wizard = self.env['mrp.product.produce'].with_context({
'active_id': self.production1.id,
'active_ids': [self.production1.id]
}).create({
'product_qty': self.production1.product_qty
})
self.product.qc_triggers = [
(0, 0, {"trigger": self.trigger.id, "test": self.test.id,})
]
self.product.categ_id.qc_triggers = [
(0, 0, {"trigger": self.trigger.id, "test": self.test.id,})
]
produce_wizard = (
self.env["mrp.product.produce"]
.with_context(
{"active_id": self.production1.id, "active_ids": [self.production1.id]}
)
.create({"product_qty": self.production1.product_qty})
)
produce_wizard.do_produce()
self.production1.post_inventory()
self.assertEqual(self.production1.created_inspections, 1,
'Only one inspection must be created')
self.assertEqual(
self.production1.created_inspections,
1,
"Only one inspection must be created",
)
def test_inspection_with_partial_fabrication(self):
self.product.qc_triggers = [(
0, 0, {
'trigger': self.trigger.id,
'test': self.test.id,
}
)]
produce_wizard = self.env['mrp.product.produce'].with_context({
'active_id': self.production1.id,
'active_ids': [self.production1.id],
}).create({
'product_qty': 1.0
})
self.product.qc_triggers = [
(0, 0, {"trigger": self.trigger.id, "test": self.test.id,})
]
produce_wizard = (
self.env["mrp.product.produce"]
.with_context(
{"active_id": self.production1.id, "active_ids": [self.production1.id],}
)
.create({"product_qty": 1.0})
)
produce_wizard.do_produce()
self.production1.post_inventory()
self.assertEqual(self.production1.created_inspections, 1,
'Only one inspection must be created.')
produce_wizard = self.env['mrp.product.produce'].with_context({
'active_id': self.production1.id,
'active_ids': [self.production1.id],
}).create({
'product_qty': 1.0
})
self.assertEqual(
self.production1.created_inspections,
1,
"Only one inspection must be created.",
)
produce_wizard = (
self.env["mrp.product.produce"]
.with_context(
{"active_id": self.production1.id, "active_ids": [self.production1.id],}
)
.create({"product_qty": 1.0})
)
produce_wizard.do_produce()
self.production1.post_inventory()
self.assertEqual(self.production1.created_inspections, 2,
'There must be only 2 inspections.')
self.assertEqual(
self.production1.created_inspections, 2, "There must be only 2 inspections."
)
def test_qc_inspection_mo(self):
self.inspection1.write({
'object_id': '%s,%d' % (self.production1._name,
self.production1.id),
})
self.assertEquals(self.inspection1.production_id,
self.production1)
self.inspection1.write(
{"object_id": "%s,%d" % (self.production1._name, self.production1.id),}
)
self.assertEquals(self.inspection1.production_id, self.production1)

View File

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8" ?>
<!-- Copyright 2018 Simone Rubino - Agile Business Group
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo>
@@ -8,22 +8,27 @@
<field name="view_mode">tree,form</field>
<field name="domain">[('production_id', '=', active_id)]</field>
</record>
<record model="ir.ui.view" id="mrp_production_qc_view">
<field name="name">mrp.production.form.qc</field>
<field name="model">mrp.production</field>
<field name="inherit_id" ref="mrp.mrp_production_form_view" />
<field name="groups_id"
eval="[(4, ref('quality_control.group_quality_control_user'))]" />
<field
name="groups_id"
eval="[(4, ref('quality_control.group_quality_control_user'))]"
/>
<field name="arch" type="xml">
<div name="button_box" position="inside">
<button class="oe_inline oe_stat_button"
<button
class="oe_inline oe_stat_button"
type="action"
name="%(action_qc_inspection_per_production)d"
icon="fa-bookmark-o">
<field name="created_inspections"
icon="fa-bookmark-o"
>
<field
name="created_inspections"
widget="statinfo"
string="inspections" />
string="inspections"
/>
</button>
</div>
</field>

View File

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8" ?>
<!-- Copyright 2018 Simone Rubino - Agile Business Group
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo>
@@ -6,75 +6,70 @@
<field name="name">qc.inspection.form.view.production</field>
<field name="model">qc.inspection</field>
<field name="inherit_id" ref="quality_control.qc_inspection_form_view" />
<field name="groups_id"
eval="[(4, ref('mrp.group_mrp_user'))]" />
<field name="groups_id" eval="[(4, ref('mrp.group_mrp_user'))]" />
<field name="arch" type="xml">
<field name="product_id" position="after">
<field name="production_id" />
</field>
</field>
</record>
<record model="ir.ui.view" id="qc_inspection_tree_view_production">
<field name="name">qc.inspection.tree.view.production</field>
<field name="model">qc.inspection</field>
<field name="inherit_id" ref="quality_control.qc_inspection_tree_view" />
<field name="groups_id"
eval="[(4, ref('mrp.group_mrp_user'))]" />
<field name="groups_id" eval="[(4, ref('mrp.group_mrp_user'))]" />
<field name="arch" type="xml">
<field name="product_id" position="after">
<field name="production_id" />
</field>
</field>
</record>
<record model="ir.ui.view" id="qc_inspection_search_view_production">
<field name="name">qc.inspection.search.view.production</field>
<field name="model">qc.inspection</field>
<field name="inherit_id" ref="quality_control.qc_inspection_search_view" />
<field name="groups_id"
eval="[(4, ref('mrp.group_mrp_user'))]" />
<field name="groups_id" eval="[(4, ref('mrp.group_mrp_user'))]" />
<field name="arch" type="xml">
<field name="product_id" position="after">
<field name="production_id" />
</field>
<group expand="0" position="inside">
<filter string="Production"
<filter
string="Production"
name="groupby_productions"
domain="[]"
context="{'group_by': 'production_id'}" />
context="{'group_by': 'production_id'}"
/>
</group>
</field>
</record>
<record model="ir.ui.view" id="qc_inspection_line_tree_production_view">
<field name="name">qc.inspection.line.tree.production</field>
<field name="model">qc.inspection.line</field>
<field name="inherit_id" ref="quality_control.qc_inspection_line_tree_view"/>
<field name="groups_id"
eval="[(4, ref('mrp.group_mrp_user'))]" />
<field name="inherit_id" ref="quality_control.qc_inspection_line_tree_view" />
<field name="groups_id" eval="[(4, ref('mrp.group_mrp_user'))]" />
<field name="arch" type="xml">
<field name="product_id" position="after">
<field name="production_id" />
</field>
</field>
</record>
<record model="ir.ui.view" id="qc_inspection_line_search_production_view">
<field name="name">qc.inspection.line.search.production</field>
<field name="model">qc.inspection.line</field>
<field name="inherit_id" ref="quality_control.qc_inspection_line_search_view" />
<field name="groups_id"
eval="[(4, ref('mrp.group_mrp_user'))]" />
<field name="groups_id" eval="[(4, ref('mrp.group_mrp_user'))]" />
<field name="arch" type="xml">
<field name="product_id" position="after">
<field name="production_id" />
</field>
<group expand="0" position="inside">
<filter string="Production order"
<filter
string="Production order"
name="groupby_productions"
domain="[]"
context="{'group_by': 'production_id'}" />
context="{'group_by': 'production_id'}"
/>
</group>
</field>
</record>