From 035b87ed28fa739b10d590a3a3f40b0d41d118b4 Mon Sep 17 00:00:00 2001 From: Simone Rubino Date: Wed, 27 Jun 2018 09:25:00 +0200 Subject: [PATCH] [MIG] quality_control_mrp: Migration to 10.0 --- quality_control_mrp/README.rst | 67 ++++++--- quality_control_mrp/__init__.py | 3 +- .../{__openerp__.py => __manifest__.py} | 20 ++- .../data/quality_control_mrp_data.xml | 26 ++-- quality_control_mrp/models/__init__.py | 3 +- quality_control_mrp/models/mrp_production.py | 54 +++---- quality_control_mrp/models/qc_inspection.py | 7 +- quality_control_mrp/readme/CONTRIBUTORS.rst | 3 + quality_control_mrp/readme/DESCRIPTION.rst | 4 + quality_control_mrp/tests/__init__.py | 3 +- .../tests/test_quality_control_mrp.py | 80 +++++++--- .../views/mrp_production_view.xml | 71 ++++----- .../views/qc_inspection_view.xml | 138 +++++++++--------- 13 files changed, 263 insertions(+), 216 deletions(-) rename quality_control_mrp/{__openerp__.py => __manifest__.py} (55%) create mode 100644 quality_control_mrp/readme/CONTRIBUTORS.rst create mode 100644 quality_control_mrp/readme/DESCRIPTION.rst diff --git a/quality_control_mrp/README.rst b/quality_control_mrp/README.rst index 297ba3160..fa3a1499b 100644 --- a/quality_control_mrp/README.rst +++ b/quality_control_mrp/README.rst @@ -1,52 +1,77 @@ -.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg - :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html - :alt: License: AGPL-3 - ================================= MRP extension for quality control ================================= +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fmanufacture-lightgray.png?logo=github + :target: https://github.com/OCA/manufacture/tree/10.0/quality_control_mrp + :alt: OCA/manufacture +.. |badge4| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/129/10.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| + This module defines a trigger that creates quality control inspections when a production order is finished. It also adds the shortcuts related to these inspections on production orders. +**Table of contents** -Usage -===== - -.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas - :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/129/8.0 - +.. contents:: + :local: Bug Tracker =========== Bugs are tracked on `GitHub Issues `_. In case of trouble, please check there if your issue has already been reported. -If you spotted it first, help us smashing it by providing a detailed and welcomed feedback `here `_. +If you spotted it first, help us smashing it by providing a detailed and welcomed feedback. +Do not contact contributors directly about support or help with technical issues. Credits ======= -Contributors ------------- -* Pedro M. Baeza -* Oihane Crucelaegui +Authors +~~~~~~~ -Maintainer ----------- +* OdooMRP team +* AvanzOSC +* Serv. Tecnol. Avanzados - Pedro M. Baeza +* Agile Business Group + +Contributors +~~~~~~~~~~~~ + +* Pedro M. Baeza +* Oihane Crucelaegui +* Simone Rubino + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. .. image:: https://odoo-community.org/logo.png :alt: Odoo Community Association :target: https://odoo-community.org -This module is maintained by the OCA. - OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. -To contribute to this module, please visit http://odoo-community.org. +This module is part of the `OCA/manufacture `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/quality_control_mrp/__init__.py b/quality_control_mrp/__init__.py index 7a3b0b9a1..b44d76594 100644 --- a/quality_control_mrp/__init__.py +++ b/quality_control_mrp/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- -# (c) 2014 Serv. Tec. Avanzados - Pedro M. Baeza -# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). from . import models diff --git a/quality_control_mrp/__openerp__.py b/quality_control_mrp/__manifest__.py similarity index 55% rename from quality_control_mrp/__openerp__.py rename to quality_control_mrp/__manifest__.py index c88440fbe..045b754b9 100644 --- a/quality_control_mrp/__openerp__.py +++ b/quality_control_mrp/__manifest__.py @@ -1,26 +1,24 @@ # -*- coding: utf-8 -*- -# (c) 2014 Serv. Tec. Avanzados - Pedro M. Baeza -# (c) 2014 Oihane Crucelaegui - AvanzOSC -# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html +# Copyright 2014 Serv. Tec. Avanzados - Pedro M. Baeza +# Copyright 2014 Oihane Crucelaegui - AvanzOSC +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). { - "name": "Quality control - MRP", - "version": "8.0.1.0.0", + "name": "MRP extension for quality control", + "version": "10.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": "http://www.odoomrp.com", - "contributors": [ - "Pedro M. Baeza ", - "Oihane Crucelaegui ", - ], + "website": "https://github.com/OCA/manufacture/tree/10.0/" + "quality_control_mrp", "depends": [ "quality_control", "quality_control_stock", - "mrp", + "mrp" ], "data": [ 'data/quality_control_mrp_data.xml', diff --git a/quality_control_mrp/data/quality_control_mrp_data.xml b/quality_control_mrp/data/quality_control_mrp_data.xml index 99a2de04a..069f18cbb 100644 --- a/quality_control_mrp/data/quality_control_mrp_data.xml +++ b/quality_control_mrp/data/quality_control_mrp_data.xml @@ -1,16 +1,14 @@ - - + + + + Production done + + - - Production done - - - - - Manufacturing Order - mrp.production - - - - + + Manufacturing Order + mrp.production + + diff --git a/quality_control_mrp/models/__init__.py b/quality_control_mrp/models/__init__.py index 01f09e84b..c2ccc73d1 100644 --- a/quality_control_mrp/models/__init__.py +++ b/quality_control_mrp/models/__init__.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- -# (c) 2014 Serv. Tec. Avanzados - Pedro M. Baeza -# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). from . import qc_inspection from . import mrp_production diff --git a/quality_control_mrp/models/mrp_production.py b/quality_control_mrp/models/mrp_production.py index 6f5ad7846..0b984d8ad 100644 --- a/quality_control_mrp/models/mrp_production.py +++ b/quality_control_mrp/models/mrp_production.py @@ -1,19 +1,21 @@ # -*- coding: utf-8 -*- -# (c) 2014 Serv. Tec. Avanzados - Pedro M. Baeza -# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html +# Copyright 2014 Serv. Tec. Avanzados - Pedro M. Baeza +# Copyright 2018 Simone Rubino - Agile Business Group +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -from openerp import models, fields, api -from openerp.addons.quality_control.models.qc_trigger_line import\ +from odoo import api, fields, models +from odoo.addons.quality_control.models.qc_trigger_line import \ _filter_trigger_lines class MrpProduction(models.Model): _inherit = 'mrp.production' - @api.one + @api.multi @api.depends('qc_inspections') def _count_inspections(self): - self.created_inspections = len(self.qc_inspections) + for production in self: + production.created_inspections = len(production.qc_inspections) qc_inspections = fields.One2many( comodel_name='qc.inspection', inverse_name='production', copy=False, @@ -21,26 +23,24 @@ class MrpProduction(models.Model): created_inspections = fields.Integer( compute="_count_inspections", string="Created inspections") - @api.model - def action_produce(self, production_id, production_qty, production_mode, - wiz=False): - production = self.browse(production_id) - done_moves = production.move_created_ids2.filtered( + @api.multi + def post_inventory(self): + done_moves = self.mapped('move_finished_ids').filtered( lambda r: r.state == 'done') - res = super(MrpProduction, self).action_produce( - production_id, production_qty, production_mode, wiz=wiz) - if production_mode == 'consume_produce': - inspection_model = self.env['qc.inspection'] - for move in production.move_created_ids2.filtered( - lambda r: r.state == 'done') - done_moves: - qc_trigger = self.env.ref('quality_control_mrp.qc_trigger_mrp') - trigger_lines = set() - 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)) - for trigger_line in _filter_trigger_lines(trigger_lines): - inspection_model._make_inspection(move, trigger_line) + 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 + if new_done_moves: + 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']: + trigger_lines = trigger_lines.union( + self.env[model].get_trigger_line_for_product( + qc_trigger, move.product_id)) + for trigger_line in _filter_trigger_lines(trigger_lines): + inspection_model._make_inspection(move, trigger_line) return res diff --git a/quality_control_mrp/models/qc_inspection.py b/quality_control_mrp/models/qc_inspection.py index b7331f518..01f5561f6 100644 --- a/quality_control_mrp/models/qc_inspection.py +++ b/quality_control_mrp/models/qc_inspection.py @@ -1,8 +1,9 @@ # -*- coding: utf-8 -*- -# (c) 2014 Serv. Tec. Avanzados - Pedro M. Baeza -# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html +# Copyright 2014 Serv. Tec. Avanzados - Pedro M. Baeza +# Copyright 2018 Simone Rubino - Agile Business Group +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -from openerp import models, fields, api +from odoo import api, fields, models class QcInspection(models.Model): diff --git a/quality_control_mrp/readme/CONTRIBUTORS.rst b/quality_control_mrp/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..887df21fa --- /dev/null +++ b/quality_control_mrp/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* Pedro M. Baeza +* Oihane Crucelaegui +* Simone Rubino diff --git a/quality_control_mrp/readme/DESCRIPTION.rst b/quality_control_mrp/readme/DESCRIPTION.rst new file mode 100644 index 000000000..876f53e8f --- /dev/null +++ b/quality_control_mrp/readme/DESCRIPTION.rst @@ -0,0 +1,4 @@ +This module defines a trigger that creates quality control inspections when a +production order is finished. + +It also adds the shortcuts related to these inspections on production orders. diff --git a/quality_control_mrp/tests/__init__.py b/quality_control_mrp/tests/__init__.py index bb13e6fe1..7564f3b6b 100644 --- a/quality_control_mrp/tests/__init__.py +++ b/quality_control_mrp/tests/__init__.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- -# (c) 2015 Oihane Crucelaegui - AvanzOSC -# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). from . import test_quality_control_mrp diff --git a/quality_control_mrp/tests/test_quality_control_mrp.py b/quality_control_mrp/tests/test_quality_control_mrp.py index d59bc5f69..e028aa25d 100644 --- a/quality_control_mrp/tests/test_quality_control_mrp.py +++ b/quality_control_mrp/tests/test_quality_control_mrp.py @@ -1,8 +1,9 @@ # -*- coding: utf-8 -*- -# (c) 2015 Oihane Crucelaegui - AvanzOSC -# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html +# 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 openerp.tests.common import TransactionCase +from odoo.tests.common import TransactionCase class TestQualityControlMrp(TransactionCase): @@ -12,15 +13,16 @@ class TestQualityControlMrp(TransactionCase): 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('product.product_product_4') + self.product = self.env.ref('mrp.product_product_computer_desk') 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': self.product.uom_id.id, + 'product_uom_id': self.product.uom_id.id, + 'bom_id': self.bom.id }) - self.production1.action_confirm() self.production1.action_assign() inspection_lines = ( self.inspection_model._prepare_inspection_lines(self.test)) @@ -36,9 +38,14 @@ class TestQualityControlMrp(TransactionCase): 'test': self.test.id, } )] - self.production1.action_produce( - self.production1.id, self.production1.product_qty, - 'consume_produce') + 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') @@ -49,9 +56,14 @@ class TestQualityControlMrp(TransactionCase): 'test': self.test.id, } )] - self.production1.action_produce( - self.production1.id, self.production1.product_qty, - 'consume_produce') + 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') @@ -62,9 +74,14 @@ class TestQualityControlMrp(TransactionCase): 'test': self.test.id, } )] - self.production1.action_produce( - self.production1.id, self.production1.product_qty, - 'consume_produce') + 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') @@ -81,9 +98,14 @@ class TestQualityControlMrp(TransactionCase): 'test': self.test.id, } )] - self.production1.action_produce( - self.production1.id, self.production1.product_qty, - 'consume_produce') + 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') @@ -94,18 +116,30 @@ class TestQualityControlMrp(TransactionCase): 'test': self.test.id, } )] - self.production1.action_produce( - self.production1.id, 1.0, 'consume_produce') + 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.') - self.production1.action_produce( - self.production1.id, 1.0, 'consume_produce') + 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.') def test_qc_inspection_mo(self): self.inspection1.write({ - 'object_id': '%s,%d' % (self.production1._model, + 'object_id': '%s,%d' % (self.production1._name, self.production1.id), }) self.assertEquals(self.inspection1.production, diff --git a/quality_control_mrp/views/mrp_production_view.xml b/quality_control_mrp/views/mrp_production_view.xml index 2b4e9b8e6..f23abe253 100644 --- a/quality_control_mrp/views/mrp_production_view.xml +++ b/quality_control_mrp/views/mrp_production_view.xml @@ -1,44 +1,31 @@ - - - - Quality inspections from production order - qc.inspection - tree,form - [('production', '=', active_id)] - + + + + Quality inspections from production order + qc.inspection + tree,form + [('production', '=', active_id)] + - - mrp.production.buttons - mrp.production - - -
-
-
-
-
-
- - - mrp.production.form.qc - mrp.production - - - -
- -
-
-
- -
-
\ No newline at end of file + + mrp.production.form.qc + mrp.production + + + +
+ +
+
+
+ \ No newline at end of file diff --git a/quality_control_mrp/views/qc_inspection_view.xml b/quality_control_mrp/views/qc_inspection_view.xml index 5bc886ef3..7f5ba5a75 100644 --- a/quality_control_mrp/views/qc_inspection_view.xml +++ b/quality_control_mrp/views/qc_inspection_view.xml @@ -1,79 +1,79 @@ - - - - - qc.inspection.form.view.production - qc.inspection - - - - - - + + + + qc.inspection.form.view.production + qc.inspection + + + + + - + + - - qc.inspection.tree.view.production - qc.inspection - - - - - - + + qc.inspection.tree.view.production + qc.inspection + + + + + - + + - - qc.inspection.search.view.production - qc.inspection - - - - - - - - - + + qc.inspection.search.view.production + qc.inspection + + + + + - + + + + + - - qc.inspection.line.tree.production - qc.inspection.line - - - - - - + + qc.inspection.line.tree.production + qc.inspection.line + + + + + - + + - - qc.inspection.line.search.production - qc.inspection.line - - - - - - - - - + + qc.inspection.line.search.production + qc.inspection.line + + + + + - - - - + + + + + +