Skip to content

Commit

Permalink
[ADD] mrp_production_machine_location: Machine location in consume an…
Browse files Browse the repository at this point in the history
…d produce products.
  • Loading branch information
alfredoavanzosc committed Nov 9, 2016
1 parent c1fcd66 commit 747f7b4
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 0 deletions.
23 changes: 23 additions & 0 deletions 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 <ajuaristo@gmail.com>
* Alfredo de la Fuente <alfredodelafuente@avanzosc.es>
4 changes: 4 additions & 0 deletions 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
19 changes: 19 additions & 0 deletions 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 <anajuaristi@avanzosc.es>",
"Alfredo de la Fuente <alfredodelafuente@avanzosc.es>",
],
"category": "Manufacturing",
"depends": ['mrp_machine_relation'
],
"data": [],
"installable": True
}
27 changes: 27 additions & 0 deletions 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"

5 changes: 5 additions & 0 deletions 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
27 changes: 27 additions & 0 deletions 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
19 changes: 19 additions & 0 deletions 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()
4 changes: 4 additions & 0 deletions 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
@@ -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')

0 comments on commit 747f7b4

Please sign in to comment.