diff --git a/mrp_production_machine_location/README.rst b/mrp_production_machine_location/README.rst new file mode 100644 index 00000000..8b2bf837 --- /dev/null +++ b/mrp_production_machine_location/README.rst @@ -0,0 +1,23 @@ +MRP Production machine location +=============================== +If the work order is to produce, and this work order has a work center that has +a machine defined, and this machine has definied a location: + + * The origin location of the products to consume in the work order, will be + the location of the machine. + + * The destination location of the product to be produced, will be the location + of the machine. + + +Configuration +============= + + +Credits +======= + +Contributors +------------ +* Ana Juaristi +* Alfredo de la Fuente diff --git a/mrp_production_machine_location/__init__.py b/mrp_production_machine_location/__init__.py new file mode 100644 index 00000000..0b1f0152 --- /dev/null +++ b/mrp_production_machine_location/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# (c) 2016 Alfredo de la Fuente - AvanzOSC +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html +from . import models diff --git a/mrp_production_machine_location/__openerp__.py b/mrp_production_machine_location/__openerp__.py new file mode 100644 index 00000000..f34f6cc3 --- /dev/null +++ b/mrp_production_machine_location/__openerp__.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# (c) 2016 Alfredo de la Fuente - AvanzOSC +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html +{ + "name": "MRP Production Machine Location", + "version": "8.0.1.0.0", + "license": "AGPL-3", + "author": "AvanzOSC", + "website": "http://www.avanzosc.es", + 'contributors': [ + "Ana Juaristi ", + "Alfredo de la Fuente ", + ], + "category": "Manufacturing", + "depends": ['mrp_machine_relation' + ], + "data": [], + "installable": True +} diff --git a/mrp_production_machine_location/i18n/es.po b/mrp_production_machine_location/i18n/es.po new file mode 100644 index 00000000..1be27689 --- /dev/null +++ b/mrp_production_machine_location/i18n/es.po @@ -0,0 +1,27 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mrp_production_machine_location +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 8.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2016-11-08 15:16+0000\n" +"PO-Revision-Date: 2016-11-08 15:16+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: mrp_production_machine_location +#: model:ir.model,name:mrp_production_machine_location.model_mrp_production +msgid "Manufacturing Order" +msgstr "Orden de fabricaciĆ³n" + +#. module: mrp_production_machine_location +#: model:ir.model,name:mrp_production_machine_location.model_stock_move +msgid "Stock Move" +msgstr "Movimiento de stock" + diff --git a/mrp_production_machine_location/models/__init__.py b/mrp_production_machine_location/models/__init__.py new file mode 100644 index 00000000..7e760687 --- /dev/null +++ b/mrp_production_machine_location/models/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# (c) 2016 Alfredo de la Fuente - AvanzOSC +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html +from . import mrp_production +from . import stock_move diff --git a/mrp_production_machine_location/models/mrp_production.py b/mrp_production_machine_location/models/mrp_production.py new file mode 100644 index 00000000..06aa0a9a --- /dev/null +++ b/mrp_production_machine_location/models/mrp_production.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# (c) 2016 Alfredo de la Fuente - AvanzOSC +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html +from openerp import models, api + + +class MrpProduction(models.Model): + _inherit = 'mrp.production' + + @api.multi + def action_confirm(self): + result = super(MrpProduction, self).action_confirm() + for prod in self: + moves = prod.move_lines.filtered( + lambda r: r.work_order.do_production and + r.work_order.workcenter_id.machine.location) + for move in moves: + location = move.work_order.workcenter_id.machine.location + move.location_id = location + workcenter_lines = prod.workcenter_lines.filtered( + lambda r: r.do_production) + workcenter_line = max( + workcenter_lines, key=lambda x: x.sequence) + location = workcenter_line.workcenter_id.machine.location + if location: + prod.move_created_ids.write({'location_dest_id': location.id}) + return result diff --git a/mrp_production_machine_location/models/stock_move.py b/mrp_production_machine_location/models/stock_move.py new file mode 100644 index 00000000..c6503238 --- /dev/null +++ b/mrp_production_machine_location/models/stock_move.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# (c) 2016 Alfredo de la Fuente - AvanzOSC +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html +from openerp import models, api + + +class StockMove(models.Model): + _inherit = 'stock.move' + + @api.multi + def action_confirm(self): + moves = self.filtered(lambda r: r.raw_material_production_id and + r.work_order.do_production and + r.work_order.workcenter_id.machine.location) + for move in moves: + location = move.work_order.workcenter_id.machine.location + if move.location_id.id != location.id: + move.location_id = location.id + return super(StockMove, self).action_confirm() diff --git a/mrp_production_machine_location/tests/__init__.py b/mrp_production_machine_location/tests/__init__.py new file mode 100755 index 00000000..bde4ce89 --- /dev/null +++ b/mrp_production_machine_location/tests/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# (c) 2015 Alfredo de la Fuente - AvanzOSC +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html +from . import test_mrp_production_machine_location diff --git a/mrp_production_machine_location/tests/test_mrp_production_machine_location.py b/mrp_production_machine_location/tests/test_mrp_production_machine_location.py new file mode 100755 index 00000000..f4935baa --- /dev/null +++ b/mrp_production_machine_location/tests/test_mrp_production_machine_location.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- +# (c) 2015 Alfredo de la Fuente - AvanzOSC +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html +import openerp.tests.common as common + + +class TestMrpProductionMachineLocation(common.TransactionCase): + + def setUp(self): + super(TestMrpProductionMachineLocation, self).setUp() + self.machine = self.env.ref('machine_manager.machinery_1') + self.machine.location = self.ref('stock.location_refrigerator_small') + self.workcenter = self.env.ref('mrp.mrp_workcenter_0') + self.workcenter.machine = self.machine.id + self.production = self.env.ref( + 'mrp_operations_extension.mrp_production_opeext') + + def test_mrp_production_machine_location(self): + self.assertEqual(self.production.state, 'draft') + self.production.signal_workflow('button_confirm') + stock_moves = self.production.mapped('move_lines').filtered( + lambda l: l.work_order.workcenter_id == self.workcenter) + for stock_move in stock_moves: + self.assertEqual( + stock_move.location_id, self.machine.location, + 'products to consume without machine location') + stock_moves.write( + {'location_id': + self.ref('stock.stock_location_locations_virtual')}) + stock_moves.action_confirm() + for stock_move in stock_moves: + self.assertEqual( + stock_move.location_id, self.machine.location, + 'products to consume without machine location')