From 79e2cf45fb098e0b23416db131833b8334a40fa8 Mon Sep 17 00:00:00 2001 From: ps-tubtim Date: Fri, 20 Mar 2020 15:28:15 +0700 Subject: [PATCH] [IMP] quality_control_stock: black, isort --- quality_control_stock_oca/__init__.py | 2 +- quality_control_stock_oca/__manifest__.py | 17 +- .../models/qc_inspection.py | 84 +-- .../models/qc_trigger.py | 5 +- .../models/stock_picking.py | 73 ++- .../models/stock_picking_type.py | 21 +- .../models/stock_production_lot.py | 44 +- .../tests/test_quality_control_stock.py | 500 ++++++++++-------- .../views/qc_inspection_view.xml | 78 +-- .../views/stock_picking_view.xml | 72 ++- .../views/stock_production_lot_view.xml | 72 ++- 11 files changed, 541 insertions(+), 427 deletions(-) diff --git a/quality_control_stock_oca/__init__.py b/quality_control_stock_oca/__init__.py index db11222a0..65c85e22f 100644 --- a/quality_control_stock_oca/__init__.py +++ b/quality_control_stock_oca/__init__.py @@ -9,6 +9,6 @@ from odoo import api, SUPERUSER_ID def post_init_hook(cr, registry): # Create QC triggers env = api.Environment(cr, SUPERUSER_ID, {}) - picking_type_ids = env['stock.picking.type'].sudo().search([]) + picking_type_ids = env["stock.picking.type"].sudo().search([]) for picking_type_id in picking_type_ids: picking_type_id.sudo()._create_qc_trigger() diff --git a/quality_control_stock_oca/__manifest__.py b/quality_control_stock_oca/__manifest__.py index 6aec78ff3..4a7b39eac 100644 --- a/quality_control_stock_oca/__manifest__.py +++ b/quality_control_stock_oca/__manifest__.py @@ -5,20 +5,13 @@ { "name": "Quality control - Stock", - "version": "12.0.1.0.0", + "version": "13.0.1.0.0", "category": "Quality control", "license": "AGPL-3", - "author": "OdooMRP team, " - "AvanzOSC, " - "Serv. Tecnol. Avanzados - Pedro M. Baeza, " - "Agile Business Group, " - "Odoo Community Association (OCA)", - "website": "https://github.com/OCA/manufacture/tree/12.0/" - "quality_control_stock", - "depends": [ - "quality_control", - "stock", - ], + "author": "OdooMRP team, AvanzOSC, Serv. Tecnol. Avanzados - Pedro M. Baeza, " + "Agile Business Group, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/manufacture/tree/12.0/quality_control_stock", + "depends": ["quality_control", "stock"], "data": [ "security/ir.model.access.csv", "views/qc_inspection_view.xml", diff --git a/quality_control_stock_oca/models/qc_inspection.py b/quality_control_stock_oca/models/qc_inspection.py index 4c8a295c2..8869216bc 100644 --- a/quality_control_stock_oca/models/qc_inspection.py +++ b/quality_control_stock_oca/models/qc_inspection.py @@ -7,95 +7,97 @@ from odoo.fields import first class QcInspection(models.Model): - _inherit = 'qc.inspection' + _inherit = "qc.inspection" picking_id = fields.Many2one( - comodel_name="stock.picking", compute="_compute_picking", store=True) + comodel_name="stock.picking", compute="_compute_picking", store=True + ) lot_id = fields.Many2one( - comodel_name='stock.production.lot', compute="_compute_lot", - store=True) + comodel_name="stock.production.lot", compute="_compute_lot", store=True + ) @api.multi def object_selection_values(self): result = super().object_selection_values() - result.extend([ - ('stock.picking', "Picking List"), ('stock.move', "Stock Move")]) + result.extend([("stock.picking", "Picking List"), ("stock.move", "Stock Move")]) return result @api.multi - @api.depends('object_id') + @api.depends("object_id") def _compute_picking(self): for inspection in self: if inspection.object_id: - if inspection.object_id._name == 'stock.move': + if inspection.object_id._name == "stock.move": inspection.picking_id = inspection.object_id.picking_id - elif inspection.object_id._name == 'stock.picking': + elif inspection.object_id._name == "stock.picking": inspection.picking_id = inspection.object_id - elif inspection.object_id._name == 'stock.move.line': + elif inspection.object_id._name == "stock.move.line": inspection.picking_id = inspection.object_id.picking_id @api.multi - @api.depends('object_id') + @api.depends("object_id") def _compute_lot(self): moves = self.filtered( - lambda i: i.object_id and - i.object_id._name == 'stock.move').mapped('object_id') - move_lines = self.env['stock.move.line'].search([ - ('lot_id', '!=', False), - ('move_id', 'in', [move.id for move in moves])]) + lambda i: i.object_id and i.object_id._name == "stock.move" + ).mapped("object_id") + 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.line': - inspection.lot_id = \ - inspection.object_id.lot_id - elif 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.production.lot': + if inspection.object_id._name == "stock.move.line": + inspection.lot_id = inspection.object_id.lot_id + elif 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.production.lot": inspection.lot_id = inspection.object_id @api.multi - @api.depends('object_id') + @api.depends("object_id") def _compute_product_id(self): """Overriden for getting the product from a stock move.""" self.ensure_one() super(QcInspection, self)._compute_product_id() if self.object_id: - if self.object_id._name == 'stock.move': + if self.object_id._name == "stock.move": self.product_id = self.object_id.product_id - elif self.object_id._name == 'stock.move.line': + elif self.object_id._name == "stock.move.line": self.product_id = self.object_id.product_id - elif self.object_id._name == 'stock.production.lot': + elif self.object_id._name == "stock.production.lot": self.product_id = self.object_id.product_id - @api.onchange('object_id') + @api.onchange("object_id") def onchange_object_id(self): if self.object_id: - if self.object_id._name == 'stock.move': + if self.object_id._name == "stock.move": self.qty = self.object_id.product_qty - elif self.object_id._name == 'stock.move.line': + elif self.object_id._name == "stock.move.line": self.qty = self.object_id.product_qty @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 == 'stock.move.line': - res['qty'] = object_ref.product_qty - if object_ref and object_ref._name == 'stock.move': - res['qty'] = object_ref.product_uom_qty + if object_ref and object_ref._name == "stock.move.line": + res["qty"] = object_ref.product_qty + if object_ref and object_ref._name == "stock.move": + res["qty"] = object_ref.product_uom_qty return res class QcInspectionLine(models.Model): - _inherit = 'qc.inspection.line' + _inherit = "qc.inspection.line" picking_id = fields.Many2one( - comodel_name="stock.picking", related="inspection_id.picking_id", - store=True) + comodel_name="stock.picking", related="inspection_id.picking_id", store=True + ) lot_id = fields.Many2one( - comodel_name="stock.production.lot", related="inspection_id.lot_id", - store=True) + comodel_name="stock.production.lot", related="inspection_id.lot_id", store=True + ) diff --git a/quality_control_stock_oca/models/qc_trigger.py b/quality_control_stock_oca/models/qc_trigger.py index 942ba29fa..80ae3b32d 100644 --- a/quality_control_stock_oca/models/qc_trigger.py +++ b/quality_control_stock_oca/models/qc_trigger.py @@ -6,7 +6,8 @@ from odoo import fields, models class QcTrigger(models.Model): - _inherit = 'qc.trigger' + _inherit = "qc.trigger" picking_type_id = fields.Many2one( - comodel_name="stock.picking.type", readonly=True, ondelete="cascade") + comodel_name="stock.picking.type", readonly=True, ondelete="cascade" + ) diff --git a/quality_control_stock_oca/models/stock_picking.py b/quality_control_stock_oca/models/stock_picking.py index 727df9de5..5c6eb8a24 100644 --- a/quality_control_stock_oca/models/stock_picking.py +++ b/quality_control_stock_oca/models/stock_picking.py @@ -4,59 +4,74 @@ # 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 StockPicking(models.Model): - _inherit = 'stock.picking' + _inherit = "stock.picking" qc_inspections_ids = fields.One2many( - comodel_name='qc.inspection', inverse_name='picking_id', copy=False, - string='Inspections', help="Inspections related to this picking.") + comodel_name="qc.inspection", + inverse_name="picking_id", + copy=False, + string="Inspections", + help="Inspections related to this picking.", + ) created_inspections = fields.Integer( - compute="_compute_count_inspections", string="Created inspections") + compute="_compute_count_inspections", string="Created inspections" + ) done_inspections = fields.Integer( - compute="_compute_count_inspections", string="Done inspections") + compute="_compute_count_inspections", string="Done inspections" + ) passed_inspections = fields.Integer( - compute="_compute_count_inspections", string="Inspections OK") + compute="_compute_count_inspections", string="Inspections OK" + ) failed_inspections = fields.Integer( - compute="_compute_count_inspections", string="Inspections failed") + compute="_compute_count_inspections", string="Inspections failed" + ) - @api.depends('qc_inspections_ids', 'qc_inspections_ids.state') + @api.depends("qc_inspections_ids", "qc_inspections_ids.state") def _compute_count_inspections(self): - data = self.env['qc.inspection'].read_group([ - ('id', 'in', self.mapped('qc_inspections_ids').ids), - ], ['picking_id', 'state'], ['picking_id', 'state'], lazy=False) + data = self.env["qc.inspection"].read_group( + [("id", "in", self.mapped("qc_inspections_ids").ids)], + ["picking_id", "state"], + ["picking_id", "state"], + lazy=False, + ) picking_data = {} for d in data: - picking_data.setdefault(d['picking_id'][0], {})\ - .setdefault(d['state'], 0) - picking_data[d['picking_id'][0]][d['state']] += d['__count'] + picking_data.setdefault(d["picking_id"][0], {}).setdefault(d["state"], 0) + picking_data[d["picking_id"][0]][d["state"]] += d["__count"] for picking in self: count_data = picking_data.get(picking.id, {}) picking.created_inspections = sum(count_data.values()) - picking.passed_inspections = count_data.get('success', 0) - picking.failed_inspections = count_data.get('failed', 0) - picking.done_inspections = \ - (picking.passed_inspections + picking.failed_inspections) + picking.passed_inspections = count_data.get("success", 0) + picking.failed_inspections = count_data.get("failed", 0) + picking.done_inspections = ( + picking.passed_inspections + picking.failed_inspections + ) @api.multi def action_done(self): res = super(StockPicking, self).action_done() - inspection_model = self.env['qc.inspection'] - qc_trigger = self.env['qc.trigger'].search( - [('picking_type_id', '=', self.picking_type_id.id)]) + inspection_model = self.env["qc.inspection"] + qc_trigger = self.env["qc.trigger"].search( + [("picking_type_id", "=", self.picking_type_id.id)] + ) for operation in self.move_lines: trigger_lines = set() - for model in ['qc.trigger.product_category_line', - 'qc.trigger.product_template_line', - 'qc.trigger.product_line']: - partner = (self.partner_id - if qc_trigger.partner_selectable else False) + for model in [ + "qc.trigger.product_category_line", + "qc.trigger.product_template_line", + "qc.trigger.product_line", + ]: + partner = self.partner_id if qc_trigger.partner_selectable else False trigger_lines = trigger_lines.union( self.env[model].get_trigger_line_for_product( - qc_trigger, operation.product_id, partner=partner)) + qc_trigger, operation.product_id, partner=partner + ) + ) for trigger_line in _filter_trigger_lines(trigger_lines): inspection_model._make_inspection(operation, trigger_line) return res diff --git a/quality_control_stock_oca/models/stock_picking_type.py b/quality_control_stock_oca/models/stock_picking_type.py index e78919f94..fc9f6b1d6 100644 --- a/quality_control_stock_oca/models/stock_picking_type.py +++ b/quality_control_stock_oca/models/stock_picking_type.py @@ -6,18 +6,18 @@ from odoo import api, models class StockPickingType(models.Model): - _inherit = 'stock.picking.type' + _inherit = "stock.picking.type" @api.multi def _create_qc_trigger(self): for picking_type in self: qc_trigger = { - 'name': picking_type.name, - 'company_id': picking_type.warehouse_id.company_id.id, - 'picking_type_id': picking_type.id, - 'partner_selectable': True + "name": picking_type.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) + self.env["qc.trigger"].sudo().create(qc_trigger) @api.model_create_multi def create(self, val_list): @@ -28,10 +28,11 @@ class StockPickingType(models.Model): @api.multi def write(self, vals): res = super(StockPickingType, self).write(vals) - if vals.get('name') or vals.get('warehouse_id'): - qc_trigger_model = self.env['qc.trigger'].sudo() + if vals.get("name") or vals.get("warehouse_id"): + qc_trigger_model = self.env["qc.trigger"].sudo() for rec in self: qc_triggers = qc_trigger_model.search( - [('picking_type_id', '=', rec.id)]) - qc_triggers.write({'name': rec.name}) + [("picking_type_id", "=", rec.id)] + ) + qc_triggers.write({"name": rec.name}) return res diff --git a/quality_control_stock_oca/models/stock_production_lot.py b/quality_control_stock_oca/models/stock_production_lot.py index 16aff5634..d2e0c9496 100644 --- a/quality_control_stock_oca/models/stock_production_lot.py +++ b/quality_control_stock_oca/models/stock_production_lot.py @@ -6,33 +6,43 @@ from odoo import api, fields, models class StockProductionLot(models.Model): - _inherit = 'stock.production.lot' + _inherit = "stock.production.lot" qc_inspections_ids = fields.One2many( - comodel_name='qc.inspection', inverse_name='lot_id', copy=False, - string='Inspections', help="Inspections related to this lot.") + comodel_name="qc.inspection", + inverse_name="lot_id", + copy=False, + string="Inspections", + help="Inspections related to this lot.", + ) created_inspections = fields.Integer( - compute="_compute_count_inspections", string="Created inspections") + compute="_compute_count_inspections", string="Created inspections" + ) done_inspections = fields.Integer( - compute="_compute_count_inspections", string="Done inspections") + compute="_compute_count_inspections", string="Done inspections" + ) passed_inspections = fields.Integer( - compute="_compute_count_inspections", string="Inspections OK") + compute="_compute_count_inspections", string="Inspections OK" + ) failed_inspections = fields.Integer( - compute="_compute_count_inspections", string="Inspections failed") + compute="_compute_count_inspections", string="Inspections failed" + ) - @api.depends('qc_inspections_ids', 'qc_inspections_ids.state') + @api.depends("qc_inspections_ids", "qc_inspections_ids.state") def _compute_count_inspections(self): - data = self.env['qc.inspection'].read_group([ - ('id', 'in', self.mapped('qc_inspections_ids').ids), - ], ['lot_id', 'state'], ['lot_id', 'state'], lazy=False) + data = self.env["qc.inspection"].read_group( + [("id", "in", self.mapped("qc_inspections_ids").ids)], + ["lot_id", "state"], + ["lot_id", "state"], + lazy=False, + ) lot_data = {} for d in data: - lot_data.setdefault(d['lot_id'][0], {}).setdefault(d['state'], 0) - lot_data[d['lot_id'][0]][d['state']] += d['__count'] + lot_data.setdefault(d["lot_id"][0], {}).setdefault(d["state"], 0) + lot_data[d["lot_id"][0]][d["state"]] += d["__count"] for lot in self: count_data = lot_data.get(lot.id, {}) lot.created_inspections = sum(count_data.values()) - lot.passed_inspections = count_data.get('success', 0) - lot.failed_inspections = count_data.get('failed', 0) - lot.done_inspections = \ - (lot.passed_inspections + lot.failed_inspections) + lot.passed_inspections = count_data.get("success", 0) + lot.failed_inspections = count_data.get("failed", 0) + lot.done_inspections = lot.passed_inspections + lot.failed_inspections diff --git a/quality_control_stock_oca/tests/test_quality_control_stock.py b/quality_control_stock_oca/tests/test_quality_control_stock.py index 6cd1d8853..cae4a09dd 100644 --- a/quality_control_stock_oca/tests/test_quality_control_stock.py +++ b/quality_control_stock_oca/tests/test_quality_control_stock.py @@ -6,287 +6,347 @@ from odoo.tests.common import TransactionCase class TestQualityControl(TransactionCase): - def setUp(self): super(TestQualityControl, self).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.qc_test_1') - self.picking_type = self.env.ref('stock.picking_type_out') - self.location_dest = self.env.ref('stock.stock_location_customers') - self.sequence = self.env['ir.sequence'] \ - .search([('prefix', 'like', '/OUT/')], limit=1) - inspection_lines = ( - self.inspection_model._prepare_inspection_lines(self.test)) - self.inspection1 = self.inspection_model.create({ - 'name': 'Test Inspection', - 'inspection_lines': inspection_lines, - }) + 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.qc_test_1") + self.picking_type = self.env.ref("stock.picking_type_out") + self.location_dest = self.env.ref("stock.stock_location_customers") + self.sequence = self.env["ir.sequence"].search( + [("prefix", "like", "/OUT/")], limit=1 + ) + 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.production.lot'].create({ - 'name': 'Lot for tests', - 'product_id': self.product.id, - }) - self.group_stock_user = self.env.ref('stock.group_stock_user') - self.company1 = self.env.ref('base.main_company') + [("picking_type_id", "=", self.picking_type.id)] + ) + self.lot = self.env["stock.production.lot"].create( + {"name": "Lot for tests", "product_id": self.product.id} + ) + self.group_stock_user = self.env.ref("stock.group_stock_user") + self.company1 = self.env.ref("base.main_company") self.user1_id = self._create_user( - 'user_1', [self.group_stock_user], self.company1) + "user_1", [self.group_stock_user], self.company1 + ) 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, - 'quantity_done': 1.0 + "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, + "quantity_done": 1.0, } - self.picking1 = self.picking_model.sudo(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_lines': [(0, 0, move_vals)], - 'location_dest_id': self.location_dest.id - }) + self.picking1 = ( + self.picking_model.sudo(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_lines": [(0, 0, move_vals)], + "location_dest_id": self.location_dest.id, + } + ) + ) self.picking1.action_confirm() sequence = 10 for line in self.picking1.move_lines.filtered( - lambda r: r.product_id == self.product): - line.write({ - 'move_line_ids': [(0, 0, { - 'lot_id': self.lot.id, - 'product_uom_qty': 1.0, - '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 - }) + lambda r: r.product_id == self.product + ): + line.write( + { + "move_line_ids": [ + ( + 0, + 0, + { + "lot_id": self.lot.id, + "product_uom_qty": 1.0, + "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({ - '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)] - }) + user = self.users_model.with_context({"no_reset_password": True}).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)], + } + ) return user.id def test_inspection_create_for_product(self): - self.product.qc_triggers = [( - 0, 0, { - 'trigger': self.trigger.id, - 'test': self.test.id, - } - )] + self.product.qc_triggers = [ + (0, 0, {"trigger": self.trigger.id, "test": self.test.id}) + ] self.picking1.action_done() - self.assertEqual(self.picking1.created_inspections, 1, - 'Only one inspection must be created') + self.assertEqual( + self.picking1.created_inspections, 1, "Only one inspection must be created" + ) inspection = self.picking1.qc_inspections_ids[:1] self.assertEqual(inspection.qty, 2.0) - self.assertEqual(inspection.test, self.test, - 'Wrong test picked when creating inspection.') + self.assertEqual( + inspection.test, self.test, "Wrong test picked when creating inspection." + ) # Try in this context if onchange with an stock.pack.operation works inspection.qty = 5 inspection.onchange_object_id() self.assertEqual(inspection.qty, 2.0) def test_inspection_create_for_template(self): - self.product.product_tmpl_id.qc_triggers = [( - 0, 0, { - 'trigger': self.trigger.id, - 'test': self.test.id, - } - )] + self.product.product_tmpl_id.qc_triggers = [ + (0, 0, {"trigger": self.trigger.id, "test": self.test.id}) + ] self.picking1.action_done() - self.assertEqual(self.picking1.created_inspections, 1, - 'Only one inspection must be created') - self.assertEqual(self.picking1.qc_inspections_ids[:1].test, self.test, - 'Wrong test picked when creating inspection.') + self.assertEqual( + self.picking1.created_inspections, 1, "Only one inspection must be created" + ) + self.assertEqual( + self.picking1.qc_inspections_ids[:1].test, + self.test, + "Wrong test picked when creating inspection.", + ) def test_inspection_create_for_category(self): - self.product.categ_id.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}) + ] self.picking1.action_done() - self.assertEqual(self.picking1.created_inspections, 1, - 'Only one inspection must be created') - self.assertEqual(self.picking1.qc_inspections_ids[:1].test, self.test, - 'Wrong test picked when creating inspection.') + self.assertEqual( + self.picking1.created_inspections, 1, "Only one inspection must be created" + ) + self.assertEqual( + self.picking1.qc_inspections_ids[:1].test, + self.test, + "Wrong test picked when creating inspection.", + ) def test_inspection_create_for_product_partner(self): - self.product.qc_triggers = [( - 0, 0, { - 'trigger': self.trigger.id, - 'test': self.test.id, - 'partners': [(6, 0, self.partner1.ids)], - } - )] + self.product.qc_triggers = [ + ( + 0, + 0, + { + "trigger": self.trigger.id, + "test": self.test.id, + "partners": [(6, 0, self.partner1.ids)], + }, + ) + ] self.picking1.action_done() - self.assertEqual(self.picking1.created_inspections, 1, - 'Only one inspection must be created') - self.assertEqual(self.picking1.qc_inspections_ids[:1].test, self.test, - 'Wrong test picked when creating inspection.') + self.assertEqual( + self.picking1.created_inspections, 1, "Only one inspection must be created" + ) + self.assertEqual( + self.picking1.qc_inspections_ids[:1].test, + self.test, + "Wrong test picked when creating inspection.", + ) def test_inspection_create_for_template_partner(self): - self.product.product_tmpl_id.qc_triggers = [( - 0, 0, { - 'trigger': self.trigger.id, - 'test': self.test.id, - 'partners': [(6, 0, self.partner1.ids)], - } - )] + self.product.product_tmpl_id.qc_triggers = [ + ( + 0, + 0, + { + "trigger": self.trigger.id, + "test": self.test.id, + "partners": [(6, 0, self.partner1.ids)], + }, + ) + ] self.picking1.action_done() - self.assertEqual(self.picking1.created_inspections, 1, - 'Only one inspection must be created') - self.assertEqual(self.picking1.qc_inspections_ids[:1].test, self.test, - 'Wrong test picked when creating inspection.') + self.assertEqual( + self.picking1.created_inspections, 1, "Only one inspection must be created" + ) + self.assertEqual( + self.picking1.qc_inspections_ids[:1].test, + self.test, + "Wrong test picked when creating inspection.", + ) def test_inspection_create_for_category_partner(self): - self.product.categ_id.qc_triggers = [( - 0, 0, { - 'trigger': self.trigger.id, - 'test': self.test.id, - 'partners': [(6, 0, self.partner1.ids)], - } - )] + self.product.categ_id.qc_triggers = [ + ( + 0, + 0, + { + "trigger": self.trigger.id, + "test": self.test.id, + "partners": [(6, 0, self.partner1.ids)], + }, + ) + ] self.picking1.action_done() - self.assertEqual(self.picking1.created_inspections, 1, - 'Only one inspection must be created') - self.assertEqual(self.picking1.qc_inspections_ids[:1].test, self.test, - 'Wrong test picked when creating inspection.') + self.assertEqual( + self.picking1.created_inspections, 1, "Only one inspection must be created" + ) + self.assertEqual( + self.picking1.qc_inspections_ids[:1].test, + self.test, + "Wrong test picked when creating inspection.", + ) def test_inspection_create_for_product_wrong_partner(self): - self.product.qc_triggers = [( - 0, 0, { - 'trigger': self.trigger.id, - 'test': self.test.id, - 'partners': [(6, 0, self.partner2.ids)], - } - )] + self.product.qc_triggers = [ + ( + 0, + 0, + { + "trigger": self.trigger.id, + "test": self.test.id, + "partners": [(6, 0, self.partner2.ids)], + }, + ) + ] self.picking1.action_done() - self.assertEqual(self.picking1.created_inspections, 0, - 'No inspection must be created') + self.assertEqual( + self.picking1.created_inspections, 0, "No inspection must be created" + ) def test_inspection_create_for_template_wrong_partner(self): - self.product.product_tmpl_id.qc_triggers = [( - 0, 0, { - 'trigger': self.trigger.id, - 'test': self.test.id, - 'partners': [(6, 0, self.partner2.ids)], - } - )] + self.product.product_tmpl_id.qc_triggers = [ + ( + 0, + 0, + { + "trigger": self.trigger.id, + "test": self.test.id, + "partners": [(6, 0, self.partner2.ids)], + }, + ) + ] self.picking1.action_done() - self.assertEqual(self.picking1.created_inspections, 0, - 'No inspection must be created') + self.assertEqual( + self.picking1.created_inspections, 0, "No inspection must be created" + ) def test_inspection_create_for_category_wrong_partner(self): - self.product.categ_id.qc_triggers = [( - 0, 0, { - 'trigger': self.trigger.id, - 'test': self.test.id, - 'partners': [(6, 0, self.partner2.ids)], - } - )] + self.product.categ_id.qc_triggers = [ + ( + 0, + 0, + { + "trigger": self.trigger.id, + "test": self.test.id, + "partners": [(6, 0, self.partner2.ids)], + }, + ) + ] self.picking1.action_done() - self.assertEqual(self.picking1.created_inspections, 0, - 'No inspection must be created') + self.assertEqual( + self.picking1.created_inspections, 0, "No 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, - } - )] + 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}) + ] self.picking1.action_done() - self.assertEqual(self.picking1.created_inspections, 1, - 'Only one inspection must be created') - self.assertEqual(self.picking1.qc_inspections_ids[:1].test, self.test, - 'Wrong test picked when creating inspection.') - self.assertEqual(self.lot.created_inspections, 1, - 'Only one inspection must be created') - self.assertEqual(self.lot.qc_inspections_ids[:1].test, self.test, - 'Wrong test picked when creating inspection.') + self.assertEqual( + self.picking1.created_inspections, 1, "Only one inspection must be created" + ) + self.assertEqual( + self.picking1.qc_inspections_ids[:1].test, + self.test, + "Wrong test picked when creating inspection.", + ) + self.assertEqual( + self.lot.created_inspections, 1, "Only one inspection must be created" + ) + self.assertEqual( + self.lot.qc_inspections_ids[:1].test, + self.test, + "Wrong test picked when creating inspection.", + ) def test_picking_type(self): - picking_type = self.picking_type_model.create({ - 'name': 'Test Picking Type', - 'code': 'outgoing', - 'sequence_id': self.sequence.id - }) + picking_type = self.picking_type_model.create( + { + "name": "Test Picking Type", + "code": "outgoing", + "sequence_id": self.sequence.id, + } + ) trigger = self.qc_trigger_model.search( - [('picking_type_id', '=', picking_type.id)]) - self.assertEqual(len(trigger), 1, - 'One trigger must have been created.') - self.assertEqual(trigger.name, picking_type.name, - 'Trigger name must match picking type name.') - picking_type.write({ - 'name': 'Test Name Change', - }) - self.assertEqual(trigger.name, picking_type.name, - 'Trigger name must match picking type name.') + [("picking_type_id", "=", picking_type.id)] + ) + self.assertEqual(len(trigger), 1, "One trigger must have been created.") + self.assertEqual( + trigger.name, + picking_type.name, + "Trigger name must match picking type name.", + ) + picking_type.write({"name": "Test Name Change"}) + self.assertEqual( + trigger.name, + picking_type.name, + "Trigger name must match picking type name.", + ) def test_qc_inspection_picking(self): - self.inspection1.write({ - 'name': self.picking1.move_lines[:1]._name + "inspection", - 'object_id': '%s,%d' % (self.picking1._name, - self.picking1.id), - }) - self.assertEqual(self.inspection1.picking_id, - self.picking1) + self.inspection1.write( + { + "name": self.picking1.move_lines[:1]._name + "inspection", + "object_id": "%s,%d" % (self.picking1._name, self.picking1.id), + } + ) + self.assertEqual(self.inspection1.picking_id, self.picking1) def test_qc_inspection_stock_move(self): - self.inspection1.write({ - 'name': self.picking1.move_lines[:1]._name + "inspection", - 'object_id': '%s,%d' % (self.picking1.move_lines[:1]._name, - self.picking1.move_lines[:1].id), - }) + self.inspection1.write( + { + "name": self.picking1.move_lines[:1]._name + "inspection", + "object_id": "%s,%d" + % (self.picking1.move_lines[:1]._name, self.picking1.move_lines[:1].id), + } + ) self.inspection1.onchange_object_id() - self.assertEqual(self.inspection1.picking_id, - self.picking1) - self.assertEqual(self.inspection1.lot_id, - self.lot) - self.assertEqual(self.inspection1.product_id, - self.picking1.move_lines[:1].product_id) - self.assertEqual(self.inspection1.qty, - self.picking1.move_lines[:1].product_qty) + self.assertEqual(self.inspection1.picking_id, self.picking1) + self.assertEqual(self.inspection1.lot_id, self.lot) + self.assertEqual( + self.inspection1.product_id, self.picking1.move_lines[:1].product_id + ) + self.assertEqual(self.inspection1.qty, self.picking1.move_lines[:1].product_qty) def test_qc_inspection_lot(self): - self.inspection1.write({ - 'name': self.picking1.move_lines[:1]._name + "inspection", - 'object_id': '%s,%d' % (self.lot._name, - self.lot.id), - }) + self.inspection1.write( + { + "name": self.picking1.move_lines[:1]._name + "inspection", + "object_id": "%s,%d" % (self.lot._name, self.lot.id), + } + ) self.inspection1.onchange_object_id() - self.assertEqual(self.inspection1.lot_id, - self.lot) - self.assertEqual(self.inspection1.product_id, - self.lot.product_id) + self.assertEqual(self.inspection1.lot_id, self.lot) + self.assertEqual(self.inspection1.product_id, self.lot.product_id) diff --git a/quality_control_stock_oca/views/qc_inspection_view.xml b/quality_control_stock_oca/views/qc_inspection_view.xml index 0e462f1c8..9b7631551 100644 --- a/quality_control_stock_oca/views/qc_inspection_view.xml +++ b/quality_control_stock_oca/views/qc_inspection_view.xml @@ -1,84 +1,88 @@ - + qc.inspection.form.view.picking qc.inspection - + - - + + - qc.inspection.tree.view.picking qc.inspection - + - - + + - qc.inspection.search.view.picking qc.inspection - + - - + + - - + + - qc.inspection.line.tree.stock qc.inspection.line - + - - + + - qc.inspection.line.search.stock qc.inspection.line - + - - + + - - + + diff --git a/quality_control_stock_oca/views/stock_picking_view.xml b/quality_control_stock_oca/views/stock_picking_view.xml index 724e2336e..0e732384b 100644 --- a/quality_control_stock_oca/views/stock_picking_view.xml +++ b/quality_control_stock_oca/views/stock_picking_view.xml @@ -1,4 +1,4 @@ - + @@ -8,60 +8,74 @@ tree,form [('picking_id', '=', active_id)] - Quality inspection from picking done qc.inspection tree,form - [('picking_id', '=', active_id), ('state', 'not in', ['draft', 'waiting'])] + [('picking_id', '=', active_id), ('state', 'not in', ['draft', 'waiting'])] - Quality inspection from picking passed qc.inspection tree,form - [('picking_id', '=', active_id), ('state', '=', 'success')] + [('picking_id', '=', active_id), ('state', '=', 'success')] - Quality inspections from picking failed qc.inspection tree,form - [('picking_id', '=', active_id), ('state', '=', 'failed')] + [('picking_id', '=', active_id), ('state', '=', 'failed')] - stock.picking.qc.view stock.picking - +
- - - -
diff --git a/quality_control_stock_oca/views/stock_production_lot_view.xml b/quality_control_stock_oca/views/stock_production_lot_view.xml index 2fe52a6d5..d3dba09f1 100644 --- a/quality_control_stock_oca/views/stock_production_lot_view.xml +++ b/quality_control_stock_oca/views/stock_production_lot_view.xml @@ -1,4 +1,4 @@ - + @@ -8,60 +8,74 @@ tree,form [('lot_id', '=', active_id)]
- Quality inspection from lot done qc.inspection tree,form - [('lot_id', '=', active_id), ('state', 'not in', ['draft', 'waiting'])] + [('lot_id', '=', active_id), ('state', 'not in', ['draft', 'waiting'])] - Quality inspection from lot passed qc.inspection tree,form - [('lot_id', '=', active_id), ('state', '=', 'success')] + [('lot_id', '=', active_id), ('state', '=', 'success')] - Quality inspections from lot failed qc.inspection tree,form - [('lot_id', '=', active_id), ('state', '=', 'failed')] + [('lot_id', '=', active_id), ('state', '=', 'failed')] - stock.production.lot.qc.view stock.production.lot - +
- - - -